begins work on updates

This commit is contained in:
2019-07-01 16:05:42 +02:00
parent 5f598aff24
commit 9acedd4119
2 changed files with 36 additions and 34 deletions

View File

@@ -26,6 +26,7 @@ pub type ActionResult = QueryResult<bool>;
/// ::new() -> DbApi<'q> (Db finds a connection by itself, usefull for cli)
/// ::with_conn(conn) -> DbApi<'q> (uses a user-defined connection)
/// v .fetch_players()
/// x .fetch_inventory()
/// v .as_player(player_id) -> AsPlayer<'q>
/// v .loot() -> List of items owned (Vec<Item>)
/// x .claim(item_id) -> Success status (bool)
@@ -35,8 +36,9 @@ pub type ActionResult = QueryResult<bool>;
/// x .update_wealth(gold_pieces) -> Success status (bool, new_wealth)
/// x .as_admin()
/// x .add_loot([inventory_item_ids]) -> Success status
/// x .resolve_claims()
/// x .sell_loot([players], [excluded_item_ids]) -> Success status (bool, player_share)
/// x .resolve_claims()
/// x .add_player(player_data)
///
pub struct DbApi<'q>(&'q DbConnection);
@@ -60,6 +62,15 @@ impl<'q> DbApi<'q> {
.load::<models::Player>(self.0)?
)
}
/// Fetch the inventory of items
///
/// Consumes the DbApi instance
pub fn fetch_inventory(self) -> QueryResult<Vec<models::Item>> {
Ok(
schema::items::table
.load::<models::Item>(self.0)?
)
}
/// Wrapper for acting as a specific player
///
/// The DbApi is moved inside a new AsPlayer object.
@@ -89,6 +100,15 @@ impl<'q> AsPlayer<'q> {
.load(self.conn)?
)
}
pub fn update_wealth(self, value: f32) -> ActionResult {
Ok(
false
// TODO:
// models::player::WealthUpdate::from_gp(self.id, value)
// .save_changes(&conn)?;
)
}
/// Put a claim on a specific item
pub fn claim(self, item: i32) -> ActionResult {
Ok(false)