Displays available owned games for a GameNight.
This commit is contained in:
parent
0e89bca126
commit
8a48119c80
57
gamenight-cli/Cargo.lock
generated
57
gamenight-cli/Cargo.lock
generated
@ -210,6 +210,21 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-executor",
|
||||
"futures-io",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.31"
|
||||
@ -217,6 +232,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -225,6 +241,40 @@ version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-executor"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"futures-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.31"
|
||||
@ -237,10 +287,16 @@ version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -280,6 +336,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"clear_screen",
|
||||
"dyn-clone",
|
||||
"futures",
|
||||
"gamenight-api-client-rs",
|
||||
"inquire",
|
||||
"jsonwebtoken",
|
||||
|
@ -15,3 +15,4 @@ jsonwebtoken = "9.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
clear_screen = "0.1"
|
||||
futures = "0.3"
|
||||
|
@ -3,3 +3,4 @@ pub mod user;
|
||||
pub mod config;
|
||||
pub mod participants;
|
||||
pub mod game;
|
||||
pub mod owned_games;
|
18
gamenight-cli/src/domain/owned_games.rs
Normal file
18
gamenight-cli/src/domain/owned_games.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use std::{collections::HashMap, fmt::Display};
|
||||
|
||||
use crate::domain::game::Game;
|
||||
|
||||
|
||||
pub struct OwnedGames<'a>(pub &'a HashMap<String, Vec<Game>>);
|
||||
|
||||
impl<'a> Display for OwnedGames<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
for (k,v) in self.0 {
|
||||
write!(f, "{k}:\n")?;
|
||||
for g in v {
|
||||
write!(f, "\t{}\n", g.name)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
|
||||
use gamenight_api_client_rs::{apis::default_api::{participants_get, user_get}, models::{GamenightId, UserId}};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use futures::future::join_all;
|
||||
use gamenight_api_client_rs::{apis::default_api::{game_get, owned_games_get, participants_get, user_get, GameGetError}, models::{self, GameId, GamenightId, UserId}};
|
||||
use inquire::Select;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{domain::{gamenight::Gamenight, participants::Participants, user::User}, flows::{exit::Exit, join::Join, leave::Leave}};
|
||||
use crate::{domain::{game::Game, gamenight::Gamenight, owned_games::OwnedGames, participants::Participants, user::User}, flows::{exit::Exit, join::Join, leave::Leave}};
|
||||
|
||||
use super::*;
|
||||
|
||||
@ -33,6 +36,7 @@ impl<'a> Flow<'a> for ViewGamenight {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
|
||||
let participants = participants_get(&state.api_configuration, Some(GamenightId{gamenight_id: self.gamenight.id.to_string()})).await?;
|
||||
|
||||
let mut users = vec![];
|
||||
for participant in participants.participants.iter() {
|
||||
let user = user_get(&state.api_configuration, Some(UserId{user_id: participant.clone()})).await?;
|
||||
@ -42,7 +46,18 @@ impl<'a> Flow<'a> for ViewGamenight {
|
||||
});
|
||||
}
|
||||
|
||||
println!("{}\nwho: {}", self.gamenight, Participants(&users));
|
||||
let mut user_games: HashMap<String, Vec<Game>> = HashMap::new();
|
||||
for user in &users {
|
||||
let request = UserId{ user_id: user.id.to_string() };
|
||||
let games: Vec<Game> = join_all(owned_games_get(&state.api_configuration, Some(request)).await?
|
||||
.iter().map(async |game_id| -> Result<models::Game, Error<GameGetError>> {
|
||||
let request = GameId{ game_id: game_id.clone() };
|
||||
game_get(&state.api_configuration, Some(request)).await
|
||||
})).await.into_iter().collect::<Result<Vec<models::Game>, Error<GameGetError>>>()?.into_iter().map(Into::into).collect();
|
||||
user_games.insert(user.username.clone(), games);
|
||||
}
|
||||
|
||||
println!("{}\nwho: {}\nGames:\n{}", self.gamenight, Participants(&users), OwnedGames(&user_games));
|
||||
|
||||
let my_uid = state.get_user_id()?;
|
||||
let join_or_leave: Box<dyn Flow<'a> + Send> =
|
||||
|
Loading…
x
Reference in New Issue
Block a user