Automated Action 0cd6e6441d Setup FastAPI REST API for Sports Betting Verification
- Set up FastAPI application structure
- Implemented SQLite database integration with SQLAlchemy
- Added Alembic migrations for database versioning
- Created bet model and API endpoints for CRUD operations
- Added comprehensive README with setup and usage instructions
- Added health check endpoint and CORS support
2025-06-07 13:06:19 +00:00

95 lines
2.1 KiB
Python

from typing import Any, List, Optional
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app import crud, schemas
from app.db.deps import get_db
router = APIRouter()
@router.get("/", response_model=List[schemas.bet.Bet])
def read_bets(
db: Session = Depends(get_db),
skip: int = 0,
limit: int = 100,
user_id: Optional[str] = None,
) -> Any:
"""
Retrieve bets.
Optionally filter by user_id.
"""
bets = crud.crud_bet.get_bets(db, skip=skip, limit=limit, user_id=user_id)
return bets
@router.post("/", response_model=schemas.bet.Bet, status_code=status.HTTP_201_CREATED)
def create_bet(
*,
db: Session = Depends(get_db),
bet_in: schemas.bet.BetCreate,
) -> Any:
"""
Create new bet.
"""
bet = crud.crud_bet.create_bet(db=db, bet=bet_in)
return bet
@router.get("/{id}", response_model=schemas.bet.Bet)
def read_bet(
*,
db: Session = Depends(get_db),
id: int,
) -> Any:
"""
Get bet by ID.
"""
bet = crud.crud_bet.get_bet(db=db, bet_id=id)
if not bet:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Bet not found",
)
return bet
@router.put("/{id}", response_model=schemas.bet.Bet)
def update_bet(
*,
db: Session = Depends(get_db),
id: int,
bet_in: schemas.bet.BetUpdate,
) -> Any:
"""
Update a bet.
"""
bet = crud.crud_bet.get_bet(db=db, bet_id=id)
if not bet:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Bet not found",
)
bet = crud.crud_bet.update_bet(db=db, bet_id=id, bet=bet_in)
return bet
@router.delete("/{id}", status_code=status.HTTP_204_NO_CONTENT, response_model=None)
def delete_bet(
*,
db: Session = Depends(get_db),
id: int,
) -> Any:
"""
Delete a bet.
"""
bet = crud.crud_bet.get_bet(db=db, bet_id=id)
if not bet:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Bet not found",
)
crud.crud_bet.delete_bet(db=db, bet_id=id)
return None