Repository navigation
feat(booking): add the view model for answering booking requests - #379
Conversation
Accepting confirms the request, takes its days off the listing and cancels the other requests for those days, in one batched write. The rules only confirm a request whose days the same write removes, so two requests sharing a day can never both be accepted. Part of #28.
Loads the bookings of one listing for its owner, waiting and accepted, with the renters' names, and accepts the request the owner chooses. Part of #28.
peng-0110
left a comment
There was a problem hiding this comment.
Nice work, the accept flow and its tests are solid. One thing to fix before the screen PR:
Should fix: show() lists every REQUESTED booking with a day from today on, but isAccept() also requires all its days to still be in the listing's availableDates. Two cases are listed with an Accept the rules will always refuse: (1) an ongoing request after the owner edits the listing, because saving drops past days through upcomingDays; (2) a request left REQUESTED by the accept race noted in #378, which overlaps a CONFIRMED booking. I reproduced both: the ViewModel lists them, and the emulator refuses both accepts. The lender would get a permission error with no way out. Suggest reading the listing's availableDates and only offering Accept when all the request's days are still offered.
|
@peng-0110 |
|
peng-0110
left a comment
There was a problem hiding this comment.
Thanks, verified. canAccept mirrors isAccept(), and both cases are covered by tests. Approving.



Summary
Part of #28. Adds
ReceivedRequestsViewModel, which loads the booking requests on one of the lender's listings and accepts the one they choose. It builds on the backend from #378, now merged. The screen follows in the next PR.What
ReceivedRequestsViewModel(listingId, bookingRepository, listingRepository, profileRepository, today):requests) andaccepted;accept(request): one at a time (acceptingId), only for a request still waiting whose days are all still offered. On success the request moves to accepted and the requests sharing its days leave the list, then the bookings are read again to catch requests sent since the screen loaded. On failure nothing changes andacceptErrorsays why;loadRequests()for Retry; ignored while a load or an accept runs; keeps the list shown on failure.ReceivedRequestsUiState.canAccept(request): true only when every day of the request is still offered on the listing, as the rules require. A request the owner's edit cut short, or one sharing a day with an accepted booking, stays listed without Accept.ReceivedRequestsUiState.conflictsOf(request): the waiting requests that acceptingrequestcancels, for the confirm dialog in the next PR.FakeBookingRepository:getBookingsForListingreturns that listing'slistingBookings,acceptBookingconfirms and cancels in them like the real repository, and tests can hold back (pendingLoad,acceptGate) or fail (loadFailure,acceptFailure) a read or an accept.Why
The screen needs a tested place for the loading, ordering, name lookups and accept states, independent of Compose. It depends only on the repository interfaces (no Firebase), per AGENTS.md.
Validation
./gradlew ktfmtCheck check compileDebugAndroidTestKotlin: passes.connectedChecknot run (no emulator).ReceivedRequestsViewModelTest: 16 tests, all pass. They cover loading, ordering and filtering (other listings, cancelled, past, ongoing), conflicts, a failed load and Retry, a failed name read again, a successful accept and its reload, a second accept while one runs, an unknown request, a failed accept that keeps the list, a failed reload after an accept, a load ignored while another runs, a request with a day no longer offered or taken by an accepted booking (listed, not acceptable), the accepted days leaving the offered ones, and a failed listing read with Retry.Follow-ups
AI use
Claude Code (Claude Opus 5.5) wrote the view model, the fake repository changes and the tests, and reviewed the diff against the team checklist. I reviewed and tested the result.