forked from Roflin/gamenight
Displays available owned games for a GameNight.
This commit is contained in:
@@ -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> =
|
||||
|
||||
Reference in New Issue
Block a user