Files
space-booking/backend/app/models/booking.py
Claude Agent e21cf03a16 feat: add multi-tenant system with properties, organizations, and public booking
Implement complete multi-property architecture:
- Properties (groups of spaces) with public/private visibility
- Property managers (many-to-many) with role-based permissions
- Organizations with member management
- Anonymous/guest booking support via public API (/api/public/*)
- Property-scoped spaces, bookings, and settings
- Frontend: property selector, organization management, public booking views
- Migration script and updated seed data

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 00:17:21 +00:00

41 lines
1.8 KiB
Python

"""Booking model."""
from datetime import datetime
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from app.db.session import Base
class Booking(Base):
"""Booking model for space reservations."""
__tablename__ = "bookings"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(Integer, ForeignKey("users.id"), nullable=True, index=True)
space_id = Column(Integer, ForeignKey("spaces.id"), nullable=False, index=True)
guest_name = Column(String, nullable=True)
guest_email = Column(String, nullable=True)
guest_organization = Column(String, nullable=True)
is_anonymous = Column(Boolean, default=False, nullable=False)
title = Column(String, nullable=False)
description = Column(String, nullable=True)
start_datetime = Column(DateTime, nullable=False, index=True)
end_datetime = Column(DateTime, nullable=False, index=True)
status = Column(
String, nullable=False, default="pending", index=True
) # pending/approved/rejected/canceled
rejection_reason = Column(String, nullable=True)
cancellation_reason = Column(String, nullable=True)
approved_by = Column(Integer, ForeignKey("users.id"), nullable=True)
google_calendar_event_id = Column(String, nullable=True) # Store Google Calendar event ID
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
# Relationships
user = relationship("User", foreign_keys=[user_id], backref="bookings")
space = relationship("Space", foreign_keys=[space_id], backref="bookings")
approver = relationship("User", foreign_keys=[approved_by], backref="approved_bookings")
notifications = relationship("Notification", back_populates="booking")
attachments = relationship("Attachment", back_populates="booking", cascade="all, delete-orphan")