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

@@ -201,9 +201,21 @@ paths:
$ref: '#/components/requestBodies/AddGameRequest'
security:
- JWT-Auth: []
delete:
responses:
'200':
description: "Ok"
'401':
$ref: '#/components/responses/FailureResponse'
'422':
$ref: '#/components/responses/FailureResponse'
requestBody:
$ref: '#/components/requestBodies/RemoveGameRequest'
security:
- JWT-Auth: [ ]
/rename_game:
post:
responses:
responses:
'200':
description: "OK"
'401':
@@ -315,9 +327,6 @@ paths:
$ref: '#/components/requestBodies/AuthorizedLocationUserIdsRequest'
security:
- JWT-Auth: []
components:
schemas:
Gamenight:
@@ -590,6 +599,11 @@ components:
application/json:
schema:
$ref: '#/components/schemas/RenameGameRequestBody'
RemoveGameRequest:
content:
application/json:
schema:
$ref: '#/components/schemas/GameId'
OwnGameRequest:
content:
application/json:

View File

@@ -56,6 +56,7 @@ async fn main() -> std::io::Result<()> {
.service(post_own_game)
.service(post_disown_game)
.service(get_owned_games)
.service(delete_game)
.service(get_locations)
.service(post_location)
.service(post_location_authorize)

View File

@@ -21,13 +21,6 @@ pub struct Claims {
pub struct AuthUser(pub User);
// pub struct AuthUser {
// pub id: Uuid,
// pub username: String,
// pub email: String,
// pub role: Role,
// }
impl From<User> for AuthUser {
fn from(value: User) -> Self {
Self(value)

View File

@@ -1,10 +1,17 @@
use actix_web::{get, http::header::ContentType, post, web, HttpResponse, Responder};
use crate::game::rename_game;
use crate::owned_game::own_game;
use crate::owned_game::owned_games;
use crate::owned_game::disown_game;
use crate::owned_game::OwnedGame;
use gamenight_database::game::load_game;
use crate::game::insert_game;
use uuid::Uuid;
use crate::game::remove_game;
use actix_web::{delete, get, http::header::ContentType, post, web, HttpResponse, Responder};
use gamenight_database::{
game::{insert_game, load_game, rename_game},
owned_game::{disown_game, own_game, owned_games, OwnedGame},
user::Role,
DbPool, GetConnection,
};
use uuid::Uuid;
use crate::{
models::{
@@ -77,6 +84,22 @@ pub async fn post_game(
.body(serde_json::to_string(&GameId{game_id: game.id.to_string()})?))
}
#[delete("/game")]
pub async fn delete_game(
pool: web::Data<DbPool>,
user: AuthUser,
game_id: web::Json<GameId>,
) -> Result<impl Responder, ApiError> {
if user.0.role != Role::Admin {
Ok(HttpResponse::Unauthorized())
} else {
let mut conn = pool.get_conn();
remove_game(&mut conn, Uuid::parse_str(&game_id.0.game_id)?)?;
Ok(HttpResponse::Ok())
}
}
#[post("/rename_game")]
pub async fn post_rename_game(
pool: web::Data<DbPool>,

View File

@@ -15,6 +15,7 @@ pub use game::post_disown_game;
pub use game::post_game;
pub use game::post_own_game;
pub use game::post_rename_game;
pub use game::delete_game;
pub use gamenight_handlers::gamenight_get;
pub use gamenight_handlers::gamenight_post;
pub use gamenight_handlers::gamenights;