Added owning games and not willing to travel with them.

This commit is contained in:
2025-12-30 21:18:16 +01:00
parent ff88029a4b
commit 0c256846f6
45 changed files with 595 additions and 92 deletions

View File

@@ -9,7 +9,7 @@ use uuid::Uuid;
use crate::{
models::{
add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId,
rename_game_request_body::RenameGameRequestBody,
rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody
},
request::{authorization::AuthUser, error::ApiError},
};
@@ -69,9 +69,12 @@ pub async fn post_game(
game_data: web::Json<AddGameRequestBody>,
) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
insert_game(&mut conn, game_data.0.into())?;
let game = game_data.0.into();
insert_game(&mut conn, &game)?;
Ok(HttpResponse::Ok())
Ok(HttpResponse::Ok()
.content_type(ContentType::json())
.body(serde_json::to_string(&GameId{game_id: game.id.to_string()})?))
}
#[post("/rename_game")]
@@ -94,14 +97,15 @@ pub async fn post_rename_game(
pub async fn post_own_game(
pool: web::Data<DbPool>,
user: AuthUser,
game_id: web::Json<GameId>,
own_data: web::Json<OwnGameRequestBody>,
) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
own_game(
&mut conn,
OwnedGame {
user_id: user.0.id,
game_id: Uuid::parse_str(&game_id.0.game_id)?,
game_id: Uuid::parse_str(&own_data.game_id)?,
location_id: own_data.location_id.clone().map(|x| Uuid::parse_str(&x).unwrap()),
},
)?;
@@ -120,6 +124,7 @@ pub async fn post_disown_game(
OwnedGame {
user_id: user.0.id,
game_id: Uuid::parse_str(&game_id.0.game_id)?,
location_id: None
},
)?;