Added owning games and not willing to travel with them.
This commit is contained in:
@@ -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
|
||||
},
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user