use gamenight_api_client_rs::{apis::default_api::post_gamenight, models}; use inquire::{CustomType, DateSelect, Text}; use chrono::{self, Local, NaiveTime}; use super::*; #[derive(Clone)] pub struct AddGamenight { } impl AddGamenight { pub fn new() -> Self { Self {} } } #[async_trait] impl<'a> Flow<'a> for AddGamenight { async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> { if let Some(name) = Text::new("What should we call your gamenight").prompt_skippable()? { if let Some(naive_date) = DateSelect::new("When is your gamenight").prompt_skippable()? { if let Some(naive_time) = CustomType::::new("At What time").prompt_skippable()? { let datetime = naive_date .and_time(naive_time) .and_local_timezone(Local) .earliest() .unwrap() .to_utc() .to_rfc3339(); let add_gamenight = models::AddGamenightRequestBody::new(name, datetime); post_gamenight(&state.api_configuration, Some(add_gamenight)).await?; clear_screen::clear(); return Ok((FlowOutcome::Successful, state)) } } } Ok((FlowOutcome::Cancelled, state)) } } impl Display for AddGamenight { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Add Gamenight.") } }