makes adding loot working
This commit is contained in:
@@ -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::<models::Item>(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<models::item::Item>) -> 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)
|
||||
|
||||
@@ -12,7 +12,7 @@ type OwnedBy = Select<OwnedLoot, ItemColumns>;
|
||||
/// 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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user