diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index f6442b3..260c96a 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -36,6 +36,12 @@ pub struct ActionStatus { } impl ActionStatus<()> { + fn was_updated(updated_lines: usize) -> Self { + match updated_lines { + 1 => Self::ok(), + _ => Self::nop(), + } + } fn ok() -> ActionStatus<()> { Self { executed: true, @@ -167,7 +173,6 @@ impl<'q> AsPlayer<'q> { .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 => ActionStatus { executed: true, @@ -190,24 +195,17 @@ impl<'q> AsPlayer<'q> { diesel::insert_into(schema::claims::table) .values(&claim) .execute(self.conn) - .map(|r| match r { - 1 => ActionStatus::ok(), - _ => ActionStatus::nop(), - }) + .map(ActionStatus::was_updated) } /// Withdraw claim pub fn unclaim(self, item: i32) -> ActionResult<()> { use schema::claims::dsl::*; diesel::delete( - claims - .filter(loot_id.eq(item)) - .filter(player_id.eq(self.id)), - ) - .execute(self.conn) - .map(|r| match r { - 1 => ActionStatus::ok(), - _ => ActionStatus::nop(), - }) + claims.filter(loot_id.eq(item)) + .filter(player_id.eq(self.id)), + ) + .execute(self.conn) + .map(ActionStatus::was_updated) } } @@ -219,10 +217,7 @@ impl<'q> AsAdmin<'q> { diesel::insert_into(schema::players::table) .values(&models::player::NewPlayer::create(&name, start_wealth)) .execute(self.0) - .map(|r| match r { - 1 => ActionStatus::ok(), - _ => ActionStatus::nop(), - }) + .map(ActionStatus::was_updated) } pub fn resolve_claims(self) -> ActionResult<()> {