Major refactor of API #1
@@ -14,7 +14,6 @@ use diesel::query_dsl::RunQueryDsl;
|
|||||||
use diesel::r2d2::{self, ConnectionManager};
|
use diesel::r2d2::{self, ConnectionManager};
|
||||||
|
|
||||||
pub mod models;
|
pub mod models;
|
||||||
//mod updates;
|
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
pub use models::{
|
pub use models::{
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
//!
|
|
||||||
//! updates.rs
|
|
||||||
//!
|
|
||||||
//! Contains semantic mutations of database
|
|
||||||
//!
|
|
||||||
use crate::models::player::Wealth;
|
|
||||||
use crate::DbConnection;
|
|
||||||
|
|
||||||
type PlayerId = i32;
|
|
||||||
type ItemId = i32;
|
|
||||||
|
|
||||||
enum LootUpdate {
|
|
||||||
AddedItem(ItemId),
|
|
||||||
RemovedItem(Item),
|
|
||||||
GivenToPlayer(ItemId),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LootUpdate {
|
|
||||||
fn add_loot(
|
|
||||||
conn: &DbConnection,
|
|
||||||
to_player: PlayerId,
|
|
||||||
item_desc: Item,
|
|
||||||
) -> Result<Self, diesel::result::Error> {
|
|
||||||
use schema::looted::dsl::*;
|
|
||||||
let new_item = models::item::NewLoot::to_player(to_player, &item_desc);
|
|
||||||
diesel::insert_into(looted)
|
|
||||||
.values(&new_item)
|
|
||||||
.execute(conn)?;
|
|
||||||
// Return newly created
|
|
||||||
let created_id = looted.select(id).order(id.desc()).first(conn)?;
|
|
||||||
Ok(LootUpdate::AddedItem(created_id))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_loot(conn: &DbConnection, loot_id: ItemId) -> Result<Self, diesel::result::Error> {
|
|
||||||
use schema::looted::dsl::*;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn give_to_player(conn: &DbConnection, loot_id: ItemId) -> Result<Self, diesel::result::Error> {
|
|
||||||
use schema::looted::dsl::*;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LootUpdate {
|
|
||||||
fn undo(self, conn: &DbConnection) -> Result<(), diesel::result::Error> {
|
|
||||||
match self {
|
|
||||||
LootUpdate::AddedItem(item_id) => {
|
|
||||||
// Remove the item
|
|
||||||
}
|
|
||||||
LootUpdate::RemovedItem(item) => {
|
|
||||||
// Add the item back
|
|
||||||
}
|
|
||||||
LootUpdate::GivenToPlayer(item_id) => {
|
|
||||||
// Change owner to group
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum PlayerUpdate {
|
|
||||||
Wealth(Wealth),
|
|
||||||
ClaimItem(ItemId),
|
|
||||||
UnclaimItem(ItemId),
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user