adds nicer notifications to user
This commit is contained in:
21
src/api.rs
21
src/api.rs
@@ -133,7 +133,6 @@ pub fn execute(
|
||||
let mut cumulated_diff: Vec<db::Wealth> = Vec::with_capacity(params.len());
|
||||
let mut added_items: u16 = 0;
|
||||
for (item_id, price_mod) in params.into_iter() {
|
||||
// Use a transaction to avoid incoherant state in case of error
|
||||
if let Ok((item, diff)) = db::buy_item_from_inventory(conn, id, item_id, price_mod) {
|
||||
cumulated_diff.push(diff);
|
||||
response.push_update(Update::ItemAdded(item));
|
||||
@@ -142,12 +141,11 @@ pub fn execute(
|
||||
response.push_error(format!("Error adding {}", item_id));
|
||||
}
|
||||
}
|
||||
response.notify(format!("Added {} items", added_items));
|
||||
response.push_update(Update::Wealth(
|
||||
cumulated_diff
|
||||
let total_amount = cumulated_diff
|
||||
.into_iter()
|
||||
.fold(db::Wealth::from_gp(0.0), |acc, i| acc + i),
|
||||
));
|
||||
.fold(db::Wealth::from_gp(0.0), |acc, i| acc + i);
|
||||
response.notify(format!("{} objets achetés pour {}po", added_items, total_amount.to_gp()));
|
||||
response.push_update(Update::Wealth(total_amount));
|
||||
}
|
||||
ApiActions::SellItems(id, params) => {
|
||||
let mut all_results: Vec<db::Wealth> = Vec::with_capacity(params.len());
|
||||
@@ -161,22 +159,23 @@ pub fn execute(
|
||||
response.push_error(format!("Error selling {}", loot_id));
|
||||
}
|
||||
}
|
||||
response.notify(format!("Sold {} items", sold_items));
|
||||
response.push_update(Update::Wealth(
|
||||
all_results
|
||||
let total_amount = all_results
|
||||
.into_iter()
|
||||
.fold(db::Wealth::from_gp(0.0), |acc, i| acc + i),
|
||||
));
|
||||
.fold(db::Wealth::from_gp(0.0), |acc, i| acc + i);
|
||||
response.notify(format!("{} objet(s) vendu(s) pour {} po", sold_items, total_amount.to_gp()));
|
||||
response.push_update(Update::Wealth(total_amount));
|
||||
}
|
||||
ApiActions::ClaimItem(id, item) => {
|
||||
response.push_update(Update::ClaimAdded(
|
||||
db::Claims(conn).add(id, item)?,
|
||||
));
|
||||
response.notify(format!("Pour moi !"));
|
||||
}
|
||||
ApiActions::UnclaimItem(id, item) => {
|
||||
response.push_update(Update::ClaimRemoved(
|
||||
db::Claims(conn).remove(id, item)?,
|
||||
));
|
||||
response.notify(format!("Bof! Finalement non."));
|
||||
}
|
||||
// Group actions
|
||||
ApiActions::AddLoot(items) => {}
|
||||
|
||||
Reference in New Issue
Block a user