Sobes.tech
Junior — Middle+

Hotel booking registration with availability check

livecode

Task condition

Implement the function create_order(user_id: int, hotel_slug: str, start_date: date, end_date: date) that saves a new reservation in the database. If there are no available rooms for the selected dates, the function should return an appropriate message.

Table availability (room availability):

hotel_slug date rooms_count
ibis_batumi 2023-12-01 2
ibis_batumi 2023-12-02 1
ibis_batumi 2023-12-03 2

Table orders (existing reservations):

user_id hotel_slug start_date end_date
1 ibis_batumi 2023-12-01 2023-12-03

Scenario of the function:

  • Client 1 (made a reservation slightly earlier):
    • the order is successfully created;
    • the number of available rooms decreases by 1 for each date in the period.
  • Client 2 (tries to book the same dates):
    • receives a message that there are no available rooms.
def create_order(user_id: int, hotel_slug: str, start_date: date, end_date: date):
    pass