- Introduced a new `event_type` column in the `duties` table to categorize duties as 'duty', 'unavailable', or 'vacation'. - Updated the duty schedule import functionality to parse and store event types from the JSON input. - Enhanced the API response to include event types for each duty, improving the calendar display logic. - Modified the web application to visually differentiate between duty types in the calendar and duty list. - Updated tests to cover new event type functionality and ensure correct parsing and storage of duties. - Revised README documentation to reflect changes in duty event types and their representation in the system.
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
"""SQLAlchemy ORM models for users and duties."""
|
|
|
|
from sqlalchemy import ForeignKey, Integer, BigInteger, Text
|
|
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
"""Declarative base for all models."""
|
|
|
|
pass
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
telegram_user_id: Mapped[int | None] = mapped_column(
|
|
BigInteger, unique=True, nullable=True
|
|
)
|
|
full_name: Mapped[str] = mapped_column(Text, nullable=False)
|
|
username: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
first_name: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
last_name: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
duties: Mapped[list["Duty"]] = relationship("Duty", back_populates="user")
|
|
|
|
|
|
class Duty(Base):
|
|
__tablename__ = "duties"
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id"), nullable=False
|
|
)
|
|
# UTC, ISO 8601 with Z suffix (e.g. 2025-01-15T09:00:00Z)
|
|
start_at: Mapped[str] = mapped_column(Text, nullable=False)
|
|
end_at: Mapped[str] = mapped_column(Text, nullable=False)
|
|
# duty | unavailable | vacation
|
|
event_type: Mapped[str] = mapped_column(Text, nullable=False, server_default="duty")
|
|
|
|
user: Mapped["User"] = relationship("User", back_populates="duties")
|