Added some more gamenight-cli Flows.
This commit is contained in:
44
gamenight-cli/src/flows/add_gamenight.rs
Normal file
44
gamenight-cli/src/flows/add_gamenight.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
use gamenight_api_client_rs::{apis::default_api::post_gamenight, models};
|
||||
use inquire::{Text, DateSelect};
|
||||
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()?);
|
||||
add_gamenight.datetime = Some(DateSelect::new("When is your gamenight").prompt()?
|
||||
.and_time(NaiveTime::default())
|
||||
.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.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user