From 14550d971e93e39583450bd6dc9c9acc89917595 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 3 Sep 2023 22:58:27 +0600 Subject: [PATCH 1/2] [~] fix --- .../booking/repository/BookingCalendarRepository.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt index 2c4f6e5a..be120bcb 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt @@ -1,11 +1,11 @@ package office.effective.features.booking.repository +import com.google.api.client.googleapis.json.GoogleJsonResponseException import com.google.api.client.util.DateTime import com.google.api.services.calendar.Calendar import com.google.api.services.calendar.model.Event import office.effective.common.exception.InstanceNotFoundException import office.effective.common.exception.MissingIdException -import office.effective.common.exception.WorkspaceUnavailableException import office.effective.config import office.effective.features.calendar.repository.CalendarIdsRepository import office.effective.features.booking.converters.GoogleCalendarConverter @@ -13,8 +13,6 @@ import office.effective.features.user.repository.UserRepository import office.effective.model.Booking import office.effective.features.user.repository.UserEntity import office.effective.features.workspace.repository.WorkspaceRepository -import office.effective.model.UserModel -import office.effective.model.Workspace import java.util.* /** @@ -59,7 +57,7 @@ class BookingCalendarRepository( */ override fun existsById(id: String): Boolean { val event: Any? - event = calendarEvents.get(defaultCalendar, id).execute() + event = findByCalendarIdAndBookingId(defaultCalendar, id) return event != null } @@ -97,7 +95,12 @@ class BookingCalendarRepository( * @author Danil Kiselev */ private fun findByCalendarIdAndBookingId(calendarId: String, bookingId: String): Event? { - return calendar.events().get(calendarId, bookingId).execute()//calendarEvents.list(calendarId).execute().items.find { it.id.equals(bookingId) } + return try { + calendar.events().get(calendarId, bookingId).execute() + } catch (e: GoogleJsonResponseException) { + if(e.statusCode == 404) return null + else throw e + } } /** -- GitLab From d5735b5b0b5ccb899ce0b06f959bc5cc2014dbef Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Mon, 4 Sep 2023 17:00:33 +0600 Subject: [PATCH 2/2] [~] fix update booking --- .../features/booking/repository/BookingCalendarRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt index be120bcb..d6cebace 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingCalendarRepository.kt @@ -260,7 +260,7 @@ class BookingCalendarRepository( */ override fun update(booking: Booking): Booking { val bookingId = booking.id ?: throw MissingIdException("Update model must have id") - if (existsById(bookingId)) { + if (!existsById(bookingId)) { throw InstanceNotFoundException(WorkspaceBookingEntity::class, "Booking with id $bookingId not wound") } deleteById(bookingId) -- GitLab