Skip to content

feat(booking): request separate days in one booking - #360

Merged
lucaschristiansson merged 2 commits into
mainfrom
feature/booking-separate-days
Nov 17, 2026
Merged

lucaschristiansson merged 2 commits into
mainfrom
feature/booking-separate-days

Conversation

@lucaschristiansson

@lucaschristiansson lucaschristiansson commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Booking stores days: Set<LocalDate> instead of startDate/endDate. Firestore stores it as a days list of epoch days, earliest first.
  • BookingRequestViewModel keeps any offered days the renter picks; the rule that cut the selection down to one period (singlePeriod) is removed. dayCount is the number of days chosen, and the total is the price per day times that count.
  • maxRentalDays counts every requested day: 1, 4 and 8–10 Nov are 5 days.
  • firestore.rules (validBooking): days is a non-empty list with no duplicates, every day is in the listing's availableDates, the count is within maxRentalDays, and the first day is not before today (server time). The old startDate/endDate shape is refused.
  • The request screen's docs now say "days" instead of "period"; the dates read like "13, 15, 20 Nov".

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 (rules-tests, npm test in the emulator): 195/195 pass. New cases cover:
    • separate days;
    • every day counting towards the maximum;
    • an unoffered day in the middle;
    • an empty list, duplicates, a day that is not a number, a past first day;
    • the old shape and a missing days.
  • Unit tests:
    • ViewModel: separate days, unselecting a middle day, the total and the maximum across separate days, and a reload that removes a middle day.
    • Repository: days written earliest first, and a booking without days or with an invalid day refused on read.
    • Screen: separate days in the dates field and the confirmation, and a full request of separate days through both ViewModels.
  • Not run: ./gradlew connectedCheck (no emulator).

Follow-ups

AI 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.

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
adrimikh previously approved these changes Nov 17, 2026

@adrimikh adrimikh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 maxRentalDays checks are tight.
  • Rules: keeping the server-time check on days[0] and documenting the limit (#346) is honest and well explained.
  • ViewModel: deleting singlePeriod and period simplifies it. dayCount = selection.size, isTooLong and total are now simple and correct.
  • Reload: selection intersect selectableDays handles days the lender took back.
  • Repository: sorting earliest-first on write is clearly tied to the rules.
  • Repository: reads are strict about the days shape.
  • Tests: the rules, repository, ViewModel and screen tests cover the edge cases well.

Nits, optional:

  1. FirebaseBookingRepository.kt, toBooking() days(): LocalDate.ofEpochDay throws DateTimeException for out-of-range values, while the other malformed cases throw IllegalStateException. Catch and rethrow it as IllegalStateException("Booking $id has an invalid day: …") for consistency.
  2. FirebaseBookingRepository.kt, toBooking(): duplicate days in a stored list collapse silently into the Set. This is harmless, because the rules already reject duplicates.
  3. firestore.rules, validBooking: the comment says "at most as many as the listing offers (366)". That holds only because hasAll plus no duplicates bounds the size. Say so explicitly, or drop the "(366)".
  4. FirebaseBookingRepository.kt: the repository's createBooking check is only isNotEmpty. 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.
@lucaschristiansson

Copy link
Copy Markdown
Contributor Author

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.

@sonarqubecloud

Copy link
Copy Markdown

@adrimikh adrimikh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect LGTM!

@lucaschristiansson
lucaschristiansson merged commit dd8cb9b into main Nov 17, 2026
4 of 5 checks passed
@lucaschristiansson
lucaschristiansson deleted the feature/booking-separate-days branch November 17, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants