forked from Roflin/gamenight
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
use std::fmt::Display;
|
|
|
|
use super::*;
|
|
use crate::flows::own::Own;
|
|
use async_trait::async_trait;
|
|
use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody};
|
|
use inquire::Text;
|
|
|
|
|
|
#[derive(Clone)]
|
|
pub struct AddGame {
|
|
}
|
|
|
|
impl AddGame {
|
|
pub fn new() -> Self {
|
|
Self {}
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<'a> Flow<'a> for AddGame {
|
|
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
|
if let Some(name) = Text::new("What is the game you want to add").prompt_skippable()? {
|
|
let add_game_request = AddGameRequestBody {
|
|
name
|
|
};
|
|
let game_id_response = game_post(&state.api_configuration, Some(add_game_request)).await?;
|
|
|
|
let own_flow = Own::new(Uuid::parse_str(&game_id_response.game_id)?);
|
|
return self.continue_with(state, &own_flow).await;
|
|
}
|
|
Ok((FlowOutcome::Cancelled, state))
|
|
}
|
|
}
|
|
|
|
impl Display for AddGame {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "Add Game")
|
|
}
|
|
} |