|
| 1 | +from sqlalchemy import Boolean, Column, ForeignKey, Integer, Time |
| 2 | +from sqlalchemy.dialects.postgresql import UUID |
| 3 | +from sqlalchemy.orm import relationship |
| 4 | +from sqlalchemy.sql import func |
| 5 | +from sqlalchemy import DateTime |
| 6 | + |
| 7 | +from .Base import Base |
| 8 | + |
| 9 | + |
| 10 | +class AvailabilityTemplate(Base): |
| 11 | + """ |
| 12 | + Stores recurring weekly availability patterns for volunteers. |
| 13 | + Each template represents a time slot on a specific day of the week. |
| 14 | + These templates are projected forward to create specific TimeBlocks for matches. |
| 15 | + """ |
| 16 | + __tablename__ = "availability_templates" |
| 17 | + |
| 18 | + id = Column(Integer, primary_key=True) |
| 19 | + user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False) |
| 20 | + |
| 21 | + # Day of week: 0=Monday, 1=Tuesday, ..., 6=Sunday |
| 22 | + day_of_week = Column(Integer, nullable=False) |
| 23 | + |
| 24 | + # Time of day (just time, no date) |
| 25 | + start_time = Column(Time, nullable=False) # e.g., 14:00:00 |
| 26 | + end_time = Column(Time, nullable=False) # e.g., 16:00:00 |
| 27 | + |
| 28 | + # Optional: for future enhancements (e.g., temporarily disable a template) |
| 29 | + is_active = Column(Boolean, default=True) |
| 30 | + |
| 31 | + created_at = Column(DateTime(timezone=True), server_default=func.now()) |
| 32 | + updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now()) |
| 33 | + |
| 34 | + user = relationship("User", back_populates="availability_templates") |
| 35 | + |
0 commit comments