Rewrite to a API trait.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use gamenight_database::owned_game::OwnedGame;
|
||||
use crate::game::rename_game;
|
||||
use crate::owned_game::own_game;
|
||||
use crate::owned_game::owned_games;
|
||||
use crate::owned_game::disown_game;
|
||||
use crate::owned_game::OwnedGame;
|
||||
use gamenight_database::game::load_game;
|
||||
use crate::game::insert_game;
|
||||
use uuid::Uuid;
|
||||
@@ -13,13 +13,10 @@ use gamenight_database::{
|
||||
DbPool, GetConnection,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
models::{
|
||||
add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId,
|
||||
rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody
|
||||
},
|
||||
request::{authorization::AuthUser, error::ApiError},
|
||||
};
|
||||
use crate::{models, models::{
|
||||
add_game_request_body::AddGameRequestBody, game::Game, game_id::GameId,
|
||||
rename_game_request_body::RenameGameRequestBody, own_game_request_body::OwnGameRequestBody
|
||||
}, request::{authorization::AuthUser, error::ApiError}};
|
||||
|
||||
#[get("/games")]
|
||||
pub async fn get_games(
|
||||
@@ -162,7 +159,11 @@ pub async fn get_owned_games(
|
||||
let mut conn = pool.get_conn();
|
||||
let game_ids = owned_games(&mut conn, user.0.id)?;
|
||||
|
||||
let model: Vec<String> = game_ids.iter().map(|x| x.to_string()).collect();
|
||||
|
||||
let model = game_ids.iter().map(|(u, l)| models::owned_game::OwnedGame {
|
||||
game_id: u.to_string(),
|
||||
location_id: l.map(|x| x.to_string())
|
||||
}).collect::<Vec<models::owned_game::OwnedGame>>();
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.content_type(ContentType::json())
|
||||
|
||||
@@ -43,6 +43,7 @@ pub async fn gamenights(
|
||||
.map(|x| Gamenight {
|
||||
id: x.id.to_string(),
|
||||
name: x.name.clone(),
|
||||
location_id: x.location_id.map(|x| x.to_string()),
|
||||
datetime: x.datetime.to_rfc3339(),
|
||||
owner_id: x.owner_id.to_string(),
|
||||
})
|
||||
@@ -77,6 +78,7 @@ pub async fn gamenight_get(
|
||||
let model = Gamenight {
|
||||
id: gamenight.id.to_string(),
|
||||
datetime: gamenight.datetime.to_rfc3339(),
|
||||
location_id: gamenight.location_id.map(|x| x.to_string()),
|
||||
name: gamenight.name,
|
||||
owner_id: gamenight.owner_id.to_string(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user