Skip to content

Commit 3216cca

Browse files
Update AttendanceStatus and bookings fields without fetching an order
1 parent ba2f3a6 commit 3216cca

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/network/rest/wpcom/wc/bookings/BookingsStore.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,26 @@ class BookingsStore @Inject internal constructor(
155155
response.isError -> WooResult(response.error)
156156
response.result != null -> {
157157
val bookingDto = response.result
158-
val orderResult = bookingDto.orderId.takeIf { it != 0L }?.let {
159-
orderStore.fetchSingleOrderSync(site, bookingDto.orderId)
160-
}
161-
if (orderResult?.isError == true) {
162-
return@withDefaultContext WooResult(orderResult.error)
158+
159+
val storedBooking = bookingsDao.getBooking(
160+
localSiteId = site.localId(),
161+
bookingId = bookingId
162+
)
163+
if (storedBooking == null) {
164+
return@withDefaultContext WooResult(WooError(GENERIC_ERROR, UNKNOWN))
163165
}
164-
val entity = with(bookingDtoMapper) {
165-
bookingDto.toEntity(
166+
167+
with(bookingDtoMapper) {
168+
val updatedBooking = bookingDto.toEntity(
166169
localSiteId = site.localId(),
167-
orderEntity = orderResult?.model,
170+
orderEntity = null,
171+
).copy(
172+
// Preserve fields not returned by the API
173+
order = storedBooking.order,
168174
)
175+
bookingsDao.insertOrReplace(updatedBooking)
176+
return@withDefaultContext WooResult(updatedBooking)
169177
}
170-
bookingsDao.insertOrReplace(listOf(entity))
171-
WooResult(entity)
172178
}
173179

174180
else -> WooResult(WooError(GENERIC_ERROR, UNKNOWN))

libs/fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/persistence/dao/BookingsDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ interface BookingsDao {
9999
)
100100
}
101101

102+
@Query("SELECT * FROM Bookings WHERE localSiteId = :localSiteId AND id = :bookingId LIMIT 1")
103+
suspend fun getBooking(localSiteId: LocalId, bookingId: Long): BookingEntity?
104+
102105
@Query("SELECT * FROM BookingResources WHERE localSiteId = :localSiteId AND id = :resourceId")
103106
fun observeResource(localSiteId: LocalId, resourceId: Long): Flow<BookingResourceEntity?>
104107

0 commit comments

Comments
 (0)