-
Notifications
You must be signed in to change notification settings - Fork 39
/
response.py
59 lines (45 loc) · 1.56 KB
/
response.py
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
from __future__ import annotations
from datetime import datetime
from pydantic import BaseModel
from reception.domain.entity.reservation import Reservation
from reception.domain.entity.room import Room
from reception.domain.value_object.guest import Guest, mobile_type
from shared_kernel.presentation.response import BaseResponse
from shared_kernel.domain.value_object import ReservationStatus, RoomStatus
class RoomSchema(BaseModel):
number: str
status: RoomStatus
@classmethod
def from_entity(cls, room: Room) -> RoomSchema:
return cls(
number=room.number,
status=room.room_status,
)
class GuestSchema(BaseModel):
mobile: mobile_type
name: str | None = None
@classmethod
def from_entity(cls, guest: Guest) -> GuestSchema:
return cls(
mobile=guest.mobile,
name=guest.name,
)
class ReservationSchema(BaseModel):
room: RoomSchema
reservation_number: str
status: ReservationStatus
date_in: datetime
date_out: datetime
guest: GuestSchema
@classmethod
def build(cls, reservation: Reservation) -> ReservationSchema:
return cls(
room=RoomSchema.from_entity(reservation.room),
reservation_number=reservation.reservation_number.value,
status=reservation.reservation_status.value,
date_in=reservation.date_in,
date_out=reservation.date_out,
guest=GuestSchema.from_entity(reservation.guest),
)
class ReservationResponse(BaseResponse):
result: ReservationSchema