
- Set up project structure with FastAPI and SQLite - Implement user authentication with JWT - Create database models for users, events, bets, and transactions - Add API endpoints for user management - Add API endpoints for events and betting functionality - Add wallet management for deposits and withdrawals - Configure Alembic for database migrations - Add linting with Ruff - Add documentation in README
71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
from enum import Enum as PyEnum
|
|
|
|
from sqlalchemy import (
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
Enum,
|
|
Float,
|
|
ForeignKey,
|
|
Integer,
|
|
String,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class EventStatus(str, PyEnum):
|
|
UPCOMING = "upcoming"
|
|
LIVE = "live"
|
|
FINISHED = "finished"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class Event(Base):
|
|
__tablename__ = "events"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
description = Column(String, nullable=True)
|
|
start_time = Column(DateTime(timezone=True), nullable=False)
|
|
end_time = Column(DateTime(timezone=True), nullable=True)
|
|
status = Column(Enum(EventStatus), default=EventStatus.UPCOMING)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
markets = relationship("Market", back_populates="event", cascade="all, delete-orphan")
|
|
|
|
|
|
class Market(Base):
|
|
__tablename__ = "markets"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
event_id = Column(Integer, ForeignKey("events.id"), nullable=False)
|
|
name = Column(String, nullable=False)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
event = relationship("Event", back_populates="markets")
|
|
outcomes = relationship("Outcome", back_populates="market", cascade="all, delete-orphan")
|
|
|
|
|
|
class Outcome(Base):
|
|
__tablename__ = "outcomes"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
market_id = Column(Integer, ForeignKey("markets.id"), nullable=False)
|
|
name = Column(String, nullable=False)
|
|
odds = Column(Float, nullable=False)
|
|
is_winner = Column(Boolean, nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
market = relationship("Market", back_populates="outcomes")
|
|
bets = relationship("Bet", back_populates="outcome") |