feat(backend): add market metadata storage and outcomes extension
This commit is contained in:
@@ -7,6 +7,8 @@ from app.schemas.dtos import (
|
||||
TokenResponse,
|
||||
AccountBalanceDTO,
|
||||
LedgerEntryDTO,
|
||||
CreateMarketMetadataRequest,
|
||||
ResolveMarketRequest,
|
||||
MarketDTO,
|
||||
CreateOrderRequest,
|
||||
OrderDTO
|
||||
@@ -24,6 +26,39 @@ async def login_with_wallet(req: UserAuthRequest, session: AsyncSession = Depend
|
||||
return TokenResponse(access_token=token, address=req.address.lower())
|
||||
|
||||
# ================= Market Routes =================
|
||||
@api_router.post("/markets/metadata", response_model=MarketDTO)
|
||||
async def create_market_metadata(
|
||||
req: CreateMarketMetadataRequest,
|
||||
current_user: str = Depends(get_current_user),
|
||||
session: AsyncSession = Depends(get_db_session)
|
||||
):
|
||||
"""保存预测市场的链下元数据 (标题, 描述, 类别, 2~255个选项)"""
|
||||
market_service = MarketService(session)
|
||||
market = await market_service.save_market_metadata(
|
||||
market_address=req.market_address,
|
||||
question_id=req.question_id,
|
||||
title=req.title,
|
||||
description=req.description,
|
||||
category=req.category,
|
||||
outcomes=req.outcomes,
|
||||
resolution_time=req.resolution_time,
|
||||
creator=current_user
|
||||
)
|
||||
return MarketDTO(
|
||||
market_address=market.market_address,
|
||||
question_id=market.question_id,
|
||||
title=market.title,
|
||||
description=market.description,
|
||||
category=market.category,
|
||||
tier=market.tier,
|
||||
creator=market.creator,
|
||||
status=market.status.value if hasattr(market.status, 'value') else str(market.status),
|
||||
outcomes=market.outcomes,
|
||||
winning_outcome=market.winning_outcome,
|
||||
resolution_time=market.resolution_time,
|
||||
created_at=market.created_at
|
||||
)
|
||||
|
||||
@api_router.get("/markets", response_model=List[MarketDTO])
|
||||
async def get_markets(
|
||||
category: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user