refactors, makes Loot private to module
This commit is contained in:
@@ -18,6 +18,21 @@ pub struct Claim {
|
||||
pub resolve: i32,
|
||||
}
|
||||
|
||||
impl Claim {
|
||||
pub fn resolve_claim(&self, conn: &DbConnection) -> QueryResult<()> {
|
||||
let loot: Loot = Loot::find(self.loot_id).first(conn)?;
|
||||
loot.set_owner(self.player_id, conn)?;
|
||||
self.remove(conn)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn remove(&self, conn: &DbConnection) -> QueryResult<()> {
|
||||
diesel::delete(claims::table.find(self.id))
|
||||
.execute(conn)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Claims<'q>(pub &'q DbConnection);
|
||||
|
||||
impl<'q> Claims<'q> {
|
||||
@@ -48,8 +63,7 @@ impl<'q> Claims<'q> {
|
||||
/// Removes a claim from database, returning it
|
||||
pub fn remove(self, player_id: i32, loot_id: i32) -> QueryResult<Claim> {
|
||||
let claim = self.find(player_id, loot_id)?;
|
||||
diesel::delete(claims::table.find(claim.id))
|
||||
.execute(self.0)?;
|
||||
claim.remove(self.0)?;
|
||||
Ok(claim)
|
||||
}
|
||||
|
||||
@@ -59,13 +73,14 @@ impl<'q> Claims<'q> {
|
||||
.load(self.0)
|
||||
}
|
||||
|
||||
pub(crate) fn grouped_by_loot(&self) -> QueryResult<Vec<(models::item::Loot, Vec<Claim>)>> {
|
||||
let loot = models::item::Loot::owned_by(0).load(self.0)?;
|
||||
pub(crate) fn grouped_by_item(&self) -> QueryResult<Vec<(models::item::Item, Vec<Claim>)>> {
|
||||
let group_loot: Vec<Loot> = Loot::owned_by(0).load(self.0)?;
|
||||
let claims = claims::table
|
||||
.load(self.0)?
|
||||
.grouped_by(&loot);
|
||||
.grouped_by(&group_loot);
|
||||
Ok(
|
||||
loot.into_iter()
|
||||
group_loot.into_iter()
|
||||
.map(|loot| loot.into_item())
|
||||
.zip(claims)
|
||||
.collect::<Vec<_>>()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user