diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/config/BookingDiModule.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/config/BookingDiModule.kt index ad50d06982701a7cf710b9166a65f6cc92fc1a83..263fcd49a3be4dde073b60cd8ba708dbfa6df540 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/config/BookingDiModule.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/config/BookingDiModule.kt @@ -10,9 +10,9 @@ import office.effective.features.booking.service.BookingService import org.koin.dsl.module val bookingDiModule = module(createdAtStart = true) { - single { BookingRepositoryConverter(get(), get(), get()) } + single { BookingRepositoryConverter(get(), get(), get(), get()) } single { BookingCalendarRepository(get(), get(), get()) } single { BookingService(get(), get(), get()) } - single { BookingFacadeConverter(get(), get(), get()) } + single { BookingFacadeConverter(get(), get()) } single { BookingFacade(get(), get(), get(), get()) } } diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingFacadeConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingFacadeConverter.kt index c7abbe7720c1c66bf91dfa7e26779c03fa8b3e89..b01426e284221be92c9a5db60b26f0d876aac72c 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingFacadeConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingFacadeConverter.kt @@ -11,8 +11,7 @@ import office.effective.model.RecurrenceModel import java.time.Instant class BookingFacadeConverter(private val userConverter: UserDTOModelConverter, - private val workspaceConverter: WorkspaceFacadeConverter, - private val uuidValidator: UuidValidator) { + private val workspaceConverter: WorkspaceFacadeConverter) { /** * Converts WorkspaceEntity to BookingDTO * @@ -48,7 +47,7 @@ class BookingFacadeConverter(private val userConverter: UserDTOModelConverter, owner = userConverter.dTOToModel(bookingDTO.owner), participants = bookingDTO.participants.map { userConverter.dTOToModel(it) }, workspace = workspaceConverter.dtoToModel(bookingDTO.workspace), - id = bookingDTO.id?.let { uuidValidator.uuidFromString(it) }, + id = bookingDTO.id, beginBooking = Instant.ofEpochMilli(bookingDTO.beginBooking), endBooking = Instant.ofEpochMilli(bookingDTO.endBooking), recurrence = recurrenceModel diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingRepositoryConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingRepositoryConverter.kt index aadeb0f1b4dfaee96ea0ddcd6d4ea8927e784b0b..4ed09bcc84f896574180ca2dd548aaeea634a150 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingRepositoryConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/converters/BookingRepositoryConverter.kt @@ -2,6 +2,7 @@ package office.effective.features.booking.converters import office.effective.common.exception.InstanceNotFoundException import office.effective.common.exception.MissingIdException +import office.effective.common.utils.UuidValidator import office.effective.features.booking.repository.WorkspaceBookingEntity import office.effective.features.user.converters.UserModelEntityConverter import office.effective.features.user.repository.UserEntity @@ -19,7 +20,8 @@ import java.util.* class BookingRepositoryConverter(private val database: Database, private val workspaceConverter: WorkspaceRepositoryConverter, - private val userConverter: UserModelEntityConverter) { + private val userConverter: UserModelEntityConverter, + private val uuidValidator: UuidValidator) { /** * Converts booking entity to model which contains user and workspace models. @@ -34,7 +36,7 @@ class BookingRepositoryConverter(private val database: Database, ownerModel, participantModels, workspaceModel, - bookingEntity.id, + bookingEntity.id.toString(), bookingEntity.beginBooking, bookingEntity.endBooking, recurrence = null @@ -52,7 +54,8 @@ class BookingRepositoryConverter(private val database: Database, return WorkspaceBookingEntity { owner = findOwnerEntity(bookingModel.owner) workspace = findWorkspaceEntity(bookingModel.workspace) - id = bookingModel.id ?: throw MissingIdException("Booking model doesn't have an id") + id = bookingModel.id?.let { uuidValidator.uuidFromString(it) } + ?: throw MissingIdException("Booking model doesn't have an id") beginBooking = bookingModel.beginBooking endBooking = bookingModel.endBooking } diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/facade/BookingFacade.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/facade/BookingFacade.kt index f84ac19f87b3cf10c9b3bcd1a7acb49094451c03..dee3e617b4f427d7057ea681a057ba257ebf43e5 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/facade/BookingFacade.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/facade/BookingFacade.kt @@ -22,9 +22,7 @@ class BookingFacade(private val bookingService: BookingService, */ fun deleteById(id: String) { transactionManager.useTransaction({ - bookingService.deleteById( - uuidValidator.uuidFromString(id) - ) + bookingService.deleteById(id) }) } @@ -36,10 +34,9 @@ class BookingFacade(private val bookingService: BookingService, * @author Daniil Zavyalov */ fun findById(id: String): BookingDTO { - val uuid = uuidValidator.uuidFromString(id) val dto: BookingDTO = transactionManager.useTransaction({ - val model = bookingService.findById(uuid) - ?: throw InstanceNotFoundException(Workspace::class, "Booking with id $id not found", uuid) + val model = bookingService.findById(id) + ?: throw InstanceNotFoundException(Workspace::class, "Booking with id $id not found") bookingConverter.modelToDto(model) }) return dto 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 b6cff7ce34bfcf99006aacde83a22d6c9d7fa944..38a0e935d378e323662ab61b78236699020301ef 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 @@ -22,21 +22,21 @@ class BookingCalendarRepository( return calendarRepository.findByWorkspace(workspaceId) } - override fun existsById(id: UUID): Boolean { + override fun existsById(id: String): Boolean { var event: Any? = null calendarRepository.findAllCalendarsId().forEach { - event = calendarEvents.get(it, id.toString()).execute() + event = calendarEvents.get(it, id).execute() } return event != null } - override fun deleteById(id: UUID) { + override fun deleteById(id: String) { calendarRepository.findAllCalendarsId().forEach { - calendarEvents.delete(it, id.toString()).execute() + calendarEvents.delete(it, id).execute() } } - override fun findById(bookingId: UUID): Booking? { + override fun findById(bookingId: String): Booking? { var event: Event? = null; calendarRepository.findAllCalendarsId().forEach { event = findByCalendarIdAndBookingId(it, bookingId) @@ -44,7 +44,7 @@ class BookingCalendarRepository( return event?.toBookingModel() } - private fun findByCalendarIdAndBookingId(calendarId: String, bookingId: UUID): Event? { + private fun findByCalendarIdAndBookingId(calendarId: String, bookingId: String): Event? { return calendarEvents.list(calendarId).execute().items.find { it.id.equals(bookingId.toString()) } } @@ -94,7 +94,7 @@ class BookingCalendarRepository( calendarRepository.findByWorkspace(booking.workspace.id ?: throw MissingIdException("workspace model")) val savedEvent = calendar.Events().insert("effective.office@effective.band", event).execute() - return findById(UUID.fromString(savedEvent.id.uppercase())) ?: throw Exception("Calendar save goes wrong") + return findById(event.id) ?: throw Exception("Calendar save goes wrong") } override fun update(booking: Booking): Booking { diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingRepository.kt index 261a34062e3ab31506e9bdadca68f583135786d3..2e195b79785dabbad5fce98aaf60c8f947d24377 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/BookingRepository.kt @@ -3,6 +3,7 @@ package office.effective.features.booking.repository import office.effective.common.exception.InstanceNotFoundException import office.effective.common.exception.MissingIdException import office.effective.common.exception.WorkspaceUnavailableException +import office.effective.common.utils.UuidValidator import office.effective.features.booking.converters.BookingRepositoryConverter import office.effective.features.user.repository.* import office.effective.model.Booking @@ -13,15 +14,17 @@ import org.ktorm.entity.* import java.util.* import kotlin.collections.List -class BookingRepository(private val database: Database, private val converter: BookingRepositoryConverter) : IBookingRepository{ +class BookingRepository(private val database: Database, + private val converter: BookingRepositoryConverter, + private val uuidValidator: UuidValidator) : IBookingRepository{ /** * Returns whether a booking with the given id exists * * @author Daniil Zavyalov */ - override fun existsById(id: UUID): Boolean { - return database.workspaceBooking.count { it.id eq id } > 0 + override fun existsById(id: String): Boolean { + return database.workspaceBooking.count { it.id eq uuidValidator.uuidFromString(id) } > 0 } /** @@ -31,9 +34,10 @@ class BookingRepository(private val database: Database, private val converter: B * * @author Daniil Zavyalov */ - override fun deleteById(id: UUID) { - database.bookingParticipants.removeIf { it.bookingId eq id } - database.workspaceBooking.removeIf { it.id eq id } + override fun deleteById(id: String) { + val uuid = uuidValidator.uuidFromString(id) + database.bookingParticipants.removeIf { it.bookingId eq uuid } + database.workspaceBooking.removeIf { it.id eq uuid } } /** @@ -42,9 +46,10 @@ class BookingRepository(private val database: Database, private val converter: B * * @author Daniil Zavyalov */ - override fun findById(bookingId: UUID): Booking? { - val entity = database.workspaceBooking.find { it.id eq bookingId } ?: return null - val participants = findParticipants(bookingId) + override fun findById(bookingId: String): Booking? { + val uuid = uuidValidator.uuidFromString(bookingId) + val entity = database.workspaceBooking.find { it.id eq uuid } ?: return null + val participants = findParticipants(uuid) return entity.let { converter.entityToModel(it, participants) } } @@ -138,7 +143,7 @@ class BookingRepository(private val database: Database, private val converter: B */ override fun save(booking: Booking): Booking { val id = UUID.randomUUID() - booking.id = id + booking.id = id.toString() val entity = converter.modelToEntity(booking) if (!workspaceAvailableForBooking(entity)) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/IBookingRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/IBookingRepository.kt index cac35677c6f719ca399469efc9d3fab5b44c20ea..786fa6fe56a13bad3411fa1e3e00483e7621c7ab 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/IBookingRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/repository/IBookingRepository.kt @@ -18,7 +18,7 @@ interface IBookingRepository { * * @author Daniil Zavyalov */ - fun existsById(id: UUID): Boolean ; + fun existsById(id: String): Boolean ; /** * Deletes the booking with the given id @@ -27,7 +27,7 @@ interface IBookingRepository { * * @author Daniil Zavyalov */ - fun deleteById(id: UUID) ; + fun deleteById(id: String) ; /** * Retrieves a booking model by its id. @@ -35,7 +35,7 @@ interface IBookingRepository { * * @author Daniil Zavyalov */ - fun findById(bookingId: UUID): Booking? ; + fun findById(bookingId: String): Booking? ; /** * Returns all bookings with the given owner id diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/service/BookingService.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/service/BookingService.kt index 960b219153231ac61a3bba108ac252ccdca0addf..1d1d2e1121a19d71568cb4627cf4d95c73236fa4 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/service/BookingService.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/service/BookingService.kt @@ -20,7 +20,7 @@ class BookingService( * * @author Daniil Zavyalov */ - fun existsById(id: UUID): Boolean { + fun existsById(id: String): Boolean { return bookingRepository.existsById(id) } @@ -29,7 +29,7 @@ class BookingService( * * @author Daniil Zavyalov */ - fun deleteById(id: UUID) { + fun deleteById(id: String) { bookingRepository.deleteById(id) } @@ -38,7 +38,7 @@ class BookingService( * * @author Daniil Zavyalov */ - fun findById(id: UUID): Booking? { + fun findById(id: String): Booking? { val booking = bookingRepository.findById(id) ?: return null val userIds = mutableSetOf() for (participant in booking.participants) { diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Booking.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Booking.kt index 8db6b03d4ab80c73d7d4ec4f1f143d12d43df600..108cbc48945efa93a48c4b057d716e16b8e9db8b 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Booking.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Booking.kt @@ -8,7 +8,7 @@ data class Booking ( var owner: UserModel, var participants: List, var workspace: Workspace, - var id: UUID?, + var id: String?, var beginBooking: Instant, var endBooking: Instant, var recurrence: RecurrenceModel?