diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 23a58d8..c5ce9cb 100644 Binary files a/lootalot_db/db.sqlite3 and b/lootalot_db/db.sqlite3 differ diff --git a/lootalot_db/src/lib.rs b/lootalot_db/src/lib.rs index 5bfa01e..619e4d2 100644 --- a/lootalot_db/src/lib.rs +++ b/lootalot_db/src/lib.rs @@ -11,17 +11,23 @@ use diesel::query_dsl::RunQueryDsl; mod models; mod schema; +/// The connection used pub type DbConnection = SqliteConnection; +/// A pool of connections pub type Pool = r2d2::Pool>; +/// The result of a query on DB pub type QueryResult = Result; +/// The result of an action provided by DbApi pub type ActionResult = QueryResult>; +/// Return status of an API Action +/// #[derive(Serialize, Debug)] pub struct ActionStatus { /// Has the action made changes ? - executed: bool, + pub executed: bool, /// Response payload - response: R, + pub response: R, } impl ActionStatus<()> { @@ -43,7 +49,7 @@ impl ActionStatus<()> { /// It offers a convenient way to deal with connection /// /// # Todo list -/// +/// ``` /// 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) @@ -62,6 +68,7 @@ impl ActionStatus<()> { /// x .sell_loot([players], [excluded_item_ids]) -> Success status (bool, player_share) /// x .resolve_claims() /// v .add_player(player_data) +/// ``` /// pub struct DbApi<'q>(&'q DbConnection); @@ -201,7 +208,7 @@ impl<'q> AsPlayer<'q> { } } - +/// Wrapper for interactions of admins with the DB. pub struct AsAdmin<'q>(&'q DbConnection); impl<'q> AsAdmin<'q> { @@ -228,6 +235,8 @@ impl<'q> AsAdmin<'q> { } } +/// Create a connection pool and returns it. +/// Uses the DATABASE_URL environment variable (must be set) pub fn create_pool() -> Pool { let connspec = std::env::var("DATABASE_URL").expect("DATABASE_URL"); dbg!( &connspec ); diff --git a/lootalot_db/src/models/player.rs b/lootalot_db/src/models/player.rs index 9da8474..32e9a50 100644 --- a/lootalot_db/src/models/player.rs +++ b/lootalot_db/src/models/player.rs @@ -95,19 +95,21 @@ mod tests { use crate::tests; #[test] - fn new_player_only_with_name() { - let n = NewPlayer::new("Féfi", None); - assert_eq!(n.name, "Féfi"); - assert_eq!(n.cp, 0); - assert_eq!(n.sp, 0); - assert_eq!(n.gp, 0); - assert_eq!(n.pp, 0); + fn test_unpack_gold_values() { + use super::unpack_gold_value; + let test_values = [ + (1.0, (0,0,1,0)), + (1.23, (3,2,1,0)), + (1.03, (3,0,1,0)), + (100.23, (3,2,0,1)), + (-100.23, (-3,-2,-0,-1)), + (10189.23, (3,2,89,101)), + (-8090.20, (0,-2,-90,-80)) + ]; + + for (tested, expected) in test_values.into_iter() { + assert_eq!(unpack_gold_value(*tested), *expected); + } } - #[test] - fn new_player_with_wealth() { - let initial_wealth = (1, 2, 3, 4); - let n = NewPlayer::new("Féfi", Some(initial_wealth)); - assert_eq!(initial_wealth, (n.cp, n.sp, n.gp, n.pp)); - } } diff --git a/lootalot_front/src/AppStorage.js b/lootalot_front/src/AppStorage.js index be2b4dc..14fe619 100644 --- a/lootalot_front/src/AppStorage.js +++ b/lootalot_front/src/AppStorage.js @@ -61,6 +61,8 @@ export const AppStorage = { this.__initPlayerList(players); this.__initClaimsStore(claims); }); + // TODO: when __initPlayerList won't use promises + //.then(_ => this.state.initiated = true); }, __initClaimsStore(data) { for (var idx in data) {