feat(score): support download replay
This commit is contained in:
58
app/database/counts.py
Normal file
58
app/database/counts.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from datetime import date
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlmodel import (
|
||||
BigInteger,
|
||||
Column,
|
||||
Field,
|
||||
ForeignKey,
|
||||
Relationship,
|
||||
SQLModel,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .lazer_user import User
|
||||
|
||||
|
||||
class CountBase(SQLModel):
|
||||
year: int = Field(index=True)
|
||||
month: int = Field(index=True)
|
||||
count: int = Field(default=0)
|
||||
|
||||
|
||||
class MonthlyPlaycounts(CountBase, table=True):
|
||||
__tablename__ = "monthly_playcounts" # pyright: ignore[reportAssignmentType]
|
||||
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(BigInteger, primary_key=True, autoincrement=True),
|
||||
)
|
||||
user_id: int = Field(
|
||||
sa_column=Column(BigInteger, ForeignKey("lazer_users.id"), index=True)
|
||||
)
|
||||
user: "User" = Relationship(back_populates="monthly_playcounts")
|
||||
|
||||
|
||||
class ReplayWatchedCount(CountBase, table=True):
|
||||
__tablename__ = "replays_watched_counts" # pyright: ignore[reportAssignmentType]
|
||||
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(BigInteger, primary_key=True, autoincrement=True),
|
||||
)
|
||||
user_id: int = Field(
|
||||
sa_column=Column(BigInteger, ForeignKey("lazer_users.id"), index=True)
|
||||
)
|
||||
user: "User" = Relationship(back_populates="replays_watched_counts")
|
||||
|
||||
|
||||
class CountResp(SQLModel):
|
||||
start_date: date
|
||||
count: int
|
||||
|
||||
@classmethod
|
||||
def from_db(cls, db_model: CountBase) -> "CountResp":
|
||||
return cls(
|
||||
start_date=date(db_model.year, db_model.month, 1),
|
||||
count=db_model.count,
|
||||
)
|
||||
Reference in New Issue
Block a user