Implemented deleting games as admin.

This commit is contained in:
2026-01-02 15:24:38 +01:00
parent 0c256846f6
commit 661a63af8f
13 changed files with 168 additions and 23 deletions

View File

@@ -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)]

View File

@@ -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>;

View 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")
}
}

View File

@@ -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())
];