wip: checkpoint multi-game core work
This commit is contained in:
+12
-8
@@ -1,3 +1,4 @@
|
||||
use crate::extractors::GameId;
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
Json,
|
||||
@@ -11,8 +12,8 @@ use crate::{
|
||||
services::{club as club_svc, profile as profile_svc, squad as squad_svc},
|
||||
};
|
||||
|
||||
pub async fn get_squad(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
pub async fn get_squad(State(state): State<AppState>, game: GameId) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool, game.as_str()).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
|
||||
let (squad, players) = squad_svc::get_squad(&state.pool, &club.id).await?;
|
||||
@@ -21,8 +22,8 @@ pub async fn get_squad(State(state): State<AppState>) -> AppResult<Json<Value>>
|
||||
Ok(Json(squad_response(&squad, &players, chemistry)))
|
||||
}
|
||||
|
||||
pub async fn get_squads(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
pub async fn get_squads(State(state): State<AppState>, game: GameId) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool, game.as_str()).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
let squads = squad_svc::list_squads(&state.pool, &club.id).await?;
|
||||
Ok(Json(json!({ "squads": squads })))
|
||||
@@ -30,9 +31,10 @@ pub async fn get_squads(State(state): State<AppState>) -> AppResult<Json<Value>>
|
||||
|
||||
pub async fn get_squad_by_id(
|
||||
State(state): State<AppState>,
|
||||
game: GameId,
|
||||
Path(squad_id): Path<String>,
|
||||
) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
let profile = profile_svc::get_active_profile(&state.pool, game.as_str()).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
|
||||
let (squad, players) = squad_svc::get_squad_by_id(&state.pool, &club.id, &squad_id).await?;
|
||||
@@ -43,13 +45,14 @@ pub async fn get_squad_by_id(
|
||||
|
||||
pub async fn post_squad(
|
||||
State(state): State<AppState>,
|
||||
game: GameId,
|
||||
Json(req): Json<SaveSquadRequest>,
|
||||
) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
let profile = profile_svc::get_active_profile(&state.pool, game.as_str()).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
|
||||
if !req.players.is_empty() {
|
||||
squad_svc::validate_formation(&state.pool, &state.card_db, &req.players).await?;
|
||||
squad_svc::validate_formation(&state.pool, &state.card_db, &club.id, &req.players).await?;
|
||||
}
|
||||
|
||||
let squad = squad_svc::save_squad(&state.pool, &club.id, &req).await?;
|
||||
@@ -58,9 +61,10 @@ pub async fn post_squad(
|
||||
|
||||
pub async fn delete_squad(
|
||||
State(state): State<AppState>,
|
||||
game: GameId,
|
||||
Path(squad_id): Path<String>,
|
||||
) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
let profile = profile_svc::get_active_profile(&state.pool, game.as_str()).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
squad_svc::delete_squad(&state.pool, &club.id, &squad_id).await?;
|
||||
Ok(Json(json!({ "deleted": squad_id })))
|
||||
|
||||
Reference in New Issue
Block a user