forked from Roflin/gamenight
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
|
|
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> {
|
|
let mut add_gamenight = models::AddGamenightRequestBody::new();
|
|
|
|
add_gamenight.name = Some(Text::new("What should we call your gamenight")
|
|
.prompt()?);
|
|
let naive_date = DateSelect::new("When is your gamenight")
|
|
.prompt()?;
|
|
let naive_time = CustomType::<NaiveTime>::new("At What time")
|
|
.prompt()?;
|
|
add_gamenight.datetime = Some(naive_date
|
|
.and_time(naive_time)
|
|
.and_local_timezone(Local)
|
|
.earliest()
|
|
.unwrap()
|
|
.to_utc()
|
|
.to_rfc3339());
|
|
|
|
post_gamenight(&state.configuration, Some(add_gamenight)).await?;
|
|
|
|
Ok((FlowOutcome::Successful, state))
|
|
}
|
|
}
|
|
|
|
impl Display for AddGamenight {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "Add Gamenight.")
|
|
}
|
|
}
|
|
|