Implemented deleting games as admin.
This commit is contained in:
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user