enhance responses from API, integrates with frontend
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use diesel::prelude::*;
|
||||
use diesel::dsl::{Eq, Filter, Select};
|
||||
use diesel::dsl::{Eq, Filter, Select, exists, Find };
|
||||
use diesel::expression::exists::Exists;
|
||||
use crate::schema::{looted, items};
|
||||
use crate::DbConnection;
|
||||
|
||||
@@ -33,8 +34,9 @@ type WithOwner = Eq<looted::owner_id, i32>;
|
||||
type OwnedLoot = Filter<looted::table, WithOwner>;
|
||||
|
||||
/// Represents an item that has been looted
|
||||
#[derive(Debug, Queryable, Serialize)]
|
||||
struct Loot {
|
||||
#[derive(Identifiable, Debug, Queryable, Serialize)]
|
||||
#[table_name="looted"]
|
||||
pub(crate) struct Loot {
|
||||
id: i32,
|
||||
name: String,
|
||||
base_value: i32,
|
||||
@@ -43,10 +45,14 @@ struct Loot {
|
||||
|
||||
impl Loot {
|
||||
/// A filter on Loot that is owned by given player
|
||||
fn owned_by(id: i32) -> OwnedLoot {
|
||||
pub(crate) fn owned_by(id: i32) -> OwnedLoot {
|
||||
looted::table
|
||||
.filter(looted::owner_id.eq(id))
|
||||
}
|
||||
|
||||
pub(crate) fn exists(id: i32) -> Exists<Find<looted::table, i32>> {
|
||||
exists(looted::table.find(id))
|
||||
}
|
||||
}
|
||||
|
||||
type ItemDesc<'a> = (&'a str, i32);
|
||||
|
||||
Reference in New Issue
Block a user