preps undo actions
This commit is contained in:
43
src/api.rs
43
src/api.rs
@@ -120,25 +120,15 @@ pub fn execute(
|
||||
query: ApiActions,
|
||||
) -> Result<ApiResponse, diesel::result::Error> {
|
||||
let mut response = ApiResponse::default();
|
||||
match query {
|
||||
ApiActions::FetchPlayers => {
|
||||
response.set_value(Value::PlayerList(db::Players(conn).all()?));
|
||||
}
|
||||
ApiActions::FetchInventory => {
|
||||
response.set_value(Value::ItemList(db::Inventory(conn).all()?));
|
||||
}
|
||||
ApiActions::FetchClaims => {
|
||||
response.set_value(Value::ClaimList(db::fetch_claims(conn)?));
|
||||
}
|
||||
ApiActions::FetchPlayer(id) => {
|
||||
response.set_value(Value::Player(db::Players(conn).find(id)?));
|
||||
}
|
||||
ApiActions::FetchNotifications(id) => {
|
||||
response.set_value(Value::Notifications(db::AsPlayer(conn, id).notifications()?));
|
||||
}
|
||||
ApiActions::FetchLoot(id) => {
|
||||
response.set_value(Value::ItemList(db::LootManager(conn, id).all()?));
|
||||
}
|
||||
// TODO: Return an Option<String> that describes what happened.
|
||||
// If there is some value, store the actions in db so that it can be reversed.
|
||||
let _action_text: () = match query {
|
||||
ApiActions::FetchPlayers => response.set_value(Value::PlayerList(db::Players(conn).all()?)),
|
||||
ApiActions::FetchInventory => response.set_value(Value::ItemList(db::Inventory(conn).all()?)),
|
||||
ApiActions::FetchClaims => response.set_value(Value::ClaimList(db::fetch_claims(conn)?)),
|
||||
ApiActions::FetchPlayer(id) => response.set_value(Value::Player(db::Players(conn).find(id)?)),
|
||||
ApiActions::FetchNotifications(id) => response.set_value(Value::Notifications(db::AsPlayer(conn, id).notifications()?)),
|
||||
ApiActions::FetchLoot(id) => response.set_value(Value::ItemList(db::LootManager(conn, id).all()?)),
|
||||
ApiActions::UpdateWealth(id, amount) => {
|
||||
response.push_update(Update::Wealth(
|
||||
db::AsPlayer(conn, id).update_wealth(amount)?,
|
||||
@@ -224,6 +214,19 @@ pub fn execute(
|
||||
response.push_error(format!("Erreur durant la notification : {:?}", e));
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
// match _action_text -> Save updates in DB
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
/// Reverts the last action stored for player
|
||||
fn revert_last_action(
|
||||
conn: &DbConnection,
|
||||
id: i32,
|
||||
) -> Result<ApiResponse, diesel::result::Error> {
|
||||
let mut response = ApiResponse::default();
|
||||
// 1. Load the last action
|
||||
// 2. Iterate trought updates and reverse them (in a single transaction)
|
||||
// 3. Send nice message back ("'action desc text' annulé !")
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user