Rewrite to chatty but functional API.

This commit is contained in:
2025-06-14 22:16:13 +02:00
parent d1832bc794
commit db6f55bc47
20 changed files with 423 additions and 175 deletions

View File

@@ -1,8 +1,10 @@
use chrono::DateTime;
use gamenight_api_client_rs::apis::default_api::get_gamenights;
use inquire::Select;
use uuid::Uuid;
use crate::flows::view_gamenight::ViewGamenight;
use crate::{domain::{gamenight::Gamenight}, flows::view_gamenight::ViewGamenight};
use super::{exit::Exit, *};
@@ -22,9 +24,18 @@ impl<'a> Flow<'a> for ListGamenights {
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
let response = get_gamenights(&state.configuration).await?;
let mut view_flows = response.into_iter().map(|gamenight| -> Box<dyn Flow<'a> + Send> {
Box::new(ViewGamenight::new(gamenight.into()))
}).collect::<Vec<Box<dyn Flow<'a> + Send>>>();
let mut view_flows: Vec<Box<dyn Flow<'_> + 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)
@@ -38,5 +49,4 @@ impl Display for ListGamenights {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "List all gamenights")
}
}
}