Files
duty-teller/db/schemas.py
Nikolay Tatarinov 7a963eccd1 Add event type handling for duties in the system
- 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.
2026-02-17 23:01:07 +03:00

56 lines
1.1 KiB
Python

"""Pydantic schemas for API and validation."""
from typing import Literal
from pydantic import BaseModel, ConfigDict
class UserBase(BaseModel):
full_name: str
username: str | None = None
first_name: str | None = None
last_name: str | None = None
class UserCreate(UserBase):
telegram_user_id: int
class UserInDb(UserBase):
id: int
telegram_user_id: int
model_config = ConfigDict(from_attributes=True)
class DutyBase(BaseModel):
user_id: int
start_at: str # UTC, ISO 8601 with Z
end_at: str # UTC, ISO 8601 with Z
class DutyCreate(DutyBase):
pass
class DutyInDb(DutyBase):
id: int
model_config = ConfigDict(from_attributes=True)
class DutyWithUser(DutyInDb):
"""Duty with full_name and event_type for calendar display."""
full_name: str
event_type: Literal["duty", "unavailable", "vacation"] = "duty"
model_config = ConfigDict(from_attributes=True)
class CalendarEvent(BaseModel):
"""External calendar event (e.g. holiday) for a single day."""
date: str # YYYY-MM-DD
summary: str