feat(link_codes): linking method between telegram and website

This commit is contained in:
2026-08-18 21:10:57 +07:00
parent 7ae3c98585
commit 771d44d34c
12 changed files with 247 additions and 9 deletions

28
db/models/link_codes.py Normal file
View File

@@ -0,0 +1,28 @@
from datetime import UTC, datetime
from sqlalchemy import TEXT, DateTime, Enum, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column
from db.base import Base
from schemas.enums import LinkCodeStatus
class LinkCode(Base):
__tablename__ = "link_codes"
code: Mapped[str] = mapped_column(TEXT, nullable=False, unique=True, primary_key=True)
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
status: Mapped[LinkCodeStatus] = mapped_column(
Enum(LinkCodeStatus, name="linkcodestatus"), nullable=False, default=LinkCodeStatus.ACTIVE
)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
default=lambda: datetime.now(UTC),
)
expires_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
nullable=False,
)
used_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=True)