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.
This commit is contained in:
@@ -35,5 +35,7 @@ class Duty(Base):
|
||||
# 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")
|
||||
|
||||
@@ -102,9 +102,16 @@ def insert_duty(
|
||||
user_id: int,
|
||||
start_at: str,
|
||||
end_at: str,
|
||||
event_type: str = "duty",
|
||||
) -> Duty:
|
||||
"""Create a duty. start_at and end_at must be UTC, ISO 8601 with Z (e.g. 2025-01-15T09:00:00Z)."""
|
||||
duty = Duty(user_id=user_id, start_at=start_at, end_at=end_at)
|
||||
"""Create a duty. start_at and end_at must be UTC, ISO 8601 with Z.
|
||||
event_type: 'duty' | 'unavailable' | 'vacation'."""
|
||||
duty = Duty(
|
||||
user_id=user_id,
|
||||
start_at=start_at,
|
||||
end_at=end_at,
|
||||
event_type=event_type,
|
||||
)
|
||||
session.add(duty)
|
||||
session.commit()
|
||||
session.refresh(duty)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Pydantic schemas for API and validation."""
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
@@ -38,9 +40,10 @@ class DutyInDb(DutyBase):
|
||||
|
||||
|
||||
class DutyWithUser(DutyInDb):
|
||||
"""Duty with full_name for calendar display."""
|
||||
"""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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user