Converted the Api to a Restful api.

This commit is contained in:
2026-01-22 22:51:03 +01:00
parent 79ba1e1b44
commit 9d3c5afb07
50 changed files with 2194 additions and 1939 deletions

View File

@@ -0,0 +1,28 @@
use actix_web::{get, web, HttpResponse, Responder};
use actix_web::http::header::ContentType;
use gamenight_database::{DbPool, GetConnection};
use gamenight_database::owned_game::owned_games;
use uuid::Uuid;
use crate::models;
use crate::request::authorization::AuthUser;
use crate::request::error::ApiError;
#[get("/user/{userId}/owned_games")]
pub async fn get_user_owned_games(
pool: web::Data<DbPool>,
_user: AuthUser,
user_id: web::Path<Uuid>
) -> Result<impl Responder, ApiError> {
let mut conn = pool.get_conn();
let game_ids = owned_games(&mut conn, user_id.into_inner())?;
let model = game_ids.iter().map(|(u,g , l)| models::owned_game::OwnedGame {
user_id: u.to_string(),
game_id: g.to_string(),
location_id: l.map(|x| x.to_string())
}).collect::<Vec<models::owned_game::OwnedGame>>();
Ok(HttpResponse::Ok()
.content_type(ContentType::json())
.body(serde_json::to_string(&model)?))
}