diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/swagger/BookingSwagger.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/swagger/BookingSwagger.kt index 5f13f4154f86c75c1f53314d3aaca6a5d287e02a..92ac2edda9c47d2fb62905d34adb87fc019d836f 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/swagger/BookingSwagger.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/swagger/BookingSwagger.kt @@ -26,52 +26,7 @@ fun SwaggerDocument.returnBookingById(): OpenApiRoute.() -> Unit = { description = "Returns booking found by id" body { example( - "Bookings", BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - UserDTO( - id = "207b9634-2bc4-11ee-be56-0242ac120002", - fullName = "Grzegorz Brzęczyszczykiewicz", - active = true, - role = "guest", - avatarUrl = "https://img.freepik.com/free-photo/capybara-in-the-nature-habitat-of-northern-pantanal_475641-1029.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "somemail@gmail.com")) - ) - ), - workspace = WorkspaceDTO( - id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( - UtilityDTO( - id = "50d89406-2bc6-11ee-be56-0242ac120002", - name = "Sockets", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 8 - ), UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", - beginBooking = 1691299526000, - endBooking = 1691310326000, - ) + "Bookings", bookingExample1 ) {} } } @@ -107,84 +62,7 @@ fun SwaggerDocument.returnBookings(): OpenApiRoute.() -> Unit = { body> { example( "Workspace", listOf( - BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - UserDTO( - id = "207b9634-2bc4-11ee-be56-0242ac120002", - fullName = "Grzegorz Brzęczyszczykiewicz", - active = true, - role = "guest", - avatarUrl = "https://img.freepik.com/free-photo/capybara-in-the-nature-habitat-of-northern-pantanal_475641-1029.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "somemail@gmail.com")) - ) - ), - workspace = WorkspaceDTO( - id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( - UtilityDTO( - id = "50d89406-2bc6-11ee-be56-0242ac120002", - name = "Sockets", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 8 - ), UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", - beginBooking = 1691299526000, - endBooking = 1691310326000, - ), BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ) - ), - workspace = WorkspaceDTO( - id = "00f9b35d-08c3-4f4b-8d09-1fbb3a3673c5", name = "Moon", utilities = listOf( - UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "d703c8a6-f58d-49d8-a074-19e75a9910e7", - beginBooking = 1691409670000, - endBooking = 1691420470000, - ) + bookingExample1, bookingExample2 ) ) {} } @@ -250,44 +128,7 @@ fun SwaggerDocument.postBooking(): OpenApiRoute.() -> Unit = { description = "Returns saved booking" body { example( - "Bookings", BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ) - ), - workspace = WorkspaceDTO( - id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( - UtilityDTO( - id = "50d89406-2bc6-11ee-be56-0242ac120002", - name = "Sockets", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 8 - ), UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", - beginBooking = 1691299526000, - endBooking = 1691310326000, - ) + "Bookings", bookingExample2 ) {} } } @@ -306,52 +147,7 @@ fun SwaggerDocument.putBooking(): OpenApiRoute.() -> Unit = { request { body { example( - "Bookings", BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - UserDTO( - id = "207b9634-2bc4-11ee-be56-0242ac120002", - fullName = "Grzegorz Brzęczyszczykiewicz", - active = true, - role = "guest", - avatarUrl = "https://img.freepik.com/free-photo/capybara-in-the-nature-habitat-of-northern-pantanal_475641-1029.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "somemail@gmail.com")) - ) - ), - workspace = WorkspaceDTO( - id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( - UtilityDTO( - id = "50d89406-2bc6-11ee-be56-0242ac120002", - name = "Sockets", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 8 - ), UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", - beginBooking = 1691399526000, - endBooking = 1691410326000, - ) + "Bookings", bookingExample1 ) } } @@ -360,52 +156,7 @@ fun SwaggerDocument.putBooking(): OpenApiRoute.() -> Unit = { description = "Returns saved booking" body { example( - "Bookings", BookingDTO( - owner = UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - participants = listOf( - UserDTO( - id = "2c77feee-2bc1-11ee-be56-0242ac120002", - fullName = "Ivan Ivanov", - active = true, - role = "employee", - avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) - ), - UserDTO( - id = "207b9634-2bc4-11ee-be56-0242ac120002", - fullName = "Grzegorz Brzęczyszczykiewicz", - active = true, - role = "guest", - avatarUrl = "https://img.freepik.com/free-photo/capybara-in-the-nature-habitat-of-northern-pantanal_475641-1029.jpg", - integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "somemail@gmail.com")) - ) - ), - workspace = WorkspaceDTO( - id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( - UtilityDTO( - id = "50d89406-2bc6-11ee-be56-0242ac120002", - name = "Sockets", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 8 - ), UtilityDTO( - id = "a62a86c6-2bc6-11ee-be56-0242ac120002", - name = "Projectors", - iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", - count = 1 - ) - ) - ), - id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", - beginBooking = 1691399526000, - endBooking = 1691410326000, - ) + "Bookings", bookingExample1 ) {} } } @@ -438,3 +189,89 @@ fun SwaggerDocument.deleteBookingById(): OpenApiRoute.() -> Unit = { } } } + +private val bookingExample1 = BookingDTO( + owner = UserDTO( + id = "2c77feee-2bc1-11ee-be56-0242ac120002", + fullName = "Ivan Ivanov", + active = true, + role = "employee", + avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) + ), + participants = listOf( + UserDTO( + id = "2c77feee-2bc1-11ee-be56-0242ac120002", + fullName = "Ivan Ivanov", + active = true, + role = "employee", + avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) + ), + UserDTO( + id = "207b9634-2bc4-11ee-be56-0242ac120002", + fullName = "Grzegorz Brzęczyszczykiewicz", + active = true, + role = "guest", + avatarUrl = "https://img.freepik.com/free-photo/capybara-in-the-nature-habitat-of-northern-pantanal_475641-1029.jpg", + integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "somemail@gmail.com")) + ) + ), + workspace = WorkspaceDTO( + id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( + UtilityDTO( + id = "50d89406-2bc6-11ee-be56-0242ac120002", + name = "Sockets", + iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + count = 8 + ), UtilityDTO( + id = "a62a86c6-2bc6-11ee-be56-0242ac120002", + name = "Projectors", + iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + count = 1 + ) + ) + ), + id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", + beginBooking = 1691299526000, + endBooking = 1691310326000, +) + +private val bookingExample2 = BookingDTO( + owner = UserDTO( + id = "2c77feee-2bc1-11ee-be56-0242ac120002", + fullName = "Ivan Ivanov", + active = true, + role = "employee", + avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) + ), + participants = listOf( + UserDTO( + id = "2c77feee-2bc1-11ee-be56-0242ac120002", + fullName = "Ivan Ivanov", + active = true, + role = "employee", + avatarUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + integrations = listOf(IntegrationDTO("c717cf6e-28b3-4148-a469-032991e5d9e9", "email", "123@effective.band")) + ) + ), + workspace = WorkspaceDTO( + id = "2561471e-2bc6-11ee-be56-0242ac120002", name = "Sun", utilities = listOf( + UtilityDTO( + id = "50d89406-2bc6-11ee-be56-0242ac120002", + name = "Sockets", + iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + count = 8 + ), UtilityDTO( + id = "a62a86c6-2bc6-11ee-be56-0242ac120002", + name = "Projectors", + iconUrl = "https://img.freepik.com/free-photo/beautiful-shot-of-a-white-british-shorthair-kitten_181624-57681.jpg", + count = 1 + ) + ) + ), + id = "c48c2a3d-bbfd-4801-b121-973ae3cf4cd9", + beginBooking = 1691299526000, + endBooking = 1691310326000, +) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceFacadeConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceFacadeConverter.kt index 3da6bdef4cda1635fd3429294a0a03d3d89e218d..ae8ea18c6a66a84ba39a1a2977491567da18bf86 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceFacadeConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceFacadeConverter.kt @@ -3,8 +3,10 @@ package office.effective.features.workspace.converters import office.effective.common.utils.UuidValidator import office.effective.features.workspace.dto.UtilityDTO import office.effective.features.workspace.dto.WorkspaceDTO +import office.effective.features.workspace.dto.WorkspaceZoneDTO import office.effective.model.Utility import office.effective.model.Workspace +import office.effective.model.WorkspaceZone class WorkspaceFacadeConverter(private val uuidValidator: UuidValidator) { @@ -15,7 +17,12 @@ class WorkspaceFacadeConverter(private val uuidValidator: UuidValidator) { */ fun modelToDto(model: Workspace): WorkspaceDTO { val utilities = model.utilities.map { utilityModelToDto(it) } - return WorkspaceDTO(model.id.toString(), model.name, utilities) + return WorkspaceDTO( + model.id.toString(), + model.name, + utilities, + model.zone?.let { zoneModelToDto(it) } + ) } /** @@ -27,6 +34,15 @@ class WorkspaceFacadeConverter(private val uuidValidator: UuidValidator) { return UtilityDTO(model.id.toString(), model.name, model.iconUrl, model.count) } + /** + * Converts WorkspaceZone to WorkspaceZoneDTO + * + * @author Daniil Zavyalov + */ + fun zoneModelToDto(model: WorkspaceZone): WorkspaceZoneDTO { + return WorkspaceZoneDTO(model.id.toString(), model.name) + } + /** * Converts WorkspaceDTO with utilities to Workspace * @@ -38,7 +54,8 @@ class WorkspaceFacadeConverter(private val uuidValidator: UuidValidator) { id = uuidValidator.uuidFromString(dto.id), name = dto.name, tag = "", //This is probably wrong - utilities = utilities + utilities = utilities, + zone = dto.zone?.let { zoneDtoToModel(it) } ) } @@ -50,4 +67,13 @@ class WorkspaceFacadeConverter(private val uuidValidator: UuidValidator) { private fun utilityDtoToModel(dto: UtilityDTO): Utility { return Utility(uuidValidator.uuidFromString(dto.id), dto.name, dto.iconUrl, dto.count) } + + /** + * Converts WorkspaceZoneDTO to WorkspaceZone + * + * @author Daniil Zavyalov + */ + private fun zoneDtoToModel(dto: WorkspaceZoneDTO): WorkspaceZone { + return WorkspaceZone(uuidValidator.uuidFromString(dto.id), dto.name) + } } \ No newline at end of file diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceRepositoryConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceRepositoryConverter.kt index d93b76eaadee1d54b05bb9de1132149dcae46470..193e713d910480e6992451e03c23f20e7c9bd5c1 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceRepositoryConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/converters/WorkspaceRepositoryConverter.kt @@ -1,12 +1,10 @@ package office.effective.features.workspace.converters import office.effective.common.exception.InstanceNotFoundException -import office.effective.features.workspace.repository.UtilityEntity -import office.effective.features.workspace.repository.WorkspaceEntity -import office.effective.features.workspace.repository.WorkspaceTagEntity -import office.effective.features.workspace.repository.workspaceTags +import office.effective.features.workspace.repository.* import office.effective.model.Utility import office.effective.model.Workspace +import office.effective.model.WorkspaceZone import org.ktorm.database.Database import org.ktorm.dsl.eq import org.ktorm.entity.find @@ -21,7 +19,31 @@ class WorkspaceRepositoryConverter(private val database: Database) { * @author Daniil Zavyalov */ fun entityToModel(entity: WorkspaceEntity, utilities: List): Workspace { - return Workspace(entity.id, entity.name, entity.tag.name, utilities) + return Workspace( + entity.id, + entity.name, + entity.tag.name, + utilities, + entity.zone?.let { (zoneEntityToModel(it)) } + ) + } + + /** + * Converts UtilityEntity to Utility with given count + * + * @author Daniil Zavyalov + */ + fun utilityEntityToModel(entity: UtilityEntity, count: Int): Utility { + return Utility(entity.id, entity.name, entity.iconUrl, count) + } + + /** + * Converts WorkspaceZoneEntity to WorkspaceZone model + * + * @author Daniil Zavyalov + */ + fun zoneEntityToModel(zoneEntity: WorkspaceZoneEntity): WorkspaceZone { + return WorkspaceZone(zoneEntity.id, zoneEntity.name) } /** @@ -43,15 +65,19 @@ class WorkspaceRepositoryConverter(private val database: Database) { id = UUID.randomUUID() name = model.name tag = tagEntity + zone = model.zone?.let{ zoneModelToEntity(it) } } } /** - * Converts UtilityEntity to Utility with given count + * Converts WorkspaceZoneEntity to WorkspaceZone model * * @author Daniil Zavyalov */ - fun utilityEntityToModel(entity: UtilityEntity, count: Int): Utility { - return Utility(entity.id, entity.name, entity.iconUrl, count) + fun zoneModelToEntity(zoneModel: WorkspaceZone): WorkspaceZoneEntity { + return WorkspaceZoneEntity { + id = zoneModel.id + name = zoneModel.name + } } } \ No newline at end of file diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt index 6dac0da7bb05f3619c26e3484ac85710db62b8a3..6748a1023f25954310d976d989266cf2d1ce716e 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt @@ -3,4 +3,9 @@ package office.effective.features.workspace.dto import kotlinx.serialization.Serializable @Serializable -data class WorkspaceDTO(val id: String, val name: String, val utilities: List) +data class WorkspaceDTO( + val id: String, + val name: String, + val utilities: List, + val zone: WorkspaceZoneDTO? = null +) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt new file mode 100644 index 0000000000000000000000000000000000000000..6a7407622be0c7da8cfbe3309732167cabc86e66 --- /dev/null +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt @@ -0,0 +1,6 @@ +package office.effective.features.workspace.dto + +import kotlinx.serialization.Serializable + +@Serializable +data class WorkspaceZoneDTO(val id: String, val name: String) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/facade/WorkspaceFacade.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/facade/WorkspaceFacade.kt index 79637aebabccbb585f9a6f3de75d017a4c02f188..4b1f03dfbae9e02732cf7b1cfdf5657cd9795c04 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/facade/WorkspaceFacade.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/facade/WorkspaceFacade.kt @@ -1,12 +1,15 @@ package office.effective.features.workspace.facade import office.effective.common.exception.InstanceNotFoundException +import office.effective.common.exception.ValidationException import office.effective.common.utils.DatabaseTransactionManager import office.effective.common.utils.UuidValidator import office.effective.features.workspace.converters.WorkspaceFacadeConverter import office.effective.features.workspace.dto.WorkspaceDTO +import office.effective.features.workspace.dto.WorkspaceZoneDTO import office.effective.features.workspace.service.WorkspaceService import office.effective.model.Workspace +import java.time.Instant class WorkspaceFacade(private val service: WorkspaceService, private val converter: WorkspaceFacadeConverter, @@ -44,4 +47,42 @@ class WorkspaceFacade(private val service: WorkspaceService, }) return result } + + /** + * Returns all workspaces with the given tag which are free during the given period + * + * @throws ValidationException if begin or end timestamp less than 0, greater than max timestamp + * or if end timestamp less than or equal to begin timestamp + * + * @author Daniil Zavyalov + */ + fun findAllFreeByPeriod(tag: String, beginTimestamp: Long, endTimestamp: Long): List { + if (beginTimestamp < 0L || beginTimestamp >= 2147483647000L) + throw ValidationException("Begin timestamp should be non-negative and less than timestamp max value") + else if (endTimestamp < 0L || endTimestamp >= 2147483647000L) + throw ValidationException("End timestamp should be non-negative and less than timestamp max value") + else if (endTimestamp <= beginTimestamp) + throw ValidationException( + "End timestamp (${endTimestamp}) should be greater than begin timestamp (${beginTimestamp})") + + return transactionManager.useTransaction({ + val modelList = service.findAllFreeByPeriod( + tag, + Instant.ofEpochMilli(beginTimestamp), + Instant.ofEpochMilli(endTimestamp) + ) + modelList.map { converter.modelToDto(it) } + }) + } + + /** + * Returns all workspace zones + * + * @author Daniil Zavyalov + */ + fun findAllZones(): List { + return transactionManager.useTransaction({ + service.findAllZones().map { converter.zoneModelToDto(it) } + }) + } } \ No newline at end of file diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceEntity.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceEntity.kt index 6fe2bca1c4a15fa187594676161d89a515675b73..b4ad27b165e9d21f88b65d4c3444019b3a25a445 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceEntity.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceEntity.kt @@ -1,8 +1,10 @@ package office.effective.features.workspace.repository import org.ktorm.database.Database +import org.ktorm.dsl.isNull import org.ktorm.entity.Entity import org.ktorm.entity.sequenceOf +import org.ktorm.schema.Column import org.ktorm.schema.Table import org.ktorm.schema.uuid import org.ktorm.schema.varchar @@ -13,12 +15,14 @@ interface WorkspaceEntity: Entity { var id: UUID var name: String var tag: WorkspaceTagEntity + var zone: WorkspaceZoneEntity? } object Workspaces: Table("workspaces") { val id = uuid("id").primaryKey().bindTo { it.id } val name = varchar("name").bindTo { it.name } val tagId = uuid("tag_id").references(WorkspaceTags) { it.tag } + val zoneId = uuid("zone_id").references(WorkspaceZones) { it.zone } } val Database.workspaces get() = this.sequenceOf(Workspaces) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceRepository.kt index b8294d3daab034fb6690ba8d76cf82dfebf0db4e..1a90ff194ec5981ac7ebafba4571857e727d6507 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceRepository.kt @@ -1,13 +1,16 @@ package office.effective.features.workspace.repository import office.effective.common.exception.InstanceNotFoundException +import office.effective.features.booking.repository.WorkspaceBooking import office.effective.features.workspace.converters.WorkspaceRepositoryConverter import office.effective.model.Utility import office.effective.model.Workspace +import office.effective.model.WorkspaceZone import org.ktorm.database.Database import org.ktorm.dsl.* import org.ktorm.entity.* import org.ktorm.support.postgresql.insertOrUpdate +import java.time.Instant import java.util.UUID class WorkspaceRepository(private val database: Database, private val converter: WorkspaceRepositoryConverter) { @@ -91,6 +94,43 @@ class WorkspaceRepository(private val database: Database, private val converter: } } + /** + * Returns all workspaces with the given tag which are free during the given period + * + * @throws InstanceNotFoundException if tag doesn't exist in the database + * + * @author Daniil Zavyalov + */ + fun findAllFreeByPeriod(tag: String, beginTimestamp: Instant, endTimestamp: Instant): List { + if (database.workspaceTags.count { it.name eq tag } == 0) + throw InstanceNotFoundException(WorkspaceTagEntity::class, "Workspace tag $tag not found") + + return database.from(Workspaces) + .innerJoin(right = WorkspaceTags, on = WorkspaceTags.id eq Workspaces.tagId) + .innerJoin(right = WorkspaceZones, on = WorkspaceZones.id eq Workspaces.zoneId) + .leftJoin( + right = WorkspaceBooking, + on = (Workspaces.id eq WorkspaceBooking.workspaceId) + .and(WorkspaceBooking.beginBooking lt endTimestamp) + .and(WorkspaceBooking.endBooking gt beginTimestamp) + ) + .select() + .where(WorkspaceBooking.workspaceId.isNull() and (WorkspaceTags.name eq tag)) + .map { row -> + val entity = Workspaces.createEntity(row) + converter.entityToModel(entity, findUtilitiesByWorkspaceId(entity.id)) + }.toList() + } + + /** + * Returns all workspace zones + * + * @author Daniil Zavyalov + */ + fun findAllZones(): List { + return database.workspaceZones.map { converter.zoneEntityToModel(it) } + } + /** * Adds utility to workspace by their id. * If the utility has already been added to the workspace, the count value will be overwritten diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceZoneEntity.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceZoneEntity.kt new file mode 100644 index 0000000000000000000000000000000000000000..24090807296661344beb4d14f701cb4852805dad --- /dev/null +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/repository/WorkspaceZoneEntity.kt @@ -0,0 +1,22 @@ +package office.effective.features.workspace.repository + +import org.ktorm.database.Database +import org.ktorm.entity.Entity +import org.ktorm.entity.sequenceOf +import org.ktorm.schema.Table +import org.ktorm.schema.uuid +import org.ktorm.schema.varchar +import java.util.* + +interface WorkspaceZoneEntity: Entity { + companion object : Entity.Factory() + var id: UUID + var name: String +} + +object WorkspaceZones: Table("workspace_zones") { + val id = uuid("id").primaryKey().bindTo { it.id } + val name = varchar("name").bindTo { it.name } +} + +val Database.workspaceZones get() = this.sequenceOf(WorkspaceZones) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/WorkspaceRouting.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/WorkspaceRouting.kt index 9105c19b68ffcbe7c60a343108c1f755d6852a3f..e0e0b3815f6c644b500988aee7639fe7ee3b3e81 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/WorkspaceRouting.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/WorkspaceRouting.kt @@ -8,6 +8,7 @@ import io.ktor.server.response.* import io.ktor.server.routing.* import office.effective.common.swagger.SwaggerDocument import office.effective.features.workspace.facade.WorkspaceFacade +import office.effective.features.workspace.routes.swagger.returnAllZones import office.effective.features.workspace.routes.swagger.returnWorkspaceById import office.effective.features.workspace.routes.swagger.returnWorkspaceByTag import org.koin.core.context.GlobalContext @@ -24,7 +25,25 @@ fun Route.workspaceRouting() { val tag: String = call.request.queryParameters["tag"] ?: return@get call.respond(HttpStatusCode.BadRequest) - call.respond(facade.findAllByTag(tag)) + val freeFrom: String? = call.request.queryParameters["free_from"] + val freeUntil: String? = call.request.queryParameters["free_until"] + + if(freeFrom == null && freeUntil == null) { + call.respond(facade.findAllByTag(tag)) + } else { + val fromLong: Long = if (freeFrom==null) 0 + else freeFrom.toLongOrNull() + ?: return@get call.respond(HttpStatusCode.BadRequest) + + val untilLong: Long = if (freeUntil==null) 2147483647000L + else freeUntil.toLongOrNull() + ?: return@get call.respond(HttpStatusCode.BadRequest) + + call.respond(facade.findAllFreeByPeriod(tag, fromLong, untilLong)) + } + } + get("/zones", SwaggerDocument.returnAllZones()) { + call.respond(facade.findAllZones()) } } } diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/swagger/WorkspaceSwagger.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/swagger/WorkspaceSwagger.kt index 589d4861a3c403a90faad8029c66c4517c875fa4..fa7a1c9b7a82e37bf7d4211ba77dc3dc6e520881 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/swagger/WorkspaceSwagger.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/routes/swagger/WorkspaceSwagger.kt @@ -5,6 +5,7 @@ import io.ktor.http.* import office.effective.common.swagger.SwaggerDocument import office.effective.features.workspace.dto.UtilityDTO import office.effective.features.workspace.dto.WorkspaceDTO +import office.effective.features.workspace.dto.WorkspaceZoneDTO fun SwaggerDocument.returnWorkspaceById(): OpenApiRoute.() -> Unit = { description = "Return workspace by id" @@ -59,6 +60,18 @@ fun SwaggerDocument.returnWorkspaceByTag(): OpenApiRoute.() -> Unit = { required = true allowEmptyValue = false } + queryParameter("free_from") { + description = "Timestamp from which the workspace should be free" + example = 1691591501000L + required = false + allowEmptyValue = false + } + queryParameter("free_until") { + description = "Timestamp before which the workspace should be free." + example = 1691591578000L + required = false + allowEmptyValue = false + } } response { HttpStatusCode.OK to { @@ -95,7 +108,8 @@ fun SwaggerDocument.returnWorkspaceByTag(): OpenApiRoute.() -> Unit = { } } HttpStatusCode.BadRequest to { - description = "Bad request" + description = "Tag shouldn't be null, free_from " + + "and free_until should be numbers from 0 to 2147483647000 (max timestamp)" } HttpStatusCode.NotFound to { description = "Provided tag doesn't exist" @@ -103,6 +117,26 @@ fun SwaggerDocument.returnWorkspaceByTag(): OpenApiRoute.() -> Unit = { } } +fun SwaggerDocument.returnAllZones(): OpenApiRoute.() -> Unit = { + description = "Returns all workspace zones" + tags = listOf("workspaces") + response { + HttpStatusCode.OK to { + description = "Returns all workspaces found by tag" + body> { + example( + "Zones", listOf( + zoneExample1, zoneExample2 + ) + ) {} + } + } + } +} + +private val zoneExample1 = WorkspaceZoneDTO("3ca26fe0-f837-4939-b586-dd4195d2a504","Cassiopeia") +private val zoneExample2 = WorkspaceZoneDTO("6cb3c60d-3c29-4a45-80e6-fac14fb0569b","Sirius") + enum class WorkspaceTag(val tagName: String) { meeting("meeting"), regular("regular") } diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/service/WorkspaceService.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/service/WorkspaceService.kt index edea94f47a37ce8652907c974c8350a7dc192865..4b138e41813e0b67255254d366567158f168430c 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/service/WorkspaceService.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/service/WorkspaceService.kt @@ -2,6 +2,8 @@ package office.effective.features.workspace.service import office.effective.features.workspace.repository.WorkspaceRepository import office.effective.model.Workspace +import office.effective.model.WorkspaceZone +import java.time.Instant import java.util.UUID class WorkspaceService(private val repository: WorkspaceRepository) { @@ -23,4 +25,22 @@ class WorkspaceService(private val repository: WorkspaceRepository) { fun findAllByTag(tag: String): List { return repository.findAllByTag(tag) } + + /** + * Returns all workspaces with the given tag which are free during the given period + * + * @author Daniil Zavyalov + */ + fun findAllFreeByPeriod(tag: String, beginTimestamp: Instant, endTimestamp: Instant): List { + return repository.findAllFreeByPeriod(tag, beginTimestamp, endTimestamp) + } + + /** + * Returns all workspace zones + * + * @author Daniil Zavyalov + */ + fun findAllZones(): List { + return repository.findAllZones() + } } \ No newline at end of file diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Workspace.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Workspace.kt index 785f6f1c24bc9860a30c96b40507a2d76b12ef27..f9dda9e5e4b0e8ada5295304f420ffd2c4a9e850 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Workspace.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/Workspace.kt @@ -2,4 +2,10 @@ package office.effective.model import java.util.* -data class Workspace(var id: UUID?, var name: String, var tag: String, var utilities: List) +data class Workspace( + var id: UUID?, + var name: String, + var tag: String, + var utilities: List, + var zone: WorkspaceZone? = null +) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/model/WorkspaceZone.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/WorkspaceZone.kt new file mode 100644 index 0000000000000000000000000000000000000000..f66223031aa66e9ba1e82d5d6906681adfed5a1b --- /dev/null +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/model/WorkspaceZone.kt @@ -0,0 +1,5 @@ +package office.effective.model + +import java.util.* + +data class WorkspaceZone(var id: UUID, var name: String) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt index 74867b30a58b3b3aef08c6c956686abc3444bd8a..8979ebe9e2d56deca860710be3251e4e80e207db 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt @@ -7,10 +7,10 @@ import office.effective.features.booking.dto.BookingDTO fun Application.configureValidation() { install(RequestValidation) { validate { booking -> - if (booking.beginBooking < 0L) - ValidationResult.Invalid("beginBooking should be non-negative") - else if (booking.endBooking < 0L) - ValidationResult.Invalid("endBooking should be non-negative") + if (booking.beginBooking < 0L || booking.beginBooking >= 2147483647000L) + ValidationResult.Invalid("beginBooking should be non-negative and less than timestamp max value") + else if (booking.endBooking < 0L || booking.endBooking >= 2147483647000L) + ValidationResult.Invalid("endBooking should be non-negative and less than timestamp max value") else if (booking.endBooking <= booking.beginBooking) ValidationResult.Invalid( "endBooking (${booking.endBooking}) should be greater than beginBooking (${booking.beginBooking})"