Cleans up the code a bit
This commit is contained in:
parent
df1e3ff905
commit
ad0e81fdc3
@ -25,11 +25,8 @@ pub async fn post_leave_gamenight(pool: web::Data<DbPool>, user: AuthUser, gamen
|
||||
gamenight_id: Uuid::parse_str(&gamenight_id.gamenight_id)?,
|
||||
user_id: user.0.id
|
||||
};
|
||||
println!("{:?}", participant);
|
||||
let x = delete_gamenight_participant(&mut conn, participant)?;
|
||||
|
||||
println!("Amount of deleted rows: {:?}", x);
|
||||
|
||||
Ok(x)
|
||||
}).await??;
|
||||
|
||||
|
@ -65,7 +65,7 @@ impl Config {
|
||||
let config_path = Self::config_path();
|
||||
if !fs::exists(&config_path)? {
|
||||
let config_error = ConfigError(format!("Cannot create parent directory for config file: {}", &config_path.display()).to_string());
|
||||
let _ = fs::create_dir_all(&config_path.parent().ok_or(config_error)?)?;
|
||||
fs::create_dir_all(config_path.parent().ok_or(config_error)?)?;
|
||||
|
||||
let config = Config::new();
|
||||
fs::write(&config_path, serde_json::to_string_pretty(&config)?.as_bytes())?;
|
||||
@ -83,3 +83,9 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ pub struct Participants<'a>(pub &'a Vec<User>);
|
||||
|
||||
impl<'a> Display for Participants<'a> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let string_list: Vec<String> = self.0.iter().map(|x| {format!("{}", x)}).collect();
|
||||
let string_list: Vec<String> = self.0.iter().map(|x| {format!("{x}")}).collect();
|
||||
write!(f, "{}", string_list.join(", "))
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ impl Connect {
|
||||
let instance_name: String;
|
||||
loop {
|
||||
if let Some(name) = Text::new("Name this instance:").prompt_skippable()? {
|
||||
if config.instances.iter().find(|x| x.name == name).is_none() {
|
||||
if config.instances.iter().any(|x| x.name == name) {
|
||||
instance_name = name;
|
||||
break;
|
||||
} else {
|
||||
@ -58,7 +58,7 @@ impl Connect {
|
||||
let instance = config.instances.iter_mut().find(|x| x.name == *instance_name).unwrap();
|
||||
instance.token = token.jwt_token.clone();
|
||||
api_configuration.bearer_access_token = token.jwt_token.clone();
|
||||
Config::save(&config)?;
|
||||
Config::save(config)?;
|
||||
Ok(true)
|
||||
}
|
||||
else {
|
||||
@ -80,7 +80,7 @@ impl Connect {
|
||||
}
|
||||
config.last_instance = Some(instance_name.clone());
|
||||
|
||||
Config::save(&config)?;
|
||||
Config::save(config)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -90,13 +90,11 @@ impl<'a> Flow<'a> for Connect {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
let mut instance = if let Some(instance) = self.instance.clone() {
|
||||
instance
|
||||
} else {
|
||||
if let Some(instance) = self.prompt_new_instance(&state.gamenight_configuration)? {
|
||||
instance
|
||||
}
|
||||
else {
|
||||
return Ok((FlowOutcome::Cancelled, state));
|
||||
}
|
||||
} else if let Some(instance) = self.prompt_new_instance(&state.gamenight_configuration)? {
|
||||
instance
|
||||
}
|
||||
else {
|
||||
return Ok((FlowOutcome::Cancelled, state));
|
||||
};
|
||||
|
||||
let instance_name = instance.name.clone();
|
||||
|
@ -25,7 +25,7 @@ impl RenameGame {
|
||||
impl<'a> Flow<'a> for RenameGame {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
if let Some(name) = Text::new(&format!("Rename {} to:", self.game.name))
|
||||
.with_initial_value(&format!("{}", self.game.name))
|
||||
.with_initial_value(&self.game.name)
|
||||
.prompt_skippable()?
|
||||
{
|
||||
let req = RenameGameRequestBody {
|
||||
|
@ -28,12 +28,12 @@ impl<'a> Flow<'a> for ViewGame {
|
||||
|
||||
println!("{}", game);
|
||||
|
||||
let owned_games: Vec<Uuid> = owned_games_get(&state.api_configuration).await?.iter().map(|x| -> Result<Uuid, FlowError> { Ok(Uuid::parse_str(&x)?) }).collect::<Result<Vec<Uuid>, FlowError>>()?;
|
||||
let owned_games: Vec<Uuid> = owned_games_get(&state.api_configuration).await?.iter().map(|x| -> Result<Uuid, FlowError> { Ok(Uuid::parse_str(x)?) }).collect::<Result<Vec<Uuid>, FlowError>>()?;
|
||||
|
||||
println!("game_id {:?}, owned_games {:?}", game.id, owned_games);
|
||||
|
||||
let own_or_disown: Box<dyn Flow<'a> + Send> =
|
||||
if owned_games.into_iter().find(|x| *x == game.id) != None {
|
||||
if owned_games.into_iter().any(|x| x == game.id) {
|
||||
Box::new(Disown::new(self.game.id))
|
||||
}
|
||||
else {
|
||||
|
@ -58,12 +58,12 @@ impl<'a> Flow<'a> for ViewGamenight {
|
||||
let mut validation = Validation::default();
|
||||
validation.insecure_disable_signature_validation();
|
||||
let claims = decode::<Claims>(
|
||||
&state.api_configuration.bearer_access_token.as_ref().unwrap(),
|
||||
state.api_configuration.bearer_access_token.as_ref().unwrap(),
|
||||
&decoding_key,
|
||||
&validation)?.claims;
|
||||
|
||||
let join_or_leave: Box<dyn Flow<'a> + Send> =
|
||||
if users.iter().map(|x| {x.id}).find(|x| *x == claims.uid) != None {
|
||||
if users.iter().map(|x| {x.id}).any(|x| x == claims.uid) {
|
||||
Box::new(Leave::new(self.gamenight.id))
|
||||
}
|
||||
else {
|
||||
|
@ -2,7 +2,6 @@ pub mod flows;
|
||||
pub mod domain;
|
||||
|
||||
use flows::{main::Main, Flow, GamenightState};
|
||||
use clear_screen;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user