use actix_web::{post, web, HttpResponse, Responder}; 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}}; #[post("/join")] pub async fn post_join_gamenight(pool: web::Data, user: AuthUser, gamenight_id: web::Json) -> Result { web::block(move || -> Result { let mut conn = pool.get_conn(); Ok(insert_gamenight_participant(&mut conn, GamenightParticipant { gamenight_id: Uuid::parse_str(&gamenight_id.gamenight_id)?, user_id: user.id })?) }).await??; Ok(HttpResponse::Ok()) } #[post("/leave")] pub async fn post_leave_gamenight(pool: web::Data, user: AuthUser, gamenight_id: web::Json) -> Result { web::block(move || -> Result { 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()) }