From 2f3e5c86a0ba1c96db29fb1e836941a88462f196 Mon Sep 17 00:00:00 2001 From: Sim-km Date: Sat, 19 Oct 2024 16:23:28 +0900 Subject: [PATCH] =?UTF-8?q?ASAP-212=20fix:=20=EC=83=88=20=ED=96=89?= =?UTF-8?q?=EC=84=B1=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=20=ED=96=89=EC=84=B1=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../space/port/out/SpaceManagementPort.kt | 5 ++ .../space/service/SpaceCommandService.kt | 5 +- .../space/SpaceApplicationConfig.kt | 9 +- .../application/space/SpaceMockManager.kt | 12 ++- .../space/SpaceApiIntegrationTest.kt | 85 +++++++++++++++---- .../adapter/SpaceManagementJpaAdapter.kt | 11 ++- 6 files changed, 101 insertions(+), 26 deletions(-) diff --git a/Application-Module/src/main/kotlin/com/asap/application/space/port/out/SpaceManagementPort.kt b/Application-Module/src/main/kotlin/com/asap/application/space/port/out/SpaceManagementPort.kt index 15f0b297..abe2de53 100644 --- a/Application-Module/src/main/kotlin/com/asap/application/space/port/out/SpaceManagementPort.kt +++ b/Application-Module/src/main/kotlin/com/asap/application/space/port/out/SpaceManagementPort.kt @@ -13,6 +13,11 @@ interface SpaceManagementPort { spaceId: DomainId, ): Space + fun getIndexedSpaceNotNull( + userId: DomainId, + spaceId: DomainId, + ): IndexedSpace + fun getAllIndexedSpace(userId: DomainId): List fun save(space: Space): Space diff --git a/Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceCommandService.kt b/Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceCommandService.kt index 03dfaba7..5009cac4 100644 --- a/Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceCommandService.kt +++ b/Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceCommandService.kt @@ -32,9 +32,10 @@ class SpaceCommandService( userId = DomainId(command.userId), name = command.spaceName, templateType = command.templateType, - ).let { - spaceManagementPort.save(it) + ).apply { + spaceManagementPort.save(this) } + reIndexingSpaceOrder(DomainId(command.userId)) } override fun update(command: UpdateSpaceNameUsecase.Command) { diff --git a/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceApplicationConfig.kt b/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceApplicationConfig.kt index 30453cef..8b477d96 100644 --- a/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceApplicationConfig.kt +++ b/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceApplicationConfig.kt @@ -6,11 +6,8 @@ import org.springframework.context.annotation.Bean @TestConfiguration class SpaceApplicationConfig( - private val spaceManagementPort: SpaceManagementPort + private val spaceManagementPort: SpaceManagementPort, ) { - @Bean - fun spaceMockManager(): SpaceMockManager { - return SpaceMockManager(spaceManagementPort) - } -} \ No newline at end of file + fun spaceMockManager(): SpaceMockManager = SpaceMockManager(spaceManagementPort) +} diff --git a/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceMockManager.kt b/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceMockManager.kt index fe80c5eb..4514cce4 100644 --- a/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceMockManager.kt +++ b/Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceMockManager.kt @@ -7,14 +7,22 @@ import com.asap.domain.space.entity.Space class SpaceMockManager( private val spaceManagementPort: SpaceManagementPort, ) { - fun settingSpace(userId: String): Space { + fun settingSpace( + userId: String, + index: Int = 0, + ): Space { val space = Space.create( userId = DomainId(userId), name = "test", templateType = 0, ) - return spaceManagementPort.save(space) + return spaceManagementPort.save(space).also { + spaceManagementPort.getIndexedSpaceNotNull(DomainId(userId), it.id).apply { + updateIndex(index) + spaceManagementPort.update(this) + } + } } fun getSpaceIndexes(userId: String): List> = diff --git a/Bootstrap-Module/src/test/kotlin/com/asap/bootstrap/integration/space/SpaceApiIntegrationTest.kt b/Bootstrap-Module/src/test/kotlin/com/asap/bootstrap/integration/space/SpaceApiIntegrationTest.kt index 36f8c27f..0fe81386 100644 --- a/Bootstrap-Module/src/test/kotlin/com/asap/bootstrap/integration/space/SpaceApiIntegrationTest.kt +++ b/Bootstrap-Module/src/test/kotlin/com/asap/bootstrap/integration/space/SpaceApiIntegrationTest.kt @@ -112,26 +112,81 @@ class SpaceApiIntegrationTest : IntegrationSupporter() { } } - @Test - fun createSpace() { - // given - val userId = userMockManager.settingUser() - val accessToken = jwtMockManager.generateAccessToken(userId) - val request = - CreateSpaceRequest( - spaceName = "spaceName", - templateType = 0, - ) - // when - val response = + @Nested + inner class CreateSpace { + @Test + fun createSpace() { + // given + val userId = userMockManager.settingUser() + val accessToken = jwtMockManager.generateAccessToken(userId) + val request = + CreateSpaceRequest( + spaceName = "spaceName", + templateType = 0, + ) + // when + val response = + mockMvc.post("/api/v1/spaces") { + contentType = MediaType.APPLICATION_JSON + content = objectMapper.writeValueAsString(request) + header("Authorization", "Bearer $accessToken") + } + // then + response.andExpect { + status { isOk() } + } + } + + @Test + fun createSpace_and_get_main_space() { + // given + val userId = userMockManager.settingUser() + val accessToken = jwtMockManager.generateAccessToken(userId) + (0..2).forEach { + spaceMockManager.settingSpace(userId) + } + val request = + CreateSpaceRequest( + spaceName = "createdSpace", + templateType = 0, + ) + // when mockMvc.post("/api/v1/spaces") { contentType = MediaType.APPLICATION_JSON content = objectMapper.writeValueAsString(request) header("Authorization", "Bearer $accessToken") } - // then - response.andExpect { - status { isOk() } + val response = + mockMvc.get("/api/v1/spaces/main") { + contentType = MediaType.APPLICATION_JSON + header("Authorization", "Bearer $accessToken") + } + + // then + response.andExpect { + status { isOk() } + jsonPath("$.spaceId") { + exists() + isString() + isNotEmpty() + } + jsonPath("$.username") { + exists() + isString() + isNotEmpty() + } + jsonPath("$.templateType") { + exists() + isNumber() + value(request.templateType) + } + jsonPath("$.spaceName") { + exists() + isString() + isNotEmpty() + value(request.spaceName) + } + } } } diff --git a/Infrastructure-Module/Persistence/src/main/kotlin/com/asap/persistence/jpa/space/adapter/SpaceManagementJpaAdapter.kt b/Infrastructure-Module/Persistence/src/main/kotlin/com/asap/persistence/jpa/space/adapter/SpaceManagementJpaAdapter.kt index 6d911028..4a6d172e 100644 --- a/Infrastructure-Module/Persistence/src/main/kotlin/com/asap/persistence/jpa/space/adapter/SpaceManagementJpaAdapter.kt +++ b/Infrastructure-Module/Persistence/src/main/kotlin/com/asap/persistence/jpa/space/adapter/SpaceManagementJpaAdapter.kt @@ -31,6 +31,15 @@ class SpaceManagementJpaAdapter( SpaceMapper.toSpace(it) } ?: throw SpaceException.SpaceNotFoundException() + override fun getIndexedSpaceNotNull( + userId: DomainId, + spaceId: DomainId, + ): IndexedSpace { + spaceJpaRepository.findActiveSpaceByIdAndUserId(spaceId.value, userId.value)?.let { + return SpaceMapper.toIndexedSpace(it) + } ?: throw SpaceException.SpaceNotFoundException() + } + override fun getAllIndexedSpace(userId: DomainId): List = spaceJpaRepository .findAllActiveSpaceByUserId(userId.value) @@ -42,7 +51,7 @@ class SpaceManagementJpaAdapter( val entity = SpaceMapper.toSpaceEntity( space = space, - index = spaceJpaRepository.countActiveSpaceByUserId(space.userId.value).toInt(), + index = -1, ) return spaceJpaRepository.save(entity).let { SpaceMapper.toSpace(it)