Initial commit: OpenFUT Core
Offline Ultimate Team backend — game-independent REST API. - 19 API endpoints: auth, profiles, clubs, cards, packs, squads, objectives, SBCs, match rewards, NPC market, statistics - Axum + SQLite + SQLx with full migrations - Weighted pack generator, SBC validation engine - JSON-driven mod data (cards, packs, objectives, SBCs) - 5 integration tests passing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
use axum::{extract::State, Json};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::{
|
||||
app::AppState,
|
||||
error::AppResult,
|
||||
models::squad::SaveSquadRequest,
|
||||
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?;
|
||||
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?;
|
||||
|
||||
let enriched: Vec<Value> = players
|
||||
.iter()
|
||||
.map(|sp| {
|
||||
json!({
|
||||
"squad_player_id": sp.id,
|
||||
"owned_card_id": sp.owned_card_id,
|
||||
"position_index": sp.position_index,
|
||||
"is_captain": sp.is_captain,
|
||||
"is_on_bench": sp.is_on_bench,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Json(json!({
|
||||
"squad": {
|
||||
"id": squad.id,
|
||||
"name": squad.name,
|
||||
"formation": squad.formation,
|
||||
},
|
||||
"players": enriched,
|
||||
})))
|
||||
}
|
||||
|
||||
pub async fn post_squad(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<SaveSquadRequest>,
|
||||
) -> AppResult<Json<Value>> {
|
||||
let profile = profile_svc::get_active_profile(&state.pool).await?;
|
||||
let club = club_svc::get_club_by_profile(&state.pool, &profile.id).await?;
|
||||
|
||||
let squad = squad_svc::save_squad(&state.pool, &club.id, &req).await?;
|
||||
Ok(Json(json!({ "squad": squad })))
|
||||
}
|
||||
Reference in New Issue
Block a user