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,47 @@
|
||||
use axum::{extract::State, Json};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::{
|
||||
app::AppState,
|
||||
error::AppResult,
|
||||
models::market::{BuyListingRequest, SellCardRequest},
|
||||
services::{club as club_svc, market as market_svc, profile as profile_svc},
|
||||
};
|
||||
|
||||
pub async fn get_market(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
||||
let listings = market_svc::get_active_listings(&state.pool, &state.card_db).await?;
|
||||
Ok(Json(
|
||||
json!({ "listings": listings, "total": listings.len() }),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn post_market_buy(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<BuyListingRequest>,
|
||||
) -> 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 card = market_svc::buy_listing(&state.pool, &state.card_db, &club.id, &req).await?;
|
||||
Ok(Json(
|
||||
json!({ "purchased_card": card, "message": "Card purchased successfully" }),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn post_market_sell(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<SellCardRequest>,
|
||||
) -> 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 new_balance = market_svc::sell_card(&state.pool, &club.id, &req).await?;
|
||||
Ok(Json(
|
||||
json!({ "new_coin_balance": new_balance, "message": "Card sold to NPC market" }),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn post_market_refresh(State(state): State<AppState>) -> AppResult<Json<Value>> {
|
||||
let count = market_svc::refresh_npc_listings(&state.pool, &state.card_db).await?;
|
||||
Ok(Json(json!({ "listings_generated": count })))
|
||||
}
|
||||
Reference in New Issue
Block a user