works on selling group items
This commit is contained in:
20
src/api.rs
20
src/api.rs
@@ -1,5 +1,15 @@
|
||||
use diesel::prelude::*;
|
||||
use lootalot_db::{self as db, DbConnection, QueryResult};
|
||||
|
||||
pub type ItemListWithMods = Vec<(i32, Option<f64>)>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct SellParams {
|
||||
pub items: ItemListWithMods,
|
||||
players: Option<Vec<i32>>,
|
||||
global_mod: Option<f64>,
|
||||
}
|
||||
|
||||
/// Every possible update which can happen during a query
|
||||
#[derive(Serialize, Debug)]
|
||||
pub enum Update {
|
||||
@@ -92,6 +102,7 @@ pub enum ApiActions {
|
||||
UpdateWealth(i32, f64),
|
||||
BuyItems(i32, Vec<(i32, Option<f64>)>),
|
||||
SellItems(i32, Vec<(i32, Option<f64>)>),
|
||||
SellGroupItems(i32, SellParams),
|
||||
ClaimItem(i32, i32),
|
||||
UnclaimItem(i32, i32),
|
||||
// Group actions
|
||||
@@ -154,7 +165,6 @@ pub fn execute(
|
||||
response.push_update(Update::Wealth(total_amount));
|
||||
}
|
||||
ApiActions::SellItems(id, params) => {
|
||||
// TODO: Different procedure for group and other players
|
||||
let mut all_results: Vec<db::Wealth> = Vec::with_capacity(params.len());
|
||||
let mut sold_items: u16 = 0;
|
||||
for (loot_id, price_mod) in params.into_iter() {
|
||||
@@ -172,6 +182,14 @@ pub fn execute(
|
||||
response.notify(format!("{} objet(s) vendu(s) pour {} po", sold_items, total_amount.to_gp()));
|
||||
response.push_update(Update::Wealth(total_amount));
|
||||
}
|
||||
ApiActions::SellGroupItems(id, params) => {
|
||||
conn.transaction(|| {
|
||||
for i in params.items.into_iter() {
|
||||
|
||||
}
|
||||
Err(diesel::result::Error::RollbackTransaction)
|
||||
});
|
||||
}
|
||||
ApiActions::ClaimItem(id, item) => {
|
||||
response.push_update(Update::ClaimAdded(
|
||||
db::Claims(conn).add(id, item)?,
|
||||
|
||||
Reference in New Issue
Block a user