Added owning games and not willing to travel with them.
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::{Flow, FlowError, FlowOutcome, FlowResult, GamenightState};
|
||||
use crate::flows::flow_helpers::LocationSelectData;
|
||||
use async_trait::async_trait;
|
||||
use gamenight_api_client_rs::{apis::default_api::own_post, models::GameId};
|
||||
use gamenight_api_client_rs::apis::default_api::locations_get;
|
||||
use gamenight_api_client_rs::models::OwnGameRequestBody;
|
||||
use gamenight_api_client_rs::apis::default_api::own_post;
|
||||
use inquire::{Confirm, Select};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{Flow, FlowOutcome, FlowResult, GamenightState};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Own {
|
||||
game_id: Uuid
|
||||
@@ -22,7 +25,25 @@ impl Own {
|
||||
#[async_trait]
|
||||
impl<'a> Flow<'a> for Own {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
let _ = own_post(&state.api_configuration, Some(GameId{game_id: self.game_id.to_string()})).await?;
|
||||
|
||||
let mut own_game_request = OwnGameRequestBody {
|
||||
game_id: self.game_id.to_string(),
|
||||
location_id: None
|
||||
};
|
||||
|
||||
if let Some(owned) = Confirm::new("Do you own this game?").prompt_skippable()? {
|
||||
if owned {
|
||||
if let Some(willing_to_travel) = Confirm::new("Are you willing to travel with this game?").prompt_skippable()? {
|
||||
if !willing_to_travel {
|
||||
let locations = locations_get(&state.api_configuration).await?.iter().map(|x| { x.try_into() }).collect::<Result<Vec<LocationSelectData>, FlowError>>()?;
|
||||
if let Some(location) = Select::new("What location can this game be played?", locations).prompt_skippable()? {
|
||||
own_game_request.location_id = Some(location.id.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = own_post(&state.api_configuration, Some(own_game_request)).await?;
|
||||
}
|
||||
}
|
||||
|
||||
clear_screen::clear();
|
||||
Ok((FlowOutcome::Successful, state))
|
||||
|
||||
Reference in New Issue
Block a user