Repository navigation
feat(booking): request separate days in one booking - #360
Conversation
A booking stores a list of days instead of a first and last day, so a renter can request 1, 4 and 8-10 Nov together. Every requested day counts towards maxRentalDays. The rules check that every day is offered, once; only the first is checked against today, since rules cannot loop (#346).
adrimikh
left a comment
There was a problem hiding this comment.
Nice change. Moving to days: Set<LocalDate> makes separate-day requests simple, and the Firestore rules now check every requested day.
- Rules:
listing.availableDates.hasAll(data.days)closes the middle-of-range gap from #313. - Rules: the non-empty, no-duplicates and
maxRentalDayschecks are tight. - Rules: keeping the server-time check on
days[0]and documenting the limit (#346) is honest and well explained. - ViewModel: deleting
singlePeriodandperiodsimplifies it.dayCount = selection.size,isTooLongandtotalare now simple and correct. - Reload:
selection intersect selectableDayshandles days the lender took back. - Repository: sorting earliest-first on write is clearly tied to the rules.
- Repository: reads are strict about the
daysshape. - Tests: the rules, repository, ViewModel and screen tests cover the edge cases well.
Nits, optional:
FirebaseBookingRepository.kt,toBooking()days():LocalDate.ofEpochDaythrowsDateTimeExceptionfor out-of-range values, while the other malformed cases throwIllegalStateException. Catch and rethrow it asIllegalStateException("Booking $id has an invalid day: …")for consistency.FirebaseBookingRepository.kt,toBooking(): duplicate days in a stored list collapse silently into theSet. This is harmless, because the rules already reject duplicates.firestore.rules,validBooking: the comment says "at most as many as the listing offers (366)". That holds only becausehasAllplus no duplicates bounds the size. Say so explicitly, or drop the "(366)".FirebaseBookingRepository.kt: the repository'screateBookingcheck is onlyisNotEmpty. That's fine, since the rules are the enforcement.
I definetely approve. On your open question about getBookingsForListing: rules now reject malformed days, so only legacy startDate/endDate documents could break the read. If any exist outside test data, skip and log the bad booking rather than failing the whole list. Otherwise keeping the current behaviour is fine.
…ption Also say in the rules why a booking has at most 366 days.
|
I skipped nitpick 2 and 4 since would add unnecessary checks, I implemented the other nitpicks. Since we are still in the implementation phase of the application we don't have any real production data so it is safe to delete the current listing data. |
|



Summary
Part of #26 and #346. A renter can now request separate days in one booking, such as 1, 4 and 8–10 Nov. The Firestore rules check that every requested day is offered, not only the first and last.
What
Bookingstoresdays: Set<LocalDate>instead ofstartDate/endDate. Firestore stores it as adayslist of epoch days, earliest first.BookingRequestViewModelkeeps any offered days the renter picks; the rule that cut the selection down to one period (singlePeriod) is removed.dayCountis the number of days chosen, and the total is the price per day times that count.maxRentalDayscounts every requested day: 1, 4 and 8–10 Nov are 5 days.firestore.rules(validBooking):daysis a non-empty list with no duplicates, every day is in the listing'savailableDates, the count is withinmaxRentalDays, and the first day is not before today (server time). The oldstartDate/endDateshape is refused.Why
Renters should be able to ask for the days they actually need in one request, not one request per stretch of days. This is the first step towards requests the lender sees and confirms on the listing and in the chat.
Storing the list also lets the rules check every day against the listing's offered days (
hasAll), which closes the gap from #313 where a day in the middle of a range was not checked.Validation
./gradlew ktfmtCheck check: successful, 1364 unit tests, 0 failures, lint included. The instrumented tests compile.rules-tests,npm testin the emulator): 195/195 pass. New cases cover:days../gradlew connectedCheck(no emulator).Follow-ups
startDate/endDate(only test data, since no screen could create one before feat(booking): open the booking request from "Choose dates" #354) are no longer read.getBookingsForListingread fail. Should we make it skip the malformed booking when the lender's request list is built or keep it as dropping the booking since it would require both a modified renter and lender so no honest user would be affectedAI use
Claude Code (Claude Opus 5.5) wrote the model, repository, ViewModel, rules and test changes. I designed the implementation, reviewed the diff and can explain every line.