impls wealth updating

This commit is contained in:
2019-07-02 15:07:03 +02:00
parent 9acedd4119
commit 36c8f24fdc
5 changed files with 57 additions and 17 deletions

View File

@@ -6,8 +6,7 @@ extern crate serde_derive;
use diesel::prelude::*;
use diesel::r2d2::{self, ConnectionManager};
// Convenience re-export, maybe DbApi should me move here instead ??
pub use diesel::query_dsl::RunQueryDsl;
use diesel::query_dsl::RunQueryDsl;
mod models;
mod schema;
@@ -101,13 +100,20 @@ impl<'q> AsPlayer<'q> {
)
}
pub fn update_wealth(self, value: f32) -> ActionResult {
Ok(
false
// TODO:
// models::player::WealthUpdate::from_gp(self.id, value)
// .save_changes(&conn)?;
)
use schema::players::dsl::*;
let current_wealth = players.find(self.id)
.select((cp, sp, gp, pp))
.first::<models::WealthUpdate>(self.conn)?;
// TODO: improve this
// should be move inside a WealthUpdate method
let update =
models::WealthUpdate::from_gp(current_wealth.to_gp() + value);
diesel::update(players)
.filter(id.eq(self.id))
.set(&update)
.execute(self.conn)
// TODO: need to work out what this boolean REALLY means
.map(|r| match r { 1 => true, _ => false })
}
/// Put a claim on a specific item
pub fn claim(self, item: i32) -> ActionResult {