diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index 83a1d20..3509296 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -138,7 +138,7 @@ impl<'q> AsPlayer<'q> { if let Ok((item, diff)) = self.conn.transaction(|| { use schema::looted::dsl::*; let item = schema::items::table.find(item_id).first::(self.conn)?; - let new_item = models::item::NewLoot::to_player(self.id, (&item.name, item.base_price)); + let new_item = models::item::NewLoot::to_player(self.id, &item); diesel::insert_into(schema::looted::table) .values(&new_item) .execute(self.conn)?; @@ -285,8 +285,8 @@ impl<'q> AsAdmin<'q> { /// /// # Params /// List of (name, base_price) values for the new items - pub fn add_loot(self, items: Vec<(&str, i32)>) -> ActionResult<()> { - for item_desc in items.into_iter() { + pub fn add_loot(self, items: Vec) -> ActionResult<()> { + for item_desc in items.iter() { let new_item = models::item::NewLoot::to_group(item_desc); diesel::insert_into(schema::looted::table) .values(&new_item) diff --git a/lootalot_db/src/models/item.rs b/lootalot_db/src/models/item.rs index bce60f3..5389d4e 100644 --- a/lootalot_db/src/models/item.rs +++ b/lootalot_db/src/models/item.rs @@ -12,7 +12,7 @@ type OwnedBy = Select; /// It is also used as a public representation of Loot, since owner /// information is implicit. /// Or maybe this is a little too confusing ?? -#[derive(Debug, Queryable, Serialize)] +#[derive(Debug, Queryable, Serialize, Deserialize, Clone)] pub struct Item { pub id: i32, pub name: String, @@ -54,9 +54,6 @@ impl Loot { } } -/// Description of an item : (name, value in gold) -pub type ItemDesc<'a> = (&'a str, i32); - /// An item being looted or bought. /// /// The owner is set to 0 in case of looting, @@ -71,19 +68,19 @@ pub(crate) struct NewLoot<'a> { impl<'a> NewLoot<'a> { /// A new loot going to the group (loot procedure) - pub(crate) fn to_group(desc: ItemDesc<'a>) -> Self { + pub(crate) fn to_group(desc: &'a Item) -> Self { Self { - name: desc.0, - base_price: desc.1, + name: &desc.name, + base_price: desc.base_price, owner_id: 0, } } /// A new loot going to a specific player (buy procedure) - pub(crate) fn to_player(player: i32, desc: ItemDesc<'a>) -> Self { + pub(crate) fn to_player(player: i32, desc: &'a Item) -> Self { Self { - name: desc.0, - base_price: desc.1, + name: &desc.name, + base_price: desc.base_price, owner_id: player, } } diff --git a/lootalot_db/src/models/mod.rs b/lootalot_db/src/models/mod.rs index 32afa0f..33147a4 100644 --- a/lootalot_db/src/models/mod.rs +++ b/lootalot_db/src/models/mod.rs @@ -3,6 +3,6 @@ pub(super) mod item; pub(super) mod player; pub use claim::Claim; -pub use item::Item; +pub use item::{Item}; pub(crate) use item::Loot; pub use player::{Player, Wealth}; diff --git a/lootalot_front/src/App.vue b/lootalot_front/src/App.vue index fcf96b5..06aa34e 100644 --- a/lootalot_front/src/App.vue +++ b/lootalot_front/src/App.vue @@ -56,14 +56,12 @@