Added owning games and not willing to travel with them.
This commit is contained in:
@@ -26,6 +26,6 @@ impl Display for Location {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, r#"name: {}
|
||||
address: {}
|
||||
note: {}"#, &self.name, &<std::option::Option<std::string::String> as Clone>::clone(&self.address).unwrap_or_default(), &<std::option::Option<std::string::String> as Clone>::clone(&self.note).unwrap_or_default())
|
||||
note: {}"#, &self.name, &<Option<String> as Clone>::clone(&self.address).unwrap_or_default(), &<Option<String> as Clone>::clone(&self.note).unwrap_or_default())
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody};
|
||||
use inquire::{Confirm, Text};
|
||||
|
||||
|
||||
use gamenight_api_client_rs::{apis::default_api::game_post, models::AddGameRequestBody, models::OwnGameRequestBody};
|
||||
use gamenight_api_client_rs::apis::default_api::{locations_get, own_post};
|
||||
use inquire::{Confirm, Select, Text};
|
||||
use crate::flows::flow_helpers::LocationSelectData;
|
||||
use crate::flows::own::Own;
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -25,13 +26,10 @@ impl<'a> Flow<'a> for AddGame {
|
||||
let add_game_request = AddGameRequestBody {
|
||||
name
|
||||
};
|
||||
game_post(&state.api_configuration, Some(add_game_request)).await?;
|
||||
let game_id_response = game_post(&state.api_configuration, Some(add_game_request)).await?;
|
||||
|
||||
if let Some(owned) = Confirm::new("Do you own this game?").prompt_skippable()? {
|
||||
if owned {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
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))
|
||||
}
|
||||
|
||||
25
gamenight-cli/src/flows/flow_helpers.rs
Normal file
25
gamenight-cli/src/flows/flow_helpers.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::fmt::{Display, Formatter};
|
||||
use gamenight_api_client_rs::models::Location;
|
||||
use uuid::Uuid;
|
||||
use crate::flows::FlowError;
|
||||
|
||||
pub struct LocationSelectData {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Display for LocationSelectData {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.name) }
|
||||
}
|
||||
|
||||
impl TryFrom<&Location> for LocationSelectData {
|
||||
type Error = FlowError;
|
||||
|
||||
fn try_from(value: &Location) -> Result<Self, Self::Error> {
|
||||
let uuid = Uuid::parse_str(&value.id)?;
|
||||
Ok(LocationSelectData {
|
||||
id: uuid,
|
||||
name: value.name.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl<'a> Flow<'a> for LocationAuthorize {
|
||||
authorized_user_ids.contains(&t.1.id)
|
||||
}).unzip();
|
||||
|
||||
let selections = MultiSelect::new("Which users should be able to host gamenights in this location?", options)
|
||||
let selections = MultiSelect::new("Which users should be able to host game nights in this location?", options)
|
||||
.with_default(&authorized_indices[..])
|
||||
.prompt_skippable()?;
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ mod list_locations;
|
||||
mod view_location;
|
||||
mod add_location;
|
||||
mod location_authorize;
|
||||
mod flow_helpers;
|
||||
|
||||
pub struct GamenightState {
|
||||
api_configuration: Configuration,
|
||||
|
||||
@@ -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