feat(user): add monthly playcounts

This commit is contained in:
MingxuanGame
2025-07-31 02:13:18 +00:00
parent 9ce99398ab
commit a15c3cef04
5 changed files with 99 additions and 26 deletions

View File

@@ -0,0 +1,43 @@
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 MonthlyPlaycounts(SQLModel, 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)
)
year: int = Field(index=True)
month: int = Field(index=True)
playcount: int = Field(default=0)
user: "User" = Relationship(back_populates="monthly_playcounts")
class MonthlyPlaycountsResp(SQLModel):
start_date: date
count: int
@classmethod
def from_db(cls, db_model: MonthlyPlaycounts) -> "MonthlyPlaycountsResp":
return cls(
start_date=date(db_model.year, db_model.month, 1),
count=db_model.playcount,
)