little fixes
This commit is contained in:
@@ -150,7 +150,7 @@ impl<'q> AsPlayer<'q> {
|
|||||||
pub fn sell(
|
pub fn sell(
|
||||||
self,
|
self,
|
||||||
loot_id: i32,
|
loot_id: i32,
|
||||||
_price_mod: Option<f32>,
|
price_mod: Option<f32>,
|
||||||
) -> ActionResult<(i32, i32, i32, i32)> {
|
) -> ActionResult<(i32, i32, i32, i32)> {
|
||||||
self.conn.transaction(|| {
|
self.conn.transaction(|| {
|
||||||
use schema::looted::dsl::*;
|
use schema::looted::dsl::*;
|
||||||
@@ -162,7 +162,10 @@ impl<'q> AsPlayer<'q> {
|
|||||||
// it can't be what we're looking for
|
// it can't be what we're looking for
|
||||||
return Err(diesel::result::Error::NotFound);
|
return Err(diesel::result::Error::NotFound);
|
||||||
}
|
}
|
||||||
let sell_value = (loot.base_price / 2) as f32;
|
let mut sell_value = (loot.base_price / 2) as f32;
|
||||||
|
if let Some(modifier) = price_mod {
|
||||||
|
sell_value *= modifier;
|
||||||
|
}
|
||||||
let _deleted = diesel::delete(looted.find(loot_id))
|
let _deleted = diesel::delete(looted.find(loot_id))
|
||||||
.execute(self.conn)?;
|
.execute(self.conn)?;
|
||||||
self.update_wealth(sell_value)
|
self.update_wealth(sell_value)
|
||||||
@@ -233,9 +236,9 @@ impl<'q> AsAdmin<'q> {
|
|||||||
/// Adds a player to the database
|
/// Adds a player to the database
|
||||||
///
|
///
|
||||||
/// Takes the player name and starting wealth (in gold value).
|
/// Takes the player name and starting wealth (in gold value).
|
||||||
pub fn add_player(self, name: String, start_wealth: f32) -> ActionResult<()> {
|
pub fn add_player(self, name: &str, start_wealth: f32) -> ActionResult<()> {
|
||||||
diesel::insert_into(schema::players::table)
|
diesel::insert_into(schema::players::table)
|
||||||
.values(&models::player::NewPlayer::create(&name, start_wealth))
|
.values(&models::player::NewPlayer::create(name, start_wealth))
|
||||||
.execute(self.0)
|
.execute(self.0)
|
||||||
.map(|rows_updated| match rows_updated {
|
.map(|rows_updated| match rows_updated {
|
||||||
1 => (),
|
1 => (),
|
||||||
@@ -244,7 +247,7 @@ impl<'q> AsAdmin<'q> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a list of items to the group loot
|
/// Adds a list of items to the group loot
|
||||||
pub fn add_loot<'a>(self, items: Vec<(&'a str, i32)>) -> ActionResult<()> {
|
pub fn add_loot(self, items: Vec<(&str, i32)>) -> ActionResult<()> {
|
||||||
for item_desc in items.into_iter() {
|
for item_desc in items.into_iter() {
|
||||||
let new_item = models::item::NewLoot::to_group(item_desc);
|
let new_item = models::item::NewLoot::to_group(item_desc);
|
||||||
diesel::insert_into(schema::looted::table)
|
diesel::insert_into(schema::looted::table)
|
||||||
@@ -336,7 +339,7 @@ mod tests {
|
|||||||
let conn = test_connection();
|
let conn = test_connection();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
.add_player("PlayerName".to_string(), 403.21)
|
.add_player("PlayerName", 403.21)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let diff = DbApi::with_conn(&conn)
|
let diff = DbApi::with_conn(&conn)
|
||||||
.as_player(1)
|
.as_player(1)
|
||||||
@@ -359,7 +362,7 @@ mod tests {
|
|||||||
let conn = test_connection();
|
let conn = test_connection();
|
||||||
let result = DbApi::with_conn(&conn)
|
let result = DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
.add_player("PlayerName".to_string(), 403.21);
|
.add_player("PlayerName", 403.21);
|
||||||
assert_eq!(result.is_ok(), true);
|
assert_eq!(result.is_ok(), true);
|
||||||
let players = DbApi::with_conn(&conn).fetch_players().unwrap();
|
let players = DbApi::with_conn(&conn).fetch_players().unwrap();
|
||||||
assert_eq!(players.len(), 2);
|
assert_eq!(players.len(), 2);
|
||||||
@@ -383,8 +386,8 @@ mod tests {
|
|||||||
("Arc", 40),
|
("Arc", 40),
|
||||||
]).is_ok(), true);
|
]).is_ok(), true);
|
||||||
// Add players
|
// Add players
|
||||||
DbApi::with_conn(&conn).as_admin().add_player("Player1".to_string(), 0.0).unwrap();
|
DbApi::with_conn(&conn).as_admin().add_player("Player1", 0.0).unwrap();
|
||||||
DbApi::with_conn(&conn).as_admin().add_player("Player2".to_string(), 0.0).unwrap();
|
DbApi::with_conn(&conn).as_admin().add_player("Player2", 0.0).unwrap();
|
||||||
// Put claims on one different item each
|
// Put claims on one different item each
|
||||||
DbApi::with_conn(&conn).as_player(1).claim(1).unwrap();
|
DbApi::with_conn(&conn).as_player(1).claim(1).unwrap();
|
||||||
DbApi::with_conn(&conn).as_player(2).claim(2).unwrap();
|
DbApi::with_conn(&conn).as_player(2).claim(2).unwrap();
|
||||||
@@ -404,7 +407,7 @@ mod tests {
|
|||||||
let conn = test_connection();
|
let conn = test_connection();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
.add_player("Player".to_string(), 0.0)
|
.add_player("Player", 0.0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
@@ -428,7 +431,7 @@ mod tests {
|
|||||||
let conn = test_connection();
|
let conn = test_connection();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
.add_player("Player".to_string(), 0.0)
|
.add_player("Player", 0.0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
@@ -460,7 +463,7 @@ mod tests {
|
|||||||
let conn = test_connection();
|
let conn = test_connection();
|
||||||
DbApi::with_conn(&conn)
|
DbApi::with_conn(&conn)
|
||||||
.as_admin()
|
.as_admin()
|
||||||
.add_player("Player".to_string(), 1000.0)
|
.add_player("Player", 1000.0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Buy an item
|
// Buy an item
|
||||||
let bought = DbApi::with_conn(&conn)
|
let bought = DbApi::with_conn(&conn)
|
||||||
|
|||||||
Reference in New Issue
Block a user