use chrono::DateTime; use gamenight_api_client_rs::apis::default_api::get_gamenights; use inquire::Select; use uuid::Uuid; use crate::{domain::{gamenight::Gamenight}, flows::view_gamenight::ViewGamenight}; use super::{exit::Exit, *}; #[derive(Clone)] pub struct ListGamenights { } impl ListGamenights { pub fn new() -> Self { Self {} } } #[async_trait] impl<'a> Flow<'a> for ListGamenights { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { let response = get_gamenights(&state.api_configuration).await?; let mut view_flows: Vec + Send>> = vec![]; for response in response.iter() { let gamenight = Gamenight { id: Uuid::parse_str(&response.id)?, name: response.name.clone(), start_time:DateTime::parse_from_rfc3339(&response.datetime)?.into(), owner_id: Uuid::parse_str(&response.owner_id)? }; view_flows.push(Box::new(ViewGamenight::new(gamenight))); } view_flows.push(Box::new(Exit::new())); let choice = Select::new("What gamenight would you like to view?", view_flows).prompt_skippable()?; self.continue_choice(state, &choice).await } } impl Display for ListGamenights { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "List all gamenights") } }