diff --git a/lootalot_db/src/models/player.rs b/lootalot_db/src/models/player.rs index eec543b..5d759dc 100644 --- a/lootalot_db/src/models/player.rs +++ b/lootalot_db/src/models/player.rs @@ -2,6 +2,7 @@ use crate::schema::players; use crate::serde_derive::Serialize; use crate::*; +/// Representation of a player in database #[derive(Debug, Queryable, Serialize)] pub struct Player { id: i32, @@ -13,6 +14,32 @@ pub struct Player { pp: i32, } +/// The sign of the update +enum WealthUpdateKind { + Income, + Expense, +} + +/// Representation of wealth value +type WealthValues = (i32, i32, i32, i32); + +/// Data used to update wealth +struct WealthUpdate { + kind: WealthUpdateKind, + values: WealthValues, +} + +impl WealthUpdate { + /// Create a new update + fn new(values: WealthValues, kind: WealthUpdateKind) -> Self { + WealthUpdate { kind, values } + } + + /// Apply the update to the specified player + fn apply_to(self, player_id: i32) {} +} + +/// Representation of a new player record #[derive(Insertable)] #[table_name = "players"] pub struct NewPlayer<'a> { @@ -24,7 +51,7 @@ pub struct NewPlayer<'a> { } impl<'a> NewPlayer<'a> { - fn new(name: &'a str, wealth: Option<(i32, i32, i32, i32)>) -> Self { + fn new(name: &'a str, wealth: Option) -> Self { let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0)); NewPlayer { name, @@ -35,7 +62,7 @@ impl<'a> NewPlayer<'a> { } } - fn insert(&self) -> Result<(), ()> { + fn insert(self) -> Result<(), ()> { Err(()) } } diff --git a/lootalot_front/src/AppStorage.js b/lootalot_front/src/AppStorage.js index 4db7294..5a44985 100644 --- a/lootalot_front/src/AppStorage.js +++ b/lootalot_front/src/AppStorage.js @@ -6,6 +6,14 @@ const PLAYER_LIST = [ {id: 3, name: "Fefi", wealth: [0,0,0,0], debt: 0}, ]; +const fetchPlayerList = function () { + +}; + +const fetchRequests = function () { + +}; + export const AppStorage = { debug: true, state: { diff --git a/src/api.rs b/src/api.rs index 8cbee32..c5e4527 100644 --- a/src/api.rs +++ b/src/api.rs @@ -30,7 +30,24 @@ mod player { } } +// struct DbApi<'q>(&'q DbConnection); +// ::new() -> DbApi<'q> (Db finds a connection by itself, usefull for cli) +// ::with_conn(conn) -> DbApi<'q> (uses a user-defined connection) +// .fetch_players() +// .with_player(player_id) -> AsPlayer<'q> +// .loot() -> List of items owned (Vec) +// .claim(item_id) -> Success status (bool) +// .unclaim(item_id) -> Success status (bool) +// .sell(item_id) -> Success status (bool, earned) +// fn db_call(f: fn(DbApi) -> ApiResponse) { ... } +// ApiResponse needs to be Serialize + +// endpoint example +// fn endpoint_name(params...) -> impl ... { +// let param_1 = { ... }; +// db_call(move |api| api.with_player(param_1).loot()) +// } pub fn players_list( pool: web::Data