small refactoring

This commit is contained in:
2019-07-15 15:34:51 +02:00
parent 96f8e36c97
commit caabad3982

View File

@@ -36,6 +36,12 @@ pub struct ActionStatus<R: serde::Serialize> {
}
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))
claims.filter(loot_id.eq(item))
.filter(player_id.eq(self.id)),
)
.execute(self.conn)
.map(|r| match r {
1 => ActionStatus::ok(),
_ => ActionStatus::nop(),
})
.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<()> {