starts improving REST Api

This commit is contained in:
2019-08-04 21:23:01 +02:00
parent e56c8df121
commit a0e4a02e0f
4 changed files with 72 additions and 51 deletions

View File

@@ -120,13 +120,10 @@ impl<'q> AsPlayer<'q> {
Ok(models::Item::owned_by(self.id).load(self.conn)?)
}
/// Buy an item and add it to this player chest
///
/// TODO: Items should be picked from a custom list
///
/// # Panics
///
/// This currently panics if player wealth fails to be updated, as this is
/// a serious error.
/// # Returns
/// Result containing the difference in coins after operation
pub fn buy<'a>(self, name: &'a str, price: i32) -> ActionResult<(i32, i32, i32, i32)> {
self.conn.transaction(|| {
let new_item = models::item::NewLoot::to_player(self.id, (name, price));
@@ -139,14 +136,11 @@ impl<'q> AsPlayer<'q> {
})?;
self.update_wealth(-(price as f32))
})
}
/// Sell an item from this player chest
///
/// # Panics
///
/// This currently panics if player wealth fails to be updated, as this is
/// a serious error.
/// # Returns
/// Result containing the difference in coins after operation
pub fn sell(
self,
loot_id: i32,