Spaces:
Running
Running
Download backend/app/models/booking.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 5.35 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/models/booking.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/models/booking.py
-
curl -L -o booking.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/models/booking.py
5.35 kB
| from sqlmodel import SQLModel, Field, Relationship, Column | |
| from sqlalchemy import JSON, TEXT, Date, Time, DateTime | |
| from typing import Optional, List, Dict, Any | |
| from datetime import datetime, date, time | |
| from uuid import UUID, uuid4 | |
| from enum import Enum | |
| class AppointmentStatus(str, Enum): | |
| SCHEDULED = "scheduled" | |
| COMPLETED = "completed" | |
| CANCELLED = "cancelled" | |
| NO_SHOW = "no_show" | |
| class Resource(SQLModel, table=True): | |
| """ | |
| Bookable resource: table, master, doctor, room, computer, etc. | |
| Universal for all business types. | |
| """ | |
| __tablename__ = "booking_resources" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| tenant_id: UUID = Field(foreign_key="tenants.id", index=True) | |
| name: str # "Стол 1", "Мастер Иван", "Кабинет 5", "ПК-12" | |
| description: Optional[str] = Field(default=None, sa_column=Column(TEXT)) | |
| # Working hours per day of week (JSON) | |
| # Format: {"0": {"start": "09:00", "end": "21:00"}, "1": {...}, ...} | |
| # Key = day of week (0=Monday, 6=Sunday), null = day off | |
| working_hours: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON)) | |
| # Order for display | |
| sort_order: int = Field(default=0) | |
| is_active: bool = Field(default=True) | |
| # Telegram notifications for this resource (expert) | |
| # When a client books this resource, send notification to this chat | |
| telegram_chat_id: Optional[str] = Field(default=None) # Expert's Telegram chat ID | |
| # Link to manager (User) who owns this resource | |
| # Enables: permission control, Telegram ID sync, filtered calendar view | |
| user_id: Optional[UUID] = Field(default=None, foreign_key="users.id", index=True) | |
| created_at: datetime = Field(default_factory=datetime.utcnow) | |
| # Relationships | |
| appointments: List["Appointment"] = Relationship(back_populates="resource") | |
| resource_services: List["ResourceService"] = Relationship(back_populates="resource") | |
| tenant: Optional["Tenant"] = Relationship(back_populates="resources") | |
| class ResourceService(SQLModel, table=True): | |
| """ | |
| Many-to-many link: which resources can provide which services. | |
| E.g., Master Ivan can do haircuts and beard trimming. | |
| """ | |
| __tablename__ = "booking_resource_services" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| resource_id: UUID = Field(foreign_key="booking_resources.id", index=True) | |
| service_id: UUID = Field(foreign_key="booking_services.id", index=True) | |
| # Relationships | |
| resource: Optional["Resource"] = Relationship(back_populates="resource_services") | |
| service: Optional["Service"] = Relationship(back_populates="resource_services") | |
| class Service(SQLModel, table=True): | |
| """Service that can be booked (e.g. Demo Call, Consultation).""" | |
| __tablename__ = "booking_services" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| tenant_id: UUID = Field(foreign_key="tenants.id", index=True) | |
| name: str | |
| description: Optional[str] = Field(default=None, sa_column=Column(TEXT)) | |
| duration_minutes: int = Field(default=30) | |
| price: float = Field(default=0.0) | |
| currency: str = Field(default="USD") | |
| is_active: bool = Field(default=True) | |
| # Relationships | |
| availabilities: List["Availability"] = Relationship(back_populates="service") | |
| appointments: List["Appointment"] = Relationship(back_populates="service") | |
| resource_services: List["ResourceService"] = Relationship(back_populates="service") | |
| tenant: Optional["Tenant"] = Relationship(back_populates="services") | |
| class Availability(SQLModel, table=True): | |
| """Availability rules for a service.""" | |
| __tablename__ = "booking_availabilities" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| service_id: UUID = Field(foreign_key="booking_services.id", index=True) | |
| # Recurring availability | |
| day_of_week: int = Field(description="0=Monday, 6=Sunday") | |
| start_time: time = Field(sa_column=Column(Time)) | |
| end_time: time = Field(sa_column=Column(Time)) | |
| is_active: bool = Field(default=True) | |
| service: Optional[Service] = Relationship(back_populates="availabilities") | |
| class Appointment(SQLModel, table=True): | |
| """Booked appointment.""" | |
| __tablename__ = "booking_appointments" | |
| id: UUID = Field(default_factory=uuid4, primary_key=True) | |
| tenant_id: UUID = Field(foreign_key="tenants.id", index=True) | |
| service_id: UUID = Field(foreign_key="booking_services.id") | |
| resource_id: Optional[UUID] = Field(default=None, foreign_key="booking_resources.id", index=True) # NEW: which resource is booked | |
| lead_id: Optional[UUID] = Field(default=None, foreign_key="leads.id") | |
| start_time: datetime = Field(sa_column=Column(DateTime)) | |
| end_time: datetime = Field(sa_column=Column(DateTime)) | |
| status: AppointmentStatus = Field(default=AppointmentStatus.SCHEDULED) | |
| notes: Optional[str] = Field(default=None, sa_column=Column(TEXT)) | |
| # Relationships | |
| service: Optional[Service] = Relationship(back_populates="appointments") | |
| resource: Optional[Resource] = Relationship(back_populates="appointments") | |
| lead: Optional["Lead"] = Relationship(back_populates="appointments") | |
| tenant: Optional["Tenant"] = Relationship(back_populates="appointments") | |