Implemented deleting games as admin.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use async_trait::async_trait;
|
||||
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::*;
|
||||
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)]
|
||||
|
||||
@@ -36,6 +36,7 @@ mod view_location;
|
||||
mod add_location;
|
||||
mod location_authorize;
|
||||
mod flow_helpers;
|
||||
mod remove_game;
|
||||
|
||||
pub struct GamenightState {
|
||||
api_configuration: Configuration,
|
||||
@@ -140,7 +141,7 @@ impl From<jsonwebtoken::errors::Error> for FlowError {
|
||||
pub enum FlowOutcome {
|
||||
Successful,
|
||||
Cancelled,
|
||||
Abort
|
||||
Abort,
|
||||
}
|
||||
|
||||
type FlowResult<'a> = Result<(FlowOutcome, &'a mut GamenightState), FlowError>;
|
||||
|
||||
38
gamenight-cli/src/flows/remove_game.rs
Normal file
38
gamenight-cli/src/flows/remove_game.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use gamenight_api_client_rs::models::GameId;
|
||||
|
||||
use super::{Flow, FlowResult, GamenightState};
|
||||
use crate::domain::game::Game;
|
||||
use crate::flows::list_games::ListGames;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RemoveGame {
|
||||
pub game: Game
|
||||
}
|
||||
|
||||
impl RemoveGame {
|
||||
pub fn new(game: Game) -> Self {
|
||||
Self{
|
||||
game
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Flow<'a> for RemoveGame {
|
||||
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
||||
let req = GameId {
|
||||
game_id: self.game.id.to_string()
|
||||
};
|
||||
gamenight_api_client_rs::apis::default_api::game_delete(&state.api_configuration, Some(req)).await?;
|
||||
self.continue_with(state, &ListGames::new()).await
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for RemoveGame {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Remove")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use inquire::Select;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{domain::game::Game, flows::{disown::Disown, exit::Exit, own::Own, rename_game::RenameGame}};
|
||||
|
||||
use crate::flows::remove_game::RemoveGame;
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -45,6 +45,7 @@ impl<'a> Flow<'a> for ViewGame {
|
||||
|
||||
let options: Vec<Box<dyn Flow<'a> + Send>> = vec![
|
||||
own_or_disown,
|
||||
Box::new(RemoveGame::new(game.clone())),
|
||||
Box::new(RenameGame::new(game.clone())),
|
||||
Box::new(Exit::new())
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user