
- 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
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
from enum import Enum as PyEnum
|
|
|
|
from sqlalchemy import Column, DateTime, Enum, Float, ForeignKey, Integer, String
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.session import Base
|
|
|
|
|
|
class TransactionType(str, PyEnum):
|
|
DEPOSIT = "deposit"
|
|
WITHDRAWAL = "withdrawal"
|
|
BET_PLACED = "bet_placed"
|
|
BET_WON = "bet_won"
|
|
BET_LOST = "bet_lost"
|
|
BET_REFUND = "bet_refund"
|
|
|
|
|
|
class TransactionStatus(str, PyEnum):
|
|
PENDING = "pending"
|
|
COMPLETED = "completed"
|
|
FAILED = "failed"
|
|
CANCELLED = "cancelled"
|
|
|
|
|
|
class Transaction(Base):
|
|
__tablename__ = "transactions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
|
amount = Column(Float, nullable=False)
|
|
transaction_type = Column(Enum(TransactionType), nullable=False)
|
|
status = Column(Enum(TransactionStatus), default=TransactionStatus.PENDING)
|
|
reference = Column(String, nullable=True) # For external references
|
|
bet_id = Column(Integer, ForeignKey("bets.id"), nullable=True) # Optional link to a bet
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="transactions")
|
|
bet = relationship("Bet", backref="transactions") |