Ability to have multiple bets per line.
This commit is contained in:
@ -75,30 +75,30 @@ async def get_event_with_grid(
|
||||
)
|
||||
bets = bets_result.scalars().all()
|
||||
|
||||
# Build spread grid with bet info
|
||||
# Build spread grid with bet info - now supports multiple bets per spread
|
||||
spread_grid = {}
|
||||
for spread in spreads:
|
||||
# Check for HOME team bet at this spread
|
||||
bet_at_spread = next(
|
||||
(b for b in bets if b.spread == spread and b.team == TeamSide.HOME),
|
||||
None
|
||||
)
|
||||
# Get ALL bets at this spread (both open and matched)
|
||||
bets_at_spread = [b for b in bets if b.spread == spread]
|
||||
|
||||
if bet_at_spread:
|
||||
spread_grid[str(spread)] = {
|
||||
"bet_id": bet_at_spread.id,
|
||||
"creator_id": bet_at_spread.creator_id,
|
||||
"creator_username": bet_at_spread.creator.username,
|
||||
"stake": float(bet_at_spread.stake_amount),
|
||||
"status": bet_at_spread.status.value,
|
||||
"team": bet_at_spread.team.value,
|
||||
"can_take": (
|
||||
bet_at_spread.status == SpreadBetStatus.OPEN and
|
||||
bet_at_spread.creator_id != current_user.id
|
||||
)
|
||||
}
|
||||
if bets_at_spread:
|
||||
spread_grid[str(spread)] = [
|
||||
{
|
||||
"bet_id": bet.id,
|
||||
"creator_id": bet.creator_id,
|
||||
"creator_username": bet.creator.username,
|
||||
"stake": float(bet.stake_amount),
|
||||
"status": bet.status.value,
|
||||
"team": bet.team.value,
|
||||
"can_take": (
|
||||
bet.status == SpreadBetStatus.OPEN and
|
||||
bet.creator_id != current_user.id
|
||||
)
|
||||
}
|
||||
for bet in bets_at_spread
|
||||
]
|
||||
else:
|
||||
spread_grid[str(spread)] = None
|
||||
spread_grid[str(spread)] = []
|
||||
|
||||
return {
|
||||
"id": event.id,
|
||||
|
||||
@ -51,20 +51,6 @@ async def create_spread_bet(
|
||||
detail=f"Spread must be between {event.min_spread} and {event.max_spread}"
|
||||
)
|
||||
|
||||
# Check for existing bet at this spread
|
||||
existing_result = await db.execute(
|
||||
select(SpreadBet).where(
|
||||
and_(
|
||||
SpreadBet.event_id == bet_data.event_id,
|
||||
SpreadBet.spread == bet_data.spread,
|
||||
SpreadBet.team == bet_data.team,
|
||||
SpreadBet.status == SpreadBetStatus.OPEN
|
||||
)
|
||||
)
|
||||
)
|
||||
if existing_result.scalar_one_or_none():
|
||||
raise HTTPException(status_code=400, detail="A bet already exists at this spread")
|
||||
|
||||
# Get admin settings for commission
|
||||
settings_result = await db.execute(select(AdminSettings).limit(1))
|
||||
settings = settings_result.scalar_one_or_none()
|
||||
|
||||
Reference in New Issue
Block a user