small refactoring
This commit is contained in:
@@ -36,6 +36,12 @@ pub struct ActionStatus<R: serde::Serialize> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActionStatus<()> {
|
impl ActionStatus<()> {
|
||||||
|
fn was_updated(updated_lines: usize) -> Self {
|
||||||
|
match updated_lines {
|
||||||
|
1 => Self::ok(),
|
||||||
|
_ => Self::nop(),
|
||||||
|
}
|
||||||
|
}
|
||||||
fn ok() -> ActionStatus<()> {
|
fn ok() -> ActionStatus<()> {
|
||||||
Self {
|
Self {
|
||||||
executed: true,
|
executed: true,
|
||||||
@@ -167,7 +173,6 @@ impl<'q> AsPlayer<'q> {
|
|||||||
.filter(id.eq(self.id))
|
.filter(id.eq(self.id))
|
||||||
.set(&update)
|
.set(&update)
|
||||||
.execute(self.conn)
|
.execute(self.conn)
|
||||||
// TODO: need to work out what this boolean REALLY means
|
|
||||||
.map(|r| match r {
|
.map(|r| match r {
|
||||||
1 => ActionStatus {
|
1 => ActionStatus {
|
||||||
executed: true,
|
executed: true,
|
||||||
@@ -190,24 +195,17 @@ impl<'q> AsPlayer<'q> {
|
|||||||
diesel::insert_into(schema::claims::table)
|
diesel::insert_into(schema::claims::table)
|
||||||
.values(&claim)
|
.values(&claim)
|
||||||
.execute(self.conn)
|
.execute(self.conn)
|
||||||
.map(|r| match r {
|
.map(ActionStatus::was_updated)
|
||||||
1 => ActionStatus::ok(),
|
|
||||||
_ => ActionStatus::nop(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
/// Withdraw claim
|
/// Withdraw claim
|
||||||
pub fn unclaim(self, item: i32) -> ActionResult<()> {
|
pub fn unclaim(self, item: i32) -> ActionResult<()> {
|
||||||
use schema::claims::dsl::*;
|
use schema::claims::dsl::*;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
claims
|
claims.filter(loot_id.eq(item))
|
||||||
.filter(loot_id.eq(item))
|
|
||||||
.filter(player_id.eq(self.id)),
|
.filter(player_id.eq(self.id)),
|
||||||
)
|
)
|
||||||
.execute(self.conn)
|
.execute(self.conn)
|
||||||
.map(|r| match r {
|
.map(ActionStatus::was_updated)
|
||||||
1 => ActionStatus::ok(),
|
|
||||||
_ => ActionStatus::nop(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,10 +217,7 @@ impl<'q> AsAdmin<'q> {
|
|||||||
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(|r| match r {
|
.map(ActionStatus::was_updated)
|
||||||
1 => ActionStatus::ok(),
|
|
||||||
_ => ActionStatus::nop(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_claims(self) -> ActionResult<()> {
|
pub fn resolve_claims(self) -> ActionResult<()> {
|
||||||
|
|||||||
Reference in New Issue
Block a user