fixes some misbehaviour
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{DbConnection, QueryResult};
|
||||
use diesel::prelude::*;
|
||||
|
||||
use crate::{DbConnection, QueryResult, Update, UpdateResult};
|
||||
use crate::models::{self, item::Loot};
|
||||
use crate::schema::claims;
|
||||
|
||||
@@ -54,7 +54,7 @@ impl<'q> Claims<'q> {
|
||||
/// Will validate that the claimed item exists and is
|
||||
/// actually owned by the group.
|
||||
/// Duplicates are also ignored.
|
||||
pub fn add(self, player_id: i32, loot_id: i32) -> QueryResult<Claim> {
|
||||
pub fn add(self, player_id: i32, loot_id: i32) -> UpdateResult {
|
||||
// We need to validate that the claimed item exists
|
||||
// AND is actually owned by group (id 0)
|
||||
let _item = models::item::LootManager(self.0, 0).find(loot_id)?;
|
||||
@@ -68,16 +68,22 @@ impl<'q> Claims<'q> {
|
||||
.values(&claim)
|
||||
.execute(self.0)?;
|
||||
// Return the created claim
|
||||
claims::table
|
||||
.order(claims::dsl::id.desc())
|
||||
.first::<Claim>(self.0)
|
||||
Ok(
|
||||
Update::ClaimAdded(
|
||||
claims::table
|
||||
.order(claims::dsl::id.desc())
|
||||
.first::<Claim>(self.0)?
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/// Removes a claim from database, returning it
|
||||
pub fn remove(self, player_id: i32, loot_id: i32) -> QueryResult<Claim> {
|
||||
pub fn remove(self, player_id: i32, loot_id: i32) -> UpdateResult {
|
||||
let claim = self.find(player_id, loot_id)?;
|
||||
claim.remove(self.0)?;
|
||||
Ok(claim)
|
||||
Ok(
|
||||
Update::ClaimRemoved(claim)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn filtered_by_loot(&self, loot_id: i32) -> QueryResult<Vec<Claim>> {
|
||||
@@ -86,6 +92,15 @@ impl<'q> Claims<'q> {
|
||||
.load(self.0)
|
||||
}
|
||||
|
||||
pub(crate) fn delete_for_loot(&self, loot_id: i32) -> QueryResult<usize> {
|
||||
diesel::delete(
|
||||
claims::table
|
||||
.filter(claims::dsl::loot_id.eq(loot_id))
|
||||
)
|
||||
.execute(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(&group_loot);
|
||||
|
||||
Reference in New Issue
Block a user