enhance responses from API, integrates with frontend

This commit is contained in:
2019-07-11 14:54:18 +02:00
parent bc65dfcd78
commit e08cd64743
9 changed files with 130 additions and 26 deletions

View File

@@ -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);