moves api to its own module, thinking about design to choose
This commit is contained in:
@@ -13,24 +13,36 @@ pub mod schema;
|
||||
pub type DbConnection = SqliteConnection;
|
||||
pub type Pool = r2d2::Pool<ConnectionManager<DbConnection>>;
|
||||
pub type QueryResult<T> = Result<T, diesel::result::Error>;
|
||||
pub type ActionResult = QueryResult<bool>;
|
||||
|
||||
pub use models::Item;
|
||||
pub use models::Player;
|
||||
|
||||
impl Player {
|
||||
/// Query the list of all players
|
||||
pub fn fetch_list(conn: &SqliteConnection) -> QueryResult<Vec<Self>> {
|
||||
use schema::players::dsl::*;
|
||||
Ok(players.load::<Self>(conn)?)
|
||||
Ok( players
|
||||
.load::<Self>(conn)?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn fetch_chest(player_id: i32, conn: &SqliteConnection) -> QueryResult<Vec<Item>> {
|
||||
/// Query the list of items belonging to player
|
||||
pub fn fetch_loot(player_id: i32, conn: &SqliteConnection) -> QueryResult<Vec<Item>> {
|
||||
use schema::looted::dsl::*;
|
||||
let owned = looted
|
||||
.filter(owner_id.eq(player_id))
|
||||
.select((id, name, base_price))
|
||||
.load::<Item>(conn)?;
|
||||
dbg!(&owned);
|
||||
Ok(owned)
|
||||
Ok( looted
|
||||
.filter(owner_id.eq(player_id))
|
||||
.select((id, name, base_price))
|
||||
.load::<Item>(conn)?
|
||||
)
|
||||
}
|
||||
|
||||
pub fn action_claim_object(player_id: i32, item_id: i32, conn: &DbConnection) -> ActionResult {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
pub fn action_withdraw_claim(player_id: i32, item_id: i32, conn: &DbConnection) -> ActionResult {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user