Implemented deleting games as admin.
This commit is contained in:
@@ -21,7 +21,7 @@ async fn main() -> std::io::Result<()> {
|
||||
let mut conn = pool.get_conn();
|
||||
run_migration(&mut conn);
|
||||
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug"));
|
||||
|
||||
HttpServer::new(move || {
|
||||
let cors = Cors::default()
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user