Implemented leaving a gamenight on the server/database side

This commit is contained in:
2025-06-15 19:11:26 +02:00
parent db6f55bc47
commit d11e31149b
5 changed files with 49 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
use actix_web::{post, web, HttpResponse, Responder};
use gamenight_database::{DbPool, GetConnection, gamenight_participants::{insert_gamenight_participant, GamenightParticipant}};
use gamenight_database::{gamenight_participants::{delete_gamenight_participant, insert_gamenight_participant, GamenightParticipant}, DbPool, GetConnection};
use uuid::Uuid;
use crate::{models::gamenight_id::GamenightId, request::{authorization::AuthUser, error::ApiError}};
@@ -16,3 +16,16 @@ pub async fn post_join_gamenight(pool: web::Data<DbPool>, user: AuthUser, gameni
Ok(HttpResponse::Ok())
}
#[post("/leave")]
pub async fn post_leave_gamenight(pool: web::Data<DbPool>, user: AuthUser, gamenight_id: web::Json<GamenightId>) -> Result<impl Responder, ApiError> {
web::block(move || -> Result<usize, ApiError> {
let mut conn = pool.get_conn();
Ok(delete_gamenight_participant(&mut conn, GamenightParticipant {
gamenight_id: Uuid::parse_str(&gamenight_id.gamenight_id)?,
user_id: user.id
})?)
}).await??;
Ok(HttpResponse::Ok())
}