From 86ee57805955f3bb92c8d018c92a8a03be22f616 Mon Sep 17 00:00:00 2001 From: Arseniy Savin Date: Sat, 12 Aug 2023 15:49:41 +0600 Subject: [PATCH 01/11] [+] Added env variables resolution --- effectiveOfficeBackend/docker-compose.yml | 33 +++++++++++++------ .../effective/common/utils/commonDiModule.kt | 11 ++++--- .../office/effective/plugins/Migration.kt | 14 ++++---- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/effectiveOfficeBackend/docker-compose.yml b/effectiveOfficeBackend/docker-compose.yml index 8b159509..78b660e1 100644 --- a/effectiveOfficeBackend/docker-compose.yml +++ b/effectiveOfficeBackend/docker-compose.yml @@ -6,20 +6,33 @@ services: ports: - "8080:8080" depends_on: - - db_postgres - profiles: - - dev + db_postgres: + condition: service_healthy + environment: + DATABASE_PASSWORD: ${POSTGRES_PASSWORD} + DATABASE_HOST: "db_postgres" # The name of the service in the same network + DATABASE_USERNAME: ${POSTGRES_USER} + DATABASE_PORT: "5432" + DATABASE_NAME: ${POSTGRES_DB} db_postgres: container_name: postgresForKtor image: postgres:15.2-alpine volumes: - - ./sql/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql - env_file: .env + - pgdata:/var/lib/postgresql/data environment: - - POSTGRES_DB=${DOCKER_DB_NAME} - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=${DOCKER_DB_PASSWORD} + - POSTGRES_DB + - POSTGRES_USER + - POSTGRES_PASSWORD ports: - - "15432:5432" - restart: 'no' \ No newline at end of file + - "5432:5432" + restart: "always" + healthcheck: + test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ] + interval: 1s + timeout: 5s + retries: 10 + + +volumes: + pgdata: {} diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/common/utils/commonDiModule.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/common/utils/commonDiModule.kt index 49cfd12d..b8668d5c 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/common/utils/commonDiModule.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/common/utils/commonDiModule.kt @@ -5,10 +5,13 @@ import org.koin.dsl.module import org.ktorm.database.Database val commonDiModule = module(createdAtStart = true) { - val url: String = config.propertyOrNull("database.url") - ?.getString() ?: "jdbc:postgresql://localhost:15432/effectiveOfficeBackendDB" - val username: String = config.propertyOrNull("database.username")?.getString() ?: "postgres" - val password: String = System.getenv("DATABASE_PASSWORD") + val host: String? = System.getenv("DATABASE_HOST") + val port: String? = System.getenv("DATABASE_PORT") + val databaseName: String? = System.getenv("DATABASE_NAME") + + val url: String = String.format("jdbc:postgresql://%s:%s/%s", host, port, databaseName) + val username: String? = System.getenv("DATABASE_USERNAME") + val password: String? = System.getenv("DATABASE_PASSWORD") single { Database.connect( diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt index 2fbd12fa..205fb352 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt @@ -9,11 +9,13 @@ import office.effective.config import java.sql.DriverManager fun Application.configureMigration() { - val url: String = config.propertyOrNull("database.url") - ?.getString() ?: "jdbc:postgresql://localhost:15432/effectiveOfficeBackendDB" - val username: String = config.propertyOrNull("database.username")?.getString() ?: "postgres" - val password: String = - System.getenv("DATABASE_PASSWORD") + val host: String? = System.getenv("DATABASE_HOST") + val port: String? = System.getenv("DATABASE_PORT") + val databaseName: String? = System.getenv("DATABASE_NAME") + + val url: String = String.format("jdbc:postgresql://%s:%s/%s", host, port, databaseName) + val username: String? = System.getenv("DATABASE_USERNAME") + val password: String? = System.getenv("DATABASE_PASSWORD") val changelogFile: String = config.propertyOrNull("liquibase.changelogFile") ?.getString() ?: "changelog/changelog-master.yaml" @@ -31,4 +33,4 @@ fun Application.configureMigration() { val liquibase = Liquibase(changelogFile, ClassLoaderResourceAccessor(), database) liquibase.update("") liquibase.database.close() -} \ No newline at end of file +} -- GitLab From 7a4982df8181178951580bad56a5699a442812c5 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sat, 12 Aug 2023 23:03:24 +0600 Subject: [PATCH 02/11] [+] add findAllUtilitiesByWorkspaceId repository method --- .../booking/service/BookingService.kt | 53 ++++++++++++++++--- .../repository/WorkspaceRepository.kt | 19 +++++++ 2 files changed, 65 insertions(+), 7 deletions(-) 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 084ad085..d9685873 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 @@ -9,9 +9,11 @@ import office.effective.features.workspace.repository.WorkspaceRepository import office.effective.model.* import java.util.UUID -class BookingService(private val bookingRepository: BookingRepository, - private val userRepository: UserRepository, - private val workspaceRepository: WorkspaceRepository) { +class BookingService( + private val bookingRepository: BookingRepository, + private val userRepository: UserRepository, + private val workspaceRepository: WorkspaceRepository +) { /** * Returns whether a booking with the given id exists @@ -59,21 +61,32 @@ class BookingService(private val bookingRepository: BookingRepository, val bookingList = when { userId != null && workspaceId != null -> { if (!workspaceRepository.workspaceExistsById(workspaceId)) - throw InstanceNotFoundException(UserEntity::class, "User with id $workspaceId not found", workspaceId) + throw InstanceNotFoundException( + UserEntity::class, + "User with id $workspaceId not found", + workspaceId + ) if (!userRepository.existsById(userId)) throw InstanceNotFoundException(UserEntity::class, "User with id $userId not found", userId) bookingRepository.findAllByOwnerAndWorkspaceId(userId, workspaceId) } + userId != null -> { if (!userRepository.existsById(userId)) throw InstanceNotFoundException(UserEntity::class, "User with id $userId not found", userId) bookingRepository.findAllByOwnerId(userId) } + workspaceId != null -> { if (!workspaceRepository.workspaceExistsById(workspaceId)) - throw InstanceNotFoundException(UserEntity::class, "User with id $workspaceId not found", workspaceId) + throw InstanceNotFoundException( + UserEntity::class, + "User with id $workspaceId not found", + workspaceId + ) bookingRepository.findAllByWorkspaceId(workspaceId) } + else -> bookingRepository.findAll() } return addIntegrationsAndUtilities(bookingList) @@ -98,6 +111,32 @@ class BookingService(private val bookingRepository: BookingRepository, return bookingList } + private fun addIntegrationsAndUtilities2(bookingList: List): List { + val userIds = mutableSetOf() + val workspaceIds = mutableSetOf() + for (booking in bookingList) { + for (participant in booking.participants) { + userIds.add( + participant.id + ?: throw MissingIdException("User with name ${participant.fullName} doesn't have an id") + ) + } + userIds.add( + booking.owner.id + ?: throw MissingIdException("User with name ${booking.owner.fullName} doesn't have an id") + ) + workspaceIds.add( + booking.workspace.id + ?: throw MissingIdException("Workspace with name ${booking.workspace.name} doesn't have an id") + ) + } + val utilities = workspaceRepository.findAllUtilitiesWorkspaceById(workspaceIds) + for (booking in bookingList) { + booking.workspace.utilities = utilities[booking.workspace.id] ?: listOf() + } + return bookingList + } + /** * Retrieves all integrations for a given user model * @@ -107,7 +146,7 @@ class BookingService(private val bookingRepository: BookingRepository, */ private fun findIntegrations(user: UserModel): Set { val userId = user.id - ?: throw MissingIdException("User with name ${ user.fullName } doesn't have an id") + ?: throw MissingIdException("User with name ${user.fullName} doesn't have an id") return userRepository.findSetOfIntegrationsByUser(userId) } @@ -120,7 +159,7 @@ class BookingService(private val bookingRepository: BookingRepository, */ private fun findUtilities(workspace: Workspace): List { val workspaceId = workspace.id - ?: throw MissingIdException("Workspace with name ${ workspace.name } doesn't have an id") + ?: throw MissingIdException("Workspace with name ${workspace.name} doesn't have an id") return workspaceRepository.findUtilitiesByWorkspaceId(workspaceId) } 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 1a90ff19..2e60efc4 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 @@ -65,6 +65,25 @@ class WorkspaceRepository(private val database: Database, private val converter: } } + + fun findAllUtilitiesByWorkspaceId(ids: Collection): HashMap> { + val result = hashMapOf>() + database + .from(WorkspaceUtilities) + .innerJoin(right = Utilities, on = WorkspaceUtilities.utilityId eq Utilities.id) + .select() + .where { WorkspaceUtilities.workspaceId inList ids } + .forEach { row -> + val workspaceId: UUID = row[WorkspaceUtilities.workspaceId] ?: return@forEach + val utility = converter.utilityEntityToModel( + Utilities.createEntity(row), row[WorkspaceUtilities.count] ?: 0 + ) + val set: MutableList = result.getOrPut(workspaceId) { mutableListOf() } + set.add(utility) + } + return result + } + /** * Retrieves a workspace model by its id * -- GitLab From 1bb0e9605571118fc847e39659b05a6b41cc0502 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 13 Aug 2023 12:26:17 +0600 Subject: [PATCH 03/11] [+] add findAllIntegrationsByUserIds method --- .../booking/service/BookingService.kt | 7 +++++- .../features/user/di/userDIModule.kt | 2 +- .../user/repository/UserRepository.kt | 24 ++++++++++++++++++- .../repository/WorkspaceRepository.kt | 6 ++--- 4 files changed, 33 insertions(+), 6 deletions(-) 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 d9685873..e3c6ece2 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 @@ -130,9 +130,14 @@ class BookingService( ?: throw MissingIdException("Workspace with name ${booking.workspace.name} doesn't have an id") ) } - val utilities = workspaceRepository.findAllUtilitiesWorkspaceById(workspaceIds) + val utilities = workspaceRepository.findAllUtilitiesByWorkspaceIds(workspaceIds) + val integrations = userRepository.findAllIntegrationsByUserIds(userIds) for (booking in bookingList) { booking.workspace.utilities = utilities[booking.workspace.id] ?: listOf() + booking.owner.integrations = integrations[booking.owner.id] ?: setOf() + for (participant in booking.participants) { + participant.integrations = integrations[participant.id] + } } return bookingList } diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/di/userDIModule.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/di/userDIModule.kt index a4e95222..9b0705c1 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/di/userDIModule.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/di/userDIModule.kt @@ -18,7 +18,7 @@ val userDIModule = module(createdAtStart = true) { single { IntegrationModelEntityConverter() } single { UserModelEntityConverter() } single { UserDTOModelConverter(get(), get(), get()) } - single { UserRepository(get(), get()) } + single { UserRepository(get(), get(), get()) } single { UserFacade(get(), get(), get(), get()) } single { IntegrationDTOModelConverter(get()) } } \ No newline at end of file diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt index 45244366..1b2c3e7a 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt @@ -1,6 +1,7 @@ package office.effective.features.user.repository import office.effective.common.exception.* +import office.effective.features.user.converters.IntegrationModelEntityConverter import office.effective.features.user.converters.UserModelEntityConverter import office.effective.model.IntegrationModel import office.effective.model.UserModel @@ -10,7 +11,10 @@ import org.ktorm.dsl.* import org.ktorm.entity.* import java.util.* -class UserRepository(private val db: Database, private val converter: UserModelEntityConverter) { +class UserRepository(private val db: Database, + private val converter: UserModelEntityConverter, + private val integrationConverter: IntegrationModelEntityConverter +) { /** * Checks existence of user by id, using count @@ -119,6 +123,24 @@ class UserRepository(private val db: Database, private val converter: UserModelE return modelsSet; } + fun findAllIntegrationsByUserIds(ids: Collection): HashMap> { + val result = hashMapOf>() + db + .from(UsersIntegrations) + .innerJoin(right = Integrations, on = UsersIntegrations.integrationId eq Integrations.id) + .select() + .where { UsersIntegrations.integrationId inList ids } + .forEach { row -> + val userId: UUID = row[UsersIntegrations.integrationId] ?: return@forEach + val utility = integrationConverter.entityToModel( + Integrations.createEntity(row), row[UsersIntegrations.valueStr] ?: "" + ) + val integrations: MutableSet = result.getOrPut(userId) { mutableSetOf() } + integrations.add(utility) + } + return result + } + /** * Returns TagModel by value * @return UserTagModel 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 2e60efc4..8bcc2244 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 @@ -66,7 +66,7 @@ class WorkspaceRepository(private val database: Database, private val converter: } - fun findAllUtilitiesByWorkspaceId(ids: Collection): HashMap> { + fun findAllUtilitiesByWorkspaceIds(ids: Collection): HashMap> { val result = hashMapOf>() database .from(WorkspaceUtilities) @@ -78,8 +78,8 @@ class WorkspaceRepository(private val database: Database, private val converter: val utility = converter.utilityEntityToModel( Utilities.createEntity(row), row[WorkspaceUtilities.count] ?: 0 ) - val set: MutableList = result.getOrPut(workspaceId) { mutableListOf() } - set.add(utility) + val utilities: MutableList = result.getOrPut(workspaceId) { mutableListOf() } + utilities.add(utility) } return result } -- GitLab From 370df83dc4f37e2eda99f48777fbc2c624cc2ec1 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 13 Aug 2023 12:53:21 +0600 Subject: [PATCH 04/11] [+] add service method to add integrations and utilities --- .../booking/service/BookingService.kt | 31 ++++++++++++------- .../user/repository/UserRepository.kt | 11 +++++++ .../repository/WorkspaceRepository.kt | 13 +++++++- 3 files changed, 43 insertions(+), 12 deletions(-) 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 e3c6ece2..c947fbc0 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 @@ -101,17 +101,6 @@ class BookingService( * @author Daniil Zavyalov */ private fun addIntegrationsAndUtilities(bookingList: List): List { - for (booking in bookingList) { - for (participant in booking.participants) { - participant.integrations = findIntegrations(participant) - } - booking.owner.integrations = findIntegrations(booking.owner) - booking.workspace.utilities = findUtilities(booking.workspace) - } - return bookingList - } - - private fun addIntegrationsAndUtilities2(bookingList: List): List { val userIds = mutableSetOf() val workspaceIds = mutableSetOf() for (booking in bookingList) { @@ -142,6 +131,26 @@ class BookingService( return bookingList } + /** + * Adds integrations and utilities to related user and workspace models. + * Use the returned booking list for further operations + * + * @throws MissingIdException if user or workspace doesn't have an id + * + * @author Daniil Zavyalov + */ + @Deprecated("Too many database requests") + private fun findIntegrationsAndUtilities(bookingList: List): List { + for (booking in bookingList) { + for (participant in booking.participants) { + participant.integrations = findIntegrations(participant) + } + booking.owner.integrations = findIntegrations(booking.owner) + booking.workspace.utilities = findUtilities(booking.workspace) + } + return bookingList + } + /** * Retrieves all integrations for a given user model * diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt index 1b2c3e7a..af331093 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/repository/UserRepository.kt @@ -123,7 +123,18 @@ class UserRepository(private val db: Database, return modelsSet; } + /** + * Returns a HashMap that maps user ids and their integrations + * @return HashMap> + * @throws InstanceNotFoundException if user with the given id doesn't exist in the database + * + * @author Daniil Zavyalov + * */ fun findAllIntegrationsByUserIds(ids: Collection): HashMap> { + for (id in ids) { + if (!existsById(id)) + throw InstanceNotFoundException(UserEntity::class, "User with id $id not found") + } val result = hashMapOf>() db .from(UsersIntegrations) 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 8bcc2244..c77ed407 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 @@ -2,6 +2,7 @@ package office.effective.features.workspace.repository import office.effective.common.exception.InstanceNotFoundException import office.effective.features.booking.repository.WorkspaceBooking +import office.effective.features.user.repository.UserEntity import office.effective.features.workspace.converters.WorkspaceRepositoryConverter import office.effective.model.Utility import office.effective.model.Workspace @@ -65,8 +66,18 @@ class WorkspaceRepository(private val database: Database, private val converter: } } - + /** + * Returns a HashMap that maps user ids and their integrations + * @return HashMap> + * @throws InstanceNotFoundException if user with the given id doesn't exist in the database + * + * @author Daniil Zavyalov + * */ fun findAllUtilitiesByWorkspaceIds(ids: Collection): HashMap> { + for (id in ids) { + if (!workspaceExistsById(id)) + throw InstanceNotFoundException(WorkspaceEntity::class, "Workspace with id $id not found") + } val result = hashMapOf>() database .from(WorkspaceUtilities) -- GitLab From 7e9cd3954b9246b97118f73d4005d522e99ff022 Mon Sep 17 00:00:00 2001 From: Kiselev Danil Date: Sun, 13 Aug 2023 16:38:56 +0600 Subject: [PATCH 05/11] [+] add .env example file --- effectiveOfficeBackend/.env.example | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 effectiveOfficeBackend/.env.example diff --git a/effectiveOfficeBackend/.env.example b/effectiveOfficeBackend/.env.example new file mode 100644 index 00000000..9592f2d0 --- /dev/null +++ b/effectiveOfficeBackend/.env.example @@ -0,0 +1,11 @@ +POSTGRES_PASSWORD=1234567890test +POSTGRES_DB=effectiveOfficeBackendDB +POSTGRES_USER=postgres +DATABASE_PASSWORD=1234567890test +GOOGLE_CLIENT_ID=random +GOOGLE_CLIENT_SECRET=random +VERIFICATION_PLUGIN_ENABLE=false +DATABASE_HOST=0.0.0.0 +DATABASE_PORT=15432 +DATABASE_NAME=effectiveOfficeBackendDB +DATABASE_USERNAME=postgres \ No newline at end of file -- GitLab From 071a381abdf6ae0055f644580e4a430114c62a45 Mon Sep 17 00:00:00 2001 From: Kiselev Danil Date: Sun, 13 Aug 2023 16:42:05 +0600 Subject: [PATCH 06/11] [~] change postgres port to 15432 and host config changed to 0.0.0.0 --- effectiveOfficeBackend/docker-compose.yml | 3 ++- effectiveOfficeBackend/src/main/resources/application.conf | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/effectiveOfficeBackend/docker-compose.yml b/effectiveOfficeBackend/docker-compose.yml index 78b660e1..d37c7d4f 100644 --- a/effectiveOfficeBackend/docker-compose.yml +++ b/effectiveOfficeBackend/docker-compose.yml @@ -14,6 +14,7 @@ services: DATABASE_USERNAME: ${POSTGRES_USER} DATABASE_PORT: "5432" DATABASE_NAME: ${POSTGRES_DB} + VERIFICATION_PLUGIN_ENABLE: ${VERIFICATION_PLUGIN_ENABLE} db_postgres: container_name: postgresForKtor @@ -25,7 +26,7 @@ services: - POSTGRES_USER - POSTGRES_PASSWORD ports: - - "5432:5432" + - "15432:5432" restart: "always" healthcheck: test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ] diff --git a/effectiveOfficeBackend/src/main/resources/application.conf b/effectiveOfficeBackend/src/main/resources/application.conf index bbfa22d5..3db6edf7 100644 --- a/effectiveOfficeBackend/src/main/resources/application.conf +++ b/effectiveOfficeBackend/src/main/resources/application.conf @@ -1,7 +1,7 @@ ktor { deployment { port = 8080 - host = "localhost" + host = "0.0.0.0" } } database { -- GitLab From e8d40891f97c72bff26a772a0441f48810a5dfc5 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 13 Aug 2023 17:02:13 +0600 Subject: [PATCH 07/11] [~] fix --- .../booking/service/BookingService.kt | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) 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 c947fbc0..d9d41ff5 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 @@ -39,13 +39,21 @@ class BookingService( * @author Daniil Zavyalov */ fun findById(id: UUID): Booking? { - val booking = bookingRepository.findById(id) - booking?.let { - for (participant in it.participants) { - participant.integrations = findIntegrations(participant) - } - it.owner.integrations = findIntegrations(it.owner) - it.workspace.utilities = findUtilities(it.workspace) + val booking = bookingRepository.findById(id) ?: return null + val userIds = mutableSetOf() + for (participant in booking.participants) { + userIds.add(participant.id + ?: throw MissingIdException("User with name ${participant.fullName} doesn't have an id") + ) + } + userIds.add(booking.owner.id + ?: throw MissingIdException("User with name ${booking.owner.fullName} doesn't have an id") + ) + val integrations = userRepository.findAllIntegrationsByUserIds(userIds) + booking.workspace.utilities = findUtilities(booking.workspace) + booking.owner.integrations = integrations[booking.owner.id] ?: setOf() + for (participant in booking.participants) { + participant.integrations = integrations[participant.id] ?: setOf() } return booking } @@ -89,7 +97,7 @@ class BookingService( else -> bookingRepository.findAll() } - return addIntegrationsAndUtilities(bookingList) + return findIntegrationsAndUtilities(bookingList) } /** @@ -100,7 +108,7 @@ class BookingService( * * @author Daniil Zavyalov */ - private fun addIntegrationsAndUtilities(bookingList: List): List { + private fun findIntegrationsAndUtilities(bookingList: List): List { val userIds = mutableSetOf() val workspaceIds = mutableSetOf() for (booking in bookingList) { @@ -121,32 +129,28 @@ class BookingService( } val utilities = workspaceRepository.findAllUtilitiesByWorkspaceIds(workspaceIds) val integrations = userRepository.findAllIntegrationsByUserIds(userIds) - for (booking in bookingList) { - booking.workspace.utilities = utilities[booking.workspace.id] ?: listOf() - booking.owner.integrations = integrations[booking.owner.id] ?: setOf() - for (participant in booking.participants) { - participant.integrations = integrations[participant.id] - } - } - return bookingList + return addIntegrationsAndUtilities(bookingList, integrations, utilities) } /** - * Adds integrations and utilities to related user and workspace models. - * Use the returned booking list for further operations + * Adds integrations and utilities to users and workspace + * related with the given booking model * - * @throws MissingIdException if user or workspace doesn't have an id + * @throws MissingIdException if user model doesn't have an id * * @author Daniil Zavyalov */ - @Deprecated("Too many database requests") - private fun findIntegrationsAndUtilities(bookingList: List): List { + private fun addIntegrationsAndUtilities( + bookingList: List, + integrations: HashMap>, + utilities: HashMap> + ): List { for (booking in bookingList) { + booking.workspace.utilities = utilities[booking.workspace.id] ?: listOf() + booking.owner.integrations = integrations[booking.owner.id] ?: setOf() for (participant in booking.participants) { - participant.integrations = findIntegrations(participant) + participant.integrations = integrations[participant.id] } - booking.owner.integrations = findIntegrations(booking.owner) - booking.workspace.utilities = findUtilities(booking.workspace) } return bookingList } -- GitLab From 224e29f58c3ec9bd033a76866539bab484677cf2 Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 13 Aug 2023 17:10:46 +0600 Subject: [PATCH 08/11] [~] add MIGRATIONS_ENABLE env variable --- .../office/effective/plugins/Migration.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt index 205fb352..fd9abd4e 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/Migration.kt @@ -21,16 +21,19 @@ fun Application.configureMigration() { ?.getString() ?: "changelog/changelog-master.yaml" val defaultSchemaName: String = config.propertyOrNull("liquibase.defaultSchemaName") ?.getString() ?: "public" + val migrationsEnable: Boolean = System.getenv("MIGRATIONS_ENABLE").equals("true") - val connection = DriverManager.getConnection( - url, - username, - password - ) - val databaseConnection = JdbcConnection(connection) - val database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection) - database.defaultSchemaName = defaultSchemaName - val liquibase = Liquibase(changelogFile, ClassLoaderResourceAccessor(), database) - liquibase.update("") - liquibase.database.close() + if (migrationsEnable) { + val connection = DriverManager.getConnection( + url, + username, + password + ) + val databaseConnection = JdbcConnection(connection) + val database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(databaseConnection) + database.defaultSchemaName = defaultSchemaName + val liquibase = Liquibase(changelogFile, ClassLoaderResourceAccessor(), database) + liquibase.update("") + liquibase.database.close() + } } -- GitLab From 4c070dd7bd9a585940b902c2f1e7ba18ab12a67e Mon Sep 17 00:00:00 2001 From: Daniil Zavyalov Date: Sun, 13 Aug 2023 17:18:53 +0600 Subject: [PATCH 09/11] [~] move DTO to root package --- .../{features/booking => }/dto/BookingDTO.kt | 6 +++--- .../{features/user => }/dto/IntegrationDTO.kt | 2 +- .../effective/{features/user => }/dto/UserDTO.kt | 2 +- .../{features/workspace => }/dto/UtilityDTO.kt | 2 +- .../{features/workspace => }/dto/WorkspaceDTO.kt | 2 +- .../{features/workspace => }/dto/WorkspaceZoneDTO.kt | 2 +- .../booking/converters/BookingFacadeConverter.kt | 2 +- .../features/booking/facade/BookingFacade.kt | 2 +- .../features/booking/routes/BookingRouting.kt | 2 +- .../features/booking/routes/swagger/BookingSwagger.kt | 11 +++++------ .../user/converters/IntegrationDTOModelConverter.kt | 3 +-- .../features/user/converters/UserDTOModelConverter.kt | 6 ++---- .../effective/features/user/facade/UserFacade.kt | 2 +- .../features/user/routes/swagger/AuthSwagger.kt | 1 - .../features/user/routes/swagger/UserSwagger.kt | 5 ++--- .../effective/features/user/routes/userRouting.kt | 2 +- .../workspace/converters/WorkspaceFacadeConverter.kt | 6 +++--- .../features/workspace/facade/WorkspaceFacade.kt | 4 ++-- .../workspace/routes/swagger/WorkspaceSwagger.kt | 6 +++--- .../office/effective/plugins/RequestValidation.kt | 2 +- .../office/effective/booking/BookingFacadeTest.kt | 6 +++--- .../office/effective/workspace/WorkspaceFacadeTest.kt | 3 +-- 22 files changed, 36 insertions(+), 43 deletions(-) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/booking => }/dto/BookingDTO.kt (61%) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/user => }/dto/IntegrationDTO.kt (77%) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/user => }/dto/UserDTO.kt (85%) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/workspace => }/dto/UtilityDTO.kt (75%) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/workspace => }/dto/WorkspaceDTO.kt (80%) rename effectiveOfficeBackend/src/main/kotlin/office/effective/{features/workspace => }/dto/WorkspaceZoneDTO.kt (71%) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/dto/BookingDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt similarity index 61% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/dto/BookingDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt index ac0eadb4..22ae0b23 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/dto/BookingDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt @@ -1,8 +1,8 @@ -package office.effective.features.booking.dto +package office.effective.dto import kotlinx.serialization.Serializable -import office.effective.features.user.dto.UserDTO -import office.effective.features.workspace.dto.WorkspaceDTO +import office.effective.dto.UserDTO +import office.effective.dto.WorkspaceDTO @Serializable data class BookingDTO ( diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/IntegrationDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/IntegrationDTO.kt similarity index 77% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/IntegrationDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/IntegrationDTO.kt index 528026f8..3dd7c0cd 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/IntegrationDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/IntegrationDTO.kt @@ -1,4 +1,4 @@ -package office.effective.features.user.dto +package office.effective.dto import kotlinx.serialization.Serializable diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/UserDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UserDTO.kt similarity index 85% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/UserDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UserDTO.kt index 965ab4c2..3c602f43 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/dto/UserDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UserDTO.kt @@ -1,4 +1,4 @@ -package office.effective.features.user.dto +package office.effective.dto import kotlinx.serialization.Serializable diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/UtilityDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UtilityDTO.kt similarity index 75% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/UtilityDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UtilityDTO.kt index 3f2a7fdc..75ee1cbf 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/UtilityDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/UtilityDTO.kt @@ -1,4 +1,4 @@ -package office.effective.features.workspace.dto +package office.effective.dto import kotlinx.serialization.Serializable diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceDTO.kt similarity index 80% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceDTO.kt index 6748a102..72c1a58e 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceDTO.kt @@ -1,4 +1,4 @@ -package office.effective.features.workspace.dto +package office.effective.dto import kotlinx.serialization.Serializable diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceZoneDTO.kt similarity index 71% rename from effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt rename to effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceZoneDTO.kt index 6a740762..daec898d 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/workspace/dto/WorkspaceZoneDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/WorkspaceZoneDTO.kt @@ -1,4 +1,4 @@ -package office.effective.features.workspace.dto +package office.effective.dto import kotlinx.serialization.Serializable 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 4b8e26bb..a62e4a47 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 @@ -1,7 +1,7 @@ package office.effective.features.booking.converters import office.effective.common.utils.UuidValidator -import office.effective.features.booking.dto.BookingDTO +import office.effective.dto.BookingDTO import office.effective.features.user.converters.UserDTOModelConverter import office.effective.features.workspace.converters.WorkspaceFacadeConverter import office.effective.model.Booking 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 b76b9828..f84ac19f 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 @@ -4,7 +4,7 @@ import office.effective.common.exception.InstanceNotFoundException import office.effective.common.utils.DatabaseTransactionManager import office.effective.common.utils.UuidValidator import office.effective.features.booking.converters.BookingFacadeConverter -import office.effective.features.booking.dto.BookingDTO +import office.effective.dto.BookingDTO import office.effective.features.booking.service.BookingService import office.effective.model.Booking import office.effective.model.Workspace diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/BookingRouting.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/BookingRouting.kt index 8c5d88f5..ae3106b6 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/BookingRouting.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/booking/routes/BookingRouting.kt @@ -10,7 +10,7 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import office.effective.common.swagger.SwaggerDocument -import office.effective.features.booking.dto.BookingDTO +import office.effective.dto.BookingDTO import office.effective.features.booking.facade.BookingFacade import office.effective.features.booking.routes.swagger.* import org.koin.core.context.GlobalContext 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 b10ae0f4..a5b37d72 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 @@ -3,12 +3,11 @@ package office.effective.features.booking.routes.swagger import io.github.smiley4.ktorswaggerui.dsl.OpenApiRoute import io.ktor.http.* import office.effective.common.swagger.SwaggerDocument -import office.effective.features.booking.dto.BookingDTO -import office.effective.features.user.dto.IntegrationDTO -import office.effective.features.user.dto.UserDTO -import office.effective.features.workspace.dto.UtilityDTO -import office.effective.features.workspace.dto.WorkspaceDTO -import office.effective.features.workspace.routes.swagger.WorkspaceTag +import office.effective.dto.BookingDTO +import office.effective.dto.IntegrationDTO +import office.effective.dto.UserDTO +import office.effective.dto.UtilityDTO +import office.effective.dto.WorkspaceDTO fun SwaggerDocument.returnBookingById(): OpenApiRoute.() -> Unit = { description = "Returns booking found by id" diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/IntegrationDTOModelConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/IntegrationDTOModelConverter.kt index f4ddccec..c0d74b2c 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/IntegrationDTOModelConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/IntegrationDTOModelConverter.kt @@ -1,9 +1,8 @@ package office.effective.features.user.converters import office.effective.common.utils.UuidValidator -import office.effective.features.user.dto.IntegrationDTO +import office.effective.dto.IntegrationDTO import office.effective.model.IntegrationModel -import java.util.* class IntegrationDTOModelConverter( private val uuidConverter : UuidValidator diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/UserDTOModelConverter.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/UserDTOModelConverter.kt index 484f894a..d1879337 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/UserDTOModelConverter.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/converters/UserDTOModelConverter.kt @@ -1,14 +1,12 @@ package office.effective.features.user.converters import office.effective.common.utils.UuidValidator -import office.effective.features.user.dto.IntegrationDTO -import office.effective.features.user.dto.UserDTO +import office.effective.dto.IntegrationDTO +import office.effective.dto.UserDTO import office.effective.features.user.repository.UserRepository import office.effective.features.user.repository.UsersTagEntity import office.effective.model.IntegrationModel import office.effective.model.UserModel -import org.koin.core.context.GlobalContext -import java.util.UUID class UserDTOModelConverter( private val repository: UserRepository, diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/facade/UserFacade.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/facade/UserFacade.kt index 78bfcb0d..967d5204 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/facade/UserFacade.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/facade/UserFacade.kt @@ -3,7 +3,7 @@ package office.effective.features.user.facade import office.effective.common.utils.DatabaseTransactionManager import office.effective.features.user.ITokenVerifier import office.effective.features.user.converters.UserDTOModelConverter -import office.effective.features.user.dto.UserDTO +import office.effective.dto.UserDTO import office.effective.features.user.service.IUserService import office.effective.model.UserModel diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/AuthSwagger.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/AuthSwagger.kt index 5e74e6ce..1bffb7b8 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/AuthSwagger.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/AuthSwagger.kt @@ -3,7 +3,6 @@ package office.effective.features.user.routes.swagger import io.github.smiley4.ktorswaggerui.dsl.OpenApiRoute import io.ktor.http.* import office.effective.common.swagger.SwaggerDocument -import office.effective.features.user.dto.UserDTO fun SwaggerDocument.login(): OpenApiRoute.() -> Unit = { description = "Empty route. Need to redirect to google authentication page" diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/UserSwagger.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/UserSwagger.kt index fc7cc414..79c0cdfa 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/UserSwagger.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/swagger/UserSwagger.kt @@ -3,9 +3,8 @@ package office.effective.features.user.routes.swagger import io.github.smiley4.ktorswaggerui.dsl.OpenApiRoute import io.ktor.http.* import office.effective.common.swagger.SwaggerDocument -import office.effective.features.booking.dto.BookingDTO -import office.effective.features.user.dto.IntegrationDTO -import office.effective.features.user.dto.UserDTO +import office.effective.dto.IntegrationDTO +import office.effective.dto.UserDTO fun SwaggerDocument.returnUserByEmail(): OpenApiRoute.() -> Unit = { description = "Return user by email" diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/userRouting.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/userRouting.kt index 06c2cd04..cf8045c0 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/userRouting.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/features/user/routes/userRouting.kt @@ -11,7 +11,7 @@ import io.ktor.server.routing.* import office.effective.common.swagger.SwaggerDocument import office.effective.features.user.ITokenVerifier import office.effective.features.user.converters.UserDTOModelConverter -import office.effective.features.user.dto.UserDTO +import office.effective.dto.UserDTO import office.effective.features.user.facade.UserFacade import office.effective.features.user.repository.UserRepository import office.effective.features.user.routes.swagger.updateUser 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 ae8ea18c..e95b7e1c 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 @@ -1,9 +1,9 @@ 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.dto.UtilityDTO +import office.effective.dto.WorkspaceDTO +import office.effective.dto.WorkspaceZoneDTO import office.effective.model.Utility import office.effective.model.Workspace import office.effective.model.WorkspaceZone 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 4b1f03df..26575458 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 @@ -5,8 +5,8 @@ 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.dto.WorkspaceDTO +import office.effective.dto.WorkspaceZoneDTO import office.effective.features.workspace.service.WorkspaceService import office.effective.model.Workspace import java.time.Instant 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 fa7a1c9b..10fca709 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 @@ -3,9 +3,9 @@ package office.effective.features.workspace.routes.swagger import io.github.smiley4.ktorswaggerui.dsl.OpenApiRoute 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 +import office.effective.dto.UtilityDTO +import office.effective.dto.WorkspaceDTO +import office.effective.dto.WorkspaceZoneDTO fun SwaggerDocument.returnWorkspaceById(): OpenApiRoute.() -> Unit = { description = "Return workspace by id" diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt index 8979ebe9..9d6c6d07 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/plugins/RequestValidation.kt @@ -2,7 +2,7 @@ package office.effective.plugins import io.ktor.server.application.* import io.ktor.server.plugins.requestvalidation.* -import office.effective.features.booking.dto.BookingDTO +import office.effective.dto.BookingDTO fun Application.configureValidation() { install(RequestValidation) { diff --git a/effectiveOfficeBackend/src/test/kotlin/office/effective/booking/BookingFacadeTest.kt b/effectiveOfficeBackend/src/test/kotlin/office/effective/booking/BookingFacadeTest.kt index 1779cd8d..824e3e98 100644 --- a/effectiveOfficeBackend/src/test/kotlin/office/effective/booking/BookingFacadeTest.kt +++ b/effectiveOfficeBackend/src/test/kotlin/office/effective/booking/BookingFacadeTest.kt @@ -5,11 +5,11 @@ import office.effective.common.exception.InstanceNotFoundException import office.effective.common.utils.DatabaseTransactionManager import office.effective.common.utils.UuidValidator import office.effective.features.booking.converters.BookingFacadeConverter -import office.effective.features.booking.dto.BookingDTO +import office.effective.dto.BookingDTO import office.effective.features.booking.facade.BookingFacade import office.effective.features.booking.service.BookingService -import office.effective.features.user.dto.UserDTO -import office.effective.features.workspace.dto.WorkspaceDTO +import office.effective.dto.UserDTO +import office.effective.dto.WorkspaceDTO import office.effective.model.Booking import office.effective.model.UserModel import office.effective.model.Workspace diff --git a/effectiveOfficeBackend/src/test/kotlin/office/effective/workspace/WorkspaceFacadeTest.kt b/effectiveOfficeBackend/src/test/kotlin/office/effective/workspace/WorkspaceFacadeTest.kt index 701658ec..a243c088 100644 --- a/effectiveOfficeBackend/src/test/kotlin/office/effective/workspace/WorkspaceFacadeTest.kt +++ b/effectiveOfficeBackend/src/test/kotlin/office/effective/workspace/WorkspaceFacadeTest.kt @@ -2,11 +2,10 @@ package office.effective.workspace import junit.framework.TestCase.assertEquals 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.dto.WorkspaceDTO import office.effective.features.workspace.facade.WorkspaceFacade import office.effective.features.workspace.service.WorkspaceService import office.effective.model.Workspace -- GitLab From 979766823b99d8f2f10a2873df1a878478cdabd0 Mon Sep 17 00:00:00 2001 From: Kiselev Danil Date: Sun, 13 Aug 2023 21:14:34 +0600 Subject: [PATCH 10/11] [+] add MIGRATIONS_ENABLE env variable to app container --- effectiveOfficeBackend/docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/effectiveOfficeBackend/docker-compose.yml b/effectiveOfficeBackend/docker-compose.yml index d37c7d4f..59d9458a 100644 --- a/effectiveOfficeBackend/docker-compose.yml +++ b/effectiveOfficeBackend/docker-compose.yml @@ -15,6 +15,7 @@ services: DATABASE_PORT: "5432" DATABASE_NAME: ${POSTGRES_DB} VERIFICATION_PLUGIN_ENABLE: ${VERIFICATION_PLUGIN_ENABLE} + MIGRATIONS_ENABLE: ${MIGRATIONS_ENABLE} db_postgres: container_name: postgresForKtor -- GitLab From 6c95407255ede67783329893400442fc31d20bf2 Mon Sep 17 00:00:00 2001 From: Kiselev Danil Date: Sun, 13 Aug 2023 21:17:56 +0600 Subject: [PATCH 11/11] [~] change booking dto variables to be immutable --- .../main/kotlin/office/effective/dto/BookingDTO.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt index 22ae0b23..75fb8d57 100644 --- a/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt +++ b/effectiveOfficeBackend/src/main/kotlin/office/effective/dto/BookingDTO.kt @@ -6,10 +6,10 @@ import office.effective.dto.WorkspaceDTO @Serializable data class BookingDTO ( - var owner: UserDTO, - var participants: List, - var workspace: WorkspaceDTO, - var id: String?, - var beginBooking: Long, - var endBooking: Long + val owner: UserDTO, + val participants: List, + val workspace: WorkspaceDTO, + val id: String?, + val beginBooking: Long, + val endBooking: Long ) -- GitLab