From 1b106dc944de5c5882310b076cb63682f5cc7eaf Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 20:24:21 +0900 Subject: [PATCH 01/17] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20Response?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/api/response/CategoryElement.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt index 7d24160..3d1a189 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt @@ -1,10 +1,6 @@ package io.github.v1servicenotification.category.api.response -import java.util.UUID - class CategoryElement( - val id: UUID, - val title: String, - val destination: String, val topic: String, + val isActivate: Boolean, ) From fcec0851bf442bceaf3ea94dc08f94772204814f Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 20:25:02 +0900 Subject: [PATCH 02/17] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20Response=EC=97=90?= =?UTF-8?q?=20=EB=A7=9E=EA=B2=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/api/SettingApi.kt | 2 +- .../setting/service/SettingApiImpl.kt | 24 ++++++++--------- .../setting/spi/SettingRepositorySpi.kt | 3 ++- .../stubs/InMemorySettingRepository.kt | 10 +++---- .../setting/SettingApiImplTest.kt | 2 +- .../repository/CustomSettingRepositoryImpl.kt | 27 ++++++++++--------- .../setting/presentation/SettingController.kt | 6 ++--- 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt index de979c1..2c41ba4 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt @@ -6,5 +6,5 @@ import java.util.UUID interface SettingApi { fun activateCategory(categoryId: UUID, userId: UUID): Int fun deActivateCategory(categoryId: UUID, userId: UUID): Int - fun queryActivatedCategory(userId: UUID): CategoryListResponse + fun queryUserCategoryStatus(userId: UUID): CategoryListResponse } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index c1bd1f5..0d7dea5 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -42,18 +42,18 @@ class SettingApiImpl( } } - override fun queryActivatedCategory(userId: UUID): CategoryListResponse { - return CategoryListResponse( - settingRepositorySpi.queryActivatedCategory(userId) - .map { - CategoryElement( - id = it.id, - title = it.title, - destination = it.destination, - topic = it.topic - ) + override fun queryUserCategoryStatus(userId: UUID): CategoryListResponse { + val settingList = settingRepositorySpi.queryUserIdSetting(userId) + val categoryList = settingRepositorySpi.queryUserCategory(userId) + val activatedCategories = settingList + .mapNotNull { setting -> + val category = categoryList.find { it.id == setting.notificationCategoryId } + category?.let { + val topicPrefix = it.topic.substringBefore("_") + CategoryElement(topicPrefix, setting.isActivated) } - .toList() - ) + } + + return CategoryListResponse(activatedCategories) } } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt index fda7c57..92edd08 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt @@ -10,5 +10,6 @@ interface SettingRepositorySpi { fun saveSetting(category: Category, userId: UUID, isActivated: Boolean): Setting fun updateSetting(category: Category, userId: UUID, isActivated: Boolean): Setting fun settingExist(category: Category, userId: UUID): Boolean - fun queryActivatedCategory(userId: UUID): List + fun queryUserIdSetting(userId: UUID): List + fun queryUserCategory(userId: UUID): List } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 12384cc..07f0c52 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -43,16 +43,14 @@ class InMemorySettingRepository( }.isNotEmpty() } - override fun queryActivatedCategory(userId: UUID): List { - return categoryMap.filter { - val setting = findSetting(userId, it.value.id) - setting?.isActivated ?: it.value.defaultActivated - }.map { it.value } - } override fun findAllUserIdByTopicAndIsActivated(topic: String, isActivated: Boolean): List { return settingMap.values.filter { it.isActivated == isActivated && categoryMap[it.notificationCategoryId]?.topic == topic }.map { it.userId } } + + override fun queryUserIdSetting(userId: UUID): List { + return settingMap.filter { it.value.userId == userId }.map { it.value } + } } diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt index 98eba94..7aa0ba7 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt @@ -32,7 +32,7 @@ class SettingApiImplTest { true ) - val result = settingApi.queryActivatedCategory(userId).categories[0] + val result = settingApi.queryUserCategoryStatus(userId).categories[0] assertThat(result.id).isEqualTo(categoryId) assertThat(result.title).isEqualTo(category.title) diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt index 1a6e62e..a9f927c 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt @@ -3,6 +3,7 @@ package io.github.v1servicenotification.domain.setting.domain.repository import com.querydsl.jpa.impl.JPAQueryFactory import io.github.v1servicenotification.category.Category import io.github.v1servicenotification.detail.spi.PostDetailSettingRepositorySpi +import io.github.v1servicenotification.domain.category.domain.CategoryEntity import io.github.v1servicenotification.domain.category.domain.QCategoryEntity.categoryEntity import io.github.v1servicenotification.domain.category.mapper.CategoryMapper import io.github.v1servicenotification.domain.setting.domain.QSettingEntity.settingEntity @@ -47,19 +48,21 @@ class CustomSettingRepositoryImpl( return settingRepository.existsById(getSettingId(category, userId)) } - override fun queryActivatedCategory(userId: UUID): List { + + override fun queryUserIdSetting(userId: UUID): List { return jpaQueryFactory - .select(categoryEntity) - .from(categoryEntity) - .leftJoin(categoryEntity.settingList, settingEntity) - .on(settingEntity.settingId.userId.eq(userId)) - .where( - settingEntity.isActivated.isTrue - .or( - categoryEntity.defaultActivated.isTrue - .and(settingEntity.isActivated.isNull) - ) - ) + .selectFrom(settingEntity) + .where(settingEntity.settingId.userId.eq(userId)) + .fetch() + .map { + settingMapper.settingEntityToDomain(it) + } + } + + override fun queryUserCategory(userId: UUID): List { + return jpaQueryFactory + .selectFrom(categoryEntity) + .where(categoryEntity.eq(settingEntity.settingId.categoryEntity)) .fetch() .map { categoryMapper.categoryEntityToDomain(it) diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt index fa0d773..4a734a4 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt @@ -26,10 +26,10 @@ class SettingController( private val settingApi: SettingApi ) { - @Operation(summary = "활성화된 알림 카테고리 목록") + @Operation(summary = "유저 알림 카테고리 상태 목록") @GetMapping - fun queryActivatedCategory(): CategoryListResponse { - return settingApi.queryActivatedCategory(getUserId()) + fun queryUserCategoryStatus(): CategoryListResponse { + return settingApi.queryUserCategoryStatus(getUserId()) } @Operation(summary = "알림 카테고리 활성화") From 45baa806d82377c20dc98cdf0b718e1b237b9f09 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 22:16:06 +0900 Subject: [PATCH 03/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20associateBy?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/service/SettingApiImpl.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index 0d7dea5..c4d0023 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -45,14 +45,16 @@ class SettingApiImpl( override fun queryUserCategoryStatus(userId: UUID): CategoryListResponse { val settingList = settingRepositorySpi.queryUserIdSetting(userId) val categoryList = settingRepositorySpi.queryUserCategory(userId) - val activatedCategories = settingList - .mapNotNull { setting -> - val category = categoryList.find { it.id == setting.notificationCategoryId } - category?.let { - val topicPrefix = it.topic.substringBefore("_") - CategoryElement(topicPrefix, setting.isActivated) - } + + val categoryMap = categoryList.associateBy { it.id } + + val activatedCategories = settingList.mapNotNull { setting -> + val category = categoryMap[setting.notificationCategoryId] + category?.let { + val topicPrefix = it.topic.substringBefore("_") + CategoryElement(topicPrefix, setting.isActivated) } + } return CategoryListResponse(activatedCategories) } From 449dbccd9e1bca15ccbf363e9bc2a7c5fb71e473 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 20:01:44 +0900 Subject: [PATCH 04/17] =?UTF-8?q?=F0=9F=93=91=20::=20SettingElement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/api/response/SettingElement.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingElement.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingElement.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingElement.kt new file mode 100644 index 0000000..f84ef01 --- /dev/null +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingElement.kt @@ -0,0 +1,6 @@ +package io.github.v1servicenotification.setting.api.response + +data class SettingElement( + val topic: String, + val isActivate: Boolean, +) From 144213a770427f6045cb08ace9a7e931f7fb74b2 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 20:01:52 +0900 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=93=91=20::=20SettingListResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/api/response/SettingListResponse.kt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingListResponse.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingListResponse.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingListResponse.kt new file mode 100644 index 0000000..ddfaf05 --- /dev/null +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/response/SettingListResponse.kt @@ -0,0 +1,5 @@ +package io.github.v1servicenotification.setting.api.response + +data class SettingListResponse( + val settings: List +) From 7c76fdc655a6f2c2f502caa995ba742b7d7ed12f Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 20:02:02 +0900 Subject: [PATCH 06/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=A0=84?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/api/response/CategoryElement.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt index 3d1a189..7d24160 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/api/response/CategoryElement.kt @@ -1,6 +1,10 @@ package io.github.v1servicenotification.category.api.response +import java.util.UUID + class CategoryElement( + val id: UUID, + val title: String, + val destination: String, val topic: String, - val isActivate: Boolean, ) From 3aaeecc8fbf9b57040c81e632bd33355ead8a12d Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 20:02:22 +0900 Subject: [PATCH 07/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Response=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/v1servicenotification/setting/api/SettingApi.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt index 2c41ba4..4c1dd3f 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt @@ -1,10 +1,10 @@ package io.github.v1servicenotification.setting.api -import io.github.v1servicenotification.category.api.response.CategoryListResponse +import io.github.v1servicenotification.setting.api.response.SettingListResponse import java.util.UUID interface SettingApi { fun activateCategory(categoryId: UUID, userId: UUID): Int fun deActivateCategory(categoryId: UUID, userId: UUID): Int - fun queryUserCategoryStatus(userId: UUID): CategoryListResponse + fun queryUserCategoryStatus(userId: UUID): SettingListResponse } From 6457ea6593c498236900f2f02837fe33f90f0d6b Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 20:02:37 +0900 Subject: [PATCH 08/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/service/SettingApiImpl.kt | 11 ++++++----- .../stubs/InMemorySettingRepository.kt | 6 ++++++ .../repository/CustomSettingRepositoryImpl.kt | 14 ++++++++++++-- .../setting/presentation/SettingController.kt | 6 +++--- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index c4d0023..c40c804 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -5,6 +5,8 @@ import io.github.v1servicenotification.category.api.response.CategoryElement import io.github.v1servicenotification.category.api.response.CategoryListResponse import io.github.v1servicenotification.setting.spi.SettingRepositorySpi import io.github.v1servicenotification.setting.api.SettingApi +import io.github.v1servicenotification.setting.api.response.SettingElement +import io.github.v1servicenotification.setting.api.response.SettingListResponse import io.github.v1servicenotification.setting.spi.SettingCategorySpi import java.util.UUID @@ -42,7 +44,7 @@ class SettingApiImpl( } } - override fun queryUserCategoryStatus(userId: UUID): CategoryListResponse { + override fun queryUserCategoryStatus(userId: UUID): SettingListResponse { val settingList = settingRepositorySpi.queryUserIdSetting(userId) val categoryList = settingRepositorySpi.queryUserCategory(userId) @@ -51,11 +53,10 @@ class SettingApiImpl( val activatedCategories = settingList.mapNotNull { setting -> val category = categoryMap[setting.notificationCategoryId] category?.let { - val topicPrefix = it.topic.substringBefore("_") - CategoryElement(topicPrefix, setting.isActivated) + SettingElement(it.topic, setting.isActivated) } - } + }.distinctBy { it.topic } - return CategoryListResponse(activatedCategories) + return SettingListResponse(activatedCategories) } } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 07f0c52..62dfd58 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -53,4 +53,10 @@ class InMemorySettingRepository( override fun queryUserIdSetting(userId: UUID): List { return settingMap.filter { it.value.userId == userId }.map { it.value } } + + override fun queryUserCategory(userId: UUID): List { + return settingMap.filter { it.value.userId == userId }.map { + categoryMap[it.value.notificationCategoryId] ?: throw RuntimeException() + } + } } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt index a9f927c..0061b67 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt @@ -62,10 +62,20 @@ class CustomSettingRepositoryImpl( override fun queryUserCategory(userId: UUID): List { return jpaQueryFactory .selectFrom(categoryEntity) - .where(categoryEntity.eq(settingEntity.settingId.categoryEntity)) + .leftJoin(categoryEntity.settingList, settingEntity) + .where(settingEntity.settingId.userId.eq(userId)) .fetch() .map { - categoryMapper.categoryEntityToDomain(it) + categoryMapper.categoryEntityToDomain( + CategoryEntity( + it.id, + it.title, + it.destination, + it.defaultActivated, + it.settingList, + it.topic.substringBefore("_"), + ) + ) } } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt index 4a734a4..1aeda96 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/presentation/SettingController.kt @@ -1,9 +1,9 @@ package io.github.v1servicenotification.domain.setting.presentation -import io.github.v1servicenotification.category.api.response.CategoryListResponse import io.github.v1servicenotification.global.extension.getUserId import io.github.v1servicenotification.global.util.CustomHttpStatus import io.github.v1servicenotification.setting.api.SettingApi +import io.github.v1servicenotification.setting.api.response.SettingListResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses @@ -28,11 +28,11 @@ class SettingController( @Operation(summary = "유저 알림 카테고리 상태 목록") @GetMapping - fun queryUserCategoryStatus(): CategoryListResponse { + fun queryUserCategoryStatus(): SettingListResponse { return settingApi.queryUserCategoryStatus(getUserId()) } - @Operation(summary = "알림 카테고리 활성화") + @Operation(summary = "알림 카테고리 활성화/비활성화") @ApiResponses(value = [ ApiResponse(responseCode = CustomHttpStatus.CREATED), ApiResponse(responseCode = CustomHttpStatus.NO_CONTENT) From 5c1f815608316559f2dbdf2e8d9fb57b914dd34a Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 22:25:55 +0900 Subject: [PATCH 09/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20exception=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/stubs/InMemorySettingRepository.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 62dfd58..a55ef75 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -1,6 +1,7 @@ package io.github.v1servicenotification.stubs import io.github.v1servicenotification.category.Category +import io.github.v1servicenotification.category.exception.CategoryNotFoundException import io.github.v1servicenotification.detail.spi.PostDetailSettingRepositorySpi import io.github.v1servicenotification.setting.Setting import io.github.v1servicenotification.setting.spi.SettingRepositorySpi @@ -56,7 +57,7 @@ class InMemorySettingRepository( override fun queryUserCategory(userId: UUID): List { return settingMap.filter { it.value.userId == userId }.map { - categoryMap[it.value.notificationCategoryId] ?: throw RuntimeException() + categoryMap[it.value.notificationCategoryId] ?: throw CategoryNotFoundException.EXCEPTION } } } From fc0a4ce936f9c69b290ebaa0fa8a6900eb7c1104 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Tue, 23 May 2023 21:26:56 +0900 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=90=9B=20::=20queryUserCategoryStat?= =?UTF-8?q?us?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/service/SettingApiImpl.kt | 2 -- .../setting/SettingApiImplTest.kt | 11 +++++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index c40c804..f72c7ac 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -1,8 +1,6 @@ package io.github.v1servicenotification.setting.service import io.github.v1servicenotification.annotation.DomainService -import io.github.v1servicenotification.category.api.response.CategoryElement -import io.github.v1servicenotification.category.api.response.CategoryListResponse import io.github.v1servicenotification.setting.spi.SettingRepositorySpi import io.github.v1servicenotification.setting.api.SettingApi import io.github.v1servicenotification.setting.api.response.SettingElement diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt index 7aa0ba7..fb8b655 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt @@ -18,11 +18,12 @@ class SettingApiImplTest { private val settingApi = SettingApiImpl(settingSpi, categorySpi) @Test - fun queryActivatedCategory() { + fun queryUserCategoryStatus() { val userId = UUID.randomUUID() val categoryId = UUID.randomUUID() val category = Category(categoryId, "Test name", "Test destination", false, "ALL") + val setting = Setting(categoryId, userId, true) settingSpi.saveCategory(category) @@ -32,12 +33,10 @@ class SettingApiImplTest { true ) - val result = settingApi.queryUserCategoryStatus(userId).categories[0] - - assertThat(result.id).isEqualTo(categoryId) - assertThat(result.title).isEqualTo(category.title) - assertThat(result.destination).isEqualTo(category.destination) + val result = settingApi.queryUserCategoryStatus(userId).settings[0] + assertThat(result.topic).isEqualTo(category.topic) + assertThat(result.isActivate).isEqualTo(setting.isActivated) } @Test From 851b59dbc6c558be8ee92bfae944e630a4b679ce Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 13:57:10 +0900 Subject: [PATCH 11/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20conflict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/setting/api/SettingApi.kt | 2 -- .../setting/spi/SettingRepositorySpi.kt | 4 +--- .../stubs/InMemorySettingRepository.kt | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt index c8c85b1..a645e66 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/api/SettingApi.kt @@ -4,8 +4,6 @@ import io.github.v1servicenotification.setting.api.response.SettingListResponse import java.util.UUID interface SettingApi { - fun activateCategory(categoryId: UUID, userId: UUID): Int - fun deActivateCategory(categoryId: UUID, userId: UUID): Int fun queryUserCategoryStatus(userId: UUID): SettingListResponse fun activateOrDeActivateCategory(isActivate: Boolean, topic: String, userId: UUID) } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt index bc2eb02..77f3e6e 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt @@ -2,16 +2,14 @@ package io.github.v1servicenotification.setting.spi import io.github.v1servicenotification.annotation.Spi import io.github.v1servicenotification.category.Category +import io.github.v1servicenotification.setting.Setting import java.util.UUID @Spi interface SettingRepositorySpi { - fun saveSetting(category: Category, userId: UUID, isActivated: Boolean): Setting - fun updateSetting(category: Category, userId: UUID, isActivated: Boolean): Setting fun settingExist(category: Category, userId: UUID): Boolean fun queryUserIdSetting(userId: UUID): List fun queryUserCategory(userId: UUID): List fun updateAllSetting(categoryIds: List, userId: UUID, isActivated: Boolean) fun settingExist(categoryIds: List, userId: UUID): Boolean - fun queryActivatedCategory(userId: UUID): List } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index dc227dc..959242b 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -24,6 +24,10 @@ class InMemorySettingRepository( } } + override fun settingExist(category: Category, userId: UUID): Boolean { + return settingMap.values.any { it.userId == userId && it.notificationCategoryId == category.id } + } + override fun settingExist(categoryIds: List, userId: UUID): Boolean { return categoryIds.map { findSetting(userId, it) }.any { it != null } } @@ -41,10 +45,6 @@ class InMemorySettingRepository( }.map { it.userId } } - override fun queryUserIdSetting(userId: UUID): List { - return settingMap.filter { it.value.userId == userId }.map { it.value } - } - override fun queryUserCategory(userId: UUID): List { return settingMap.filter { it.value.userId == userId }.map { categoryMap[it.value.notificationCategoryId] ?: throw CategoryNotFoundException.EXCEPTION From 1c158b8960ed83707115ae5f6788603370ea5d04 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 13:59:23 +0900 Subject: [PATCH 12/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20inmemory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/stubs/InMemorySettingRepository.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 959242b..406be9b 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -32,6 +32,9 @@ class InMemorySettingRepository( return categoryIds.map { findSetting(userId, it) }.any { it != null } } + override fun queryUserIdSetting(userId: UUID): List { + return settingMap.values.filter { it.userId == userId } + } private fun findSetting(userId: UUID, categoryId: UUID): Setting? { return settingMap From e56bb4bc836a3db49f56e4f41031be9e8385954f Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 14:41:31 +0900 Subject: [PATCH 13/17] =?UTF-8?q?=F0=9F=A7=AA=20::=20saveSetting=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stubs/InMemorySettingRepository.kt | 8 ++++++++ .../v1servicenotification/setting/SettingApiImplTest.kt | 9 +++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 406be9b..5838955 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -12,6 +12,14 @@ class InMemorySettingRepository( private val settingMap: HashMap = hashMapOf() ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { + + fun saveSetting(category: Category, userId: UUID, isActivated: Boolean): Setting { + val setting = Setting(userId, category.id, isActivated) + settingMap[UUID.randomUUID()] = setting + + return setting + } + fun saveCategory(category: Category) { categoryMap[category.id] = category } diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt index 5e06208..29ba09d 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/setting/SettingApiImplTest.kt @@ -27,16 +27,13 @@ class SettingApiImplTest { settingSpi.saveCategory(category) - val categoryIds = listOf(category.id) - - - settingSpi.updateAllSetting( - categoryIds, + settingSpi.saveSetting( + category, userId, true ) - val result = settingApi.queryUserCategoryStatus(userId).settings[0] + val result = settingApi.queryUserCategoryStatus(userId).settings.first() assertThat(result.topic).isEqualTo(category.topic) assertThat(result.isActivate).isEqualTo(setting.isActivated) From daf06309b8a93213cb9fb228456c2d0ff879fe17 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 14:50:23 +0900 Subject: [PATCH 14/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=95=88?= =?UTF-8?q?=EC=93=B0=EB=8A=94=EA=B2=83=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/setting/spi/SettingRepositorySpi.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt index 77f3e6e..d4cef29 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingRepositorySpi.kt @@ -7,7 +7,6 @@ import java.util.UUID @Spi interface SettingRepositorySpi { - fun settingExist(category: Category, userId: UUID): Boolean fun queryUserIdSetting(userId: UUID): List fun queryUserCategory(userId: UUID): List fun updateAllSetting(categoryIds: List, userId: UUID, isActivated: Boolean) From 9d6239627c3be2974db51008a8ed641d6988beaf Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 14:54:14 +0900 Subject: [PATCH 15/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20overriding=20?= =?UTF-8?q?=EC=95=88=EB=90=9C=EA=B2=83=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicenotification/stubs/InMemorySettingRepository.kt | 4 ---- .../setting/domain/repository/CustomSettingRepositoryImpl.kt | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt index 5838955..ad68759 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemorySettingRepository.kt @@ -32,10 +32,6 @@ class InMemorySettingRepository( } } - override fun settingExist(category: Category, userId: UUID): Boolean { - return settingMap.values.any { it.userId == userId && it.notificationCategoryId == category.id } - } - override fun settingExist(categoryIds: List, userId: UUID): Boolean { return categoryIds.map { findSetting(userId, it) }.any { it != null } } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt index 13f9165..90c7938 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt @@ -9,6 +9,8 @@ import io.github.v1servicenotification.domain.category.domain.repository.Categor import io.github.v1servicenotification.domain.category.mapper.CategoryMapper import io.github.v1servicenotification.domain.setting.domain.QSettingEntity.settingEntity import io.github.v1servicenotification.domain.setting.domain.SettingId +import io.github.v1servicenotification.domain.setting.mapper.SettingMapper +import io.github.v1servicenotification.setting.Setting import io.github.v1servicenotification.setting.spi.SettingRepositorySpi import org.springframework.stereotype.Repository import java.util.UUID @@ -20,6 +22,7 @@ class CustomSettingRepositoryImpl( private val categoryMapper: CategoryMapper, private val jpaQueryFactory: JPAQueryFactory, private val categoryRepository: CategoryRepository, + private val settingMapper: SettingMapper ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { @Transactional From ae95f26d18e34bf5f191a68c418d60f0257ecb8d Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 16:54:25 +0900 Subject: [PATCH 16/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A6=AC=EB=B7=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/v1servicenotification/category/Category.kt | 6 +++++- .../setting/service/SettingApiImpl.kt | 2 +- .../domain/repository/CustomSettingRepositoryImpl.kt | 11 +---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt index 6851e43..8171029 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt @@ -14,4 +14,8 @@ class Category( val defaultActivated: Boolean, val topic: String, -) +) { + fun getTopicSubStringBy_(): String { + return topic.substringBefore("_") + } +} diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index d38aa5c..a7b599c 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -33,7 +33,7 @@ class SettingApiImpl( val activatedCategories = settingList.mapNotNull { setting -> val category = categoryMap[setting.notificationCategoryId] category?.let { - SettingElement(it.topic, setting.isActivated) + SettingElement(it.getTopicSubStringBy_(), setting.isActivated) } }.distinctBy { it.topic } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt index 90c7938..d137bbc 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/setting/domain/repository/CustomSettingRepositoryImpl.kt @@ -77,16 +77,7 @@ class CustomSettingRepositoryImpl( .where(settingEntity.settingId.userId.eq(userId)) .fetch() .map { - categoryMapper.categoryEntityToDomain( - CategoryEntity( - it.id, - it.title, - it.destination, - it.defaultActivated, - it.settingList, - it.topic.substringBefore("_"), - ) - ) + categoryMapper.categoryEntityToDomain(it) } } From a3db1bbba917f18f26661f5ddd4d685863ca52be Mon Sep 17 00:00:00 2001 From: lyutvs Date: Thu, 25 May 2023 18:47:12 +0900 Subject: [PATCH 17/17] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/github/v1servicenotification/category/Category.kt | 6 +----- .../v1servicenotification/setting/service/SettingApiImpl.kt | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt index 8171029..6851e43 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/category/Category.kt @@ -14,8 +14,4 @@ class Category( val defaultActivated: Boolean, val topic: String, -) { - fun getTopicSubStringBy_(): String { - return topic.substringBefore("_") - } -} +) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt index a7b599c..47bf674 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/service/SettingApiImpl.kt @@ -33,7 +33,8 @@ class SettingApiImpl( val activatedCategories = settingList.mapNotNull { setting -> val category = categoryMap[setting.notificationCategoryId] category?.let { - SettingElement(it.getTopicSubStringBy_(), setting.isActivated) + val topicSubStringByUnderscore = it.topic.substringBefore("_") + SettingElement(topicSubStringByUnderscore, setting.isActivated) } }.distinctBy { it.topic }