Add 3 roles, settings for marathons
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey, Integer
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey, Integer, Boolean
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.core.database import Base
|
||||
@@ -12,24 +12,31 @@ class MarathonStatus(str, Enum):
|
||||
FINISHED = "finished"
|
||||
|
||||
|
||||
class GameProposalMode(str, Enum):
|
||||
ALL_PARTICIPANTS = "all_participants"
|
||||
ORGANIZER_ONLY = "organizer_only"
|
||||
|
||||
|
||||
class Marathon(Base):
|
||||
__tablename__ = "marathons"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
title: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
organizer_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
creator_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
status: Mapped[str] = mapped_column(String(20), default=MarathonStatus.PREPARING.value)
|
||||
invite_code: Mapped[str] = mapped_column(String(20), unique=True, nullable=False, index=True)
|
||||
is_public: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
game_proposal_mode: Mapped[str] = mapped_column(String(20), default=GameProposalMode.ALL_PARTICIPANTS.value)
|
||||
start_date: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
end_date: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
organizer: Mapped["User"] = relationship(
|
||||
creator: Mapped["User"] = relationship(
|
||||
"User",
|
||||
back_populates="organized_marathons",
|
||||
foreign_keys=[organizer_id]
|
||||
back_populates="created_marathons",
|
||||
foreign_keys=[creator_id]
|
||||
)
|
||||
participants: Mapped[list["Participant"]] = relationship(
|
||||
"Participant",
|
||||
|
||||
Reference in New Issue
Block a user