- Introduced a new `spin_sessions` table to track user spin activities. - Updated the API to include a new endpoint for spinning games, allowing users to place bets and specify spin counts. - Enhanced game information structure and added validation for bets and spin counts. - Implemented the `Forest Fortune` slot game mechanics, including payline evaluation and scatter functionality. - Updated dependencies in `pyproject.toml` for development and added `httpx` for HTTP requests. - Added unit tests for the new slot mechanics and API endpoints to ensure functionality and reliability.
57 lines
2.6 KiB
Python
57 lines
2.6 KiB
Python
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Numeric, String, BigInteger, Text, Integer, func
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
telegram_id: Mapped[int | None] = mapped_column(BigInteger, unique=True, index=True, nullable=True)
|
|
username: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
first_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
balance: Mapped[Decimal] = mapped_column(Numeric(18, 2), default=Decimal("0.00"), nullable=False)
|
|
agreement_accepted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
onupdate=func.now(),
|
|
nullable=False,
|
|
)
|
|
|
|
deposits: Mapped[list["Deposit"]] = relationship(back_populates="user", cascade="all, delete-orphan")
|
|
spin_sessions: Mapped[list["SpinSession"]] = relationship(
|
|
back_populates="user", cascade="all, delete-orphan"
|
|
)
|
|
|
|
|
|
class Deposit(Base):
|
|
__tablename__ = "deposits"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True, nullable=False)
|
|
amount: Mapped[Decimal] = mapped_column(Numeric(18, 2), nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
|
|
user: Mapped[User] = relationship(back_populates="deposits")
|
|
|
|
|
|
class SpinSession(Base):
|
|
__tablename__ = "spin_sessions"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True, nullable=False)
|
|
slug: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
|
bet: Mapped[Decimal] = mapped_column(Numeric(18, 2), nullable=False)
|
|
spin_count: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
total_win: Mapped[Decimal] = mapped_column(Numeric(18, 2), nullable=False)
|
|
payload_json: Mapped[str] = mapped_column(Text, nullable=False)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
|
|
user: Mapped[User] = relationship(back_populates="spin_sessions")
|