-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmodels.py
More file actions
62 lines (46 loc) · 2.98 KB
/
models.py
File metadata and controls
62 lines (46 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from datetime import date, datetime
from sqlalchemy import Integer, String, Float, Date, DateTime, ForeignKey, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from database import Base
class Ship(Base):
__tablename__ = "ships"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
name: Mapped[str] = mapped_column(String(100), nullable=False)
capacity: Mapped[int] = mapped_column(Integer, nullable=False)
year_built: Mapped[int] = mapped_column(Integer, nullable=False)
itineraries: Mapped[list["Itinerary"]] = relationship(back_populates="ship")
class Itinerary(Base):
__tablename__ = "itineraries"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
name: Mapped[str] = mapped_column(String(200), nullable=False)
ship_id: Mapped[int] = mapped_column(Integer, ForeignKey("ships.id"), nullable=False)
departure_port: Mapped[str] = mapped_column(String(100), nullable=False)
destination_ports: Mapped[str] = mapped_column(String(500), nullable=False)
departure_date: Mapped[date] = mapped_column(Date, nullable=False)
return_date: Mapped[date] = mapped_column(Date, nullable=False)
base_price: Mapped[float] = mapped_column(Float, nullable=False)
ship: Mapped["Ship"] = relationship(back_populates="itineraries")
bookings: Mapped[list["Booking"]] = relationship(back_populates="itinerary")
class Guest(Base):
__tablename__ = "guests"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
first_name: Mapped[str] = mapped_column(String(50), nullable=False)
last_name: Mapped[str] = mapped_column(String(50), nullable=False)
email: Mapped[str] = mapped_column(String(100), unique=True, nullable=False)
loyalty_tier: Mapped[str] = mapped_column(String(20), nullable=False, default="Bronze")
preferences: Mapped[str | None] = mapped_column(String(500), nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
bookings: Mapped[list["Booking"]] = relationship(back_populates="guest")
class Booking(Base):
__tablename__ = "bookings"
id: Mapped[int] = mapped_column(Integer, primary_key=True, index=True)
guest_id: Mapped[int] = mapped_column(Integer, ForeignKey("guests.id"), nullable=False)
itinerary_id: Mapped[int] = mapped_column(Integer, ForeignKey("itineraries.id"), nullable=False)
cabin_type: Mapped[str] = mapped_column(String(20), nullable=False)
base_price: Mapped[float] = mapped_column(Float, nullable=False)
discount_percent: Mapped[float] = mapped_column(Float, nullable=False, default=0.0)
total_price: Mapped[float] = mapped_column(Float, nullable=False)
status: Mapped[str] = mapped_column(String(20), nullable=False, default="pending")
booked_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
guest: Mapped["Guest"] = relationship(back_populates="bookings")
itinerary: Mapped["Itinerary"] = relationship(back_populates="bookings")