Choosing data structure for bookings

Hello there!
We want to develop a smart contract to eliminate the need for a centralized solution like Booking or Airbnb. We are quite confused about choosing the proper data structure for that purpose.
Here are some bullet points we've made so far:

  • One may book a hotel only for the future dates
  • Check-out date shall be greater than check-in date
  • One may book a hotel from the 16th to the 31st of July, e.g., and if now is the 10th of July, then we should allow to book a hotel for dates before the 16th but after the 10th - the main problem lies here.

The first idea is to use mapping (bookingId => Booking) and store the nextBookingId in the Booking structure, which will link to the next chronological booking. In addition, store some mostRecentBookingBeforeToday and update it dynamically when the booking is created...

What do you think?

1 Like

I dont get where the problem is? block.timestamp gives you the current unix timestamp from which you can convert it to the current date. Also in the booking function you should put in check-in and check-out timestamp and just use that? You only need to find an efficient way to check if the dates chosen have already been booked but with some thought you can do that too.
Get a booking struct with check-in, check-out and whatever you need. Do a mapping from a bookingID to the struct and then you only need a array or some other kind of mechanism to check wheter chosen date is bookable. You may also use a mapping where you check all booked dates