From c0b3d5e6b153637cbd07c784c1b34810e7f3d107 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 21:02:39 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/api/SettingApi.kt | 3 +- .../setting/service/SettingApiImpl.kt | 22 ++++------ .../setting/spi/SettingCategorySpi.kt | 3 +- .../setting/spi/SettingRepositorySpi.kt | 6 +-- .../stubs/InMemoryCategoryRepository.kt | 11 ++--- .../stubs/InMemorySettingRepository.kt | 34 ++++++++------- .../CustomCategoryRepositoryImpl.kt | 18 ++++---- .../repository/CustomSettingRepositoryImpl.kt | 41 +++++++++++-------- .../setting/presentation/SettingController.kt | 37 +++++++---------- 9 files changed, 85 insertions(+), 90 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 de979c14..3268d3aa 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,7 +4,6 @@ import io.github.v1servicenotification.category.api.response.CategoryListRespons import java.util.UUID interface SettingApi { - fun activateCategory(categoryId: UUID, userId: UUID): Int - fun deActivateCategory(categoryId: UUID, userId: UUID): Int + fun activateCategory(isActivate: Boolean, topic: String, userId: UUID): Int fun queryActivatedCategory(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 c1bd1f5c..d35ce852 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 @@ -12,26 +12,18 @@ import java.util.UUID class SettingApiImpl( private val settingRepositorySpi: SettingRepositorySpi, private val settingCategorySpi: SettingCategorySpi -): SettingApi { +) : SettingApi { - override fun activateCategory(categoryId: UUID, userId: UUID): Int { + override fun activateCategory(isActivate: Boolean, topic: String, userId: UUID): Int { return saveOrUpdateSetting( - categoryId = categoryId, + isActivate = isActivate, + topic = topic, userId = userId, - isActivate = true - ) - } - - override fun deActivateCategory(categoryId: UUID, userId: UUID): Int { - return saveOrUpdateSetting( - categoryId = categoryId, - userId = userId, - isActivate = false - ) + ) } - private fun saveOrUpdateSetting(categoryId: UUID, userId: UUID, isActivate: Boolean): Int { - val category = settingCategorySpi.findById(categoryId) + private fun saveOrUpdateSetting(isActivate: Boolean, topic: String, userId: UUID): Int { + val category = settingCategorySpi.findByStartingWithTopic(topic) return if (settingRepositorySpi.settingExist(category, userId)) { settingRepositorySpi.updateSetting(category, userId, isActivate) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt index 3340078f..6c7e05ba 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt @@ -1,8 +1,7 @@ package io.github.v1servicenotification.setting.spi import io.github.v1servicenotification.category.Category -import java.util.UUID interface SettingCategorySpi { - fun findById(id: UUID): Category + fun findByStartingWithTopic(topic: String): List } 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 fda7c572..d29827f7 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,8 +7,8 @@ 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 saveSetting(categories: List, userId: UUID, isActivated: Boolean): List + fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List + fun settingExist(categories: List, userId: UUID): Boolean fun queryActivatedCategory(userId: UUID): List } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt index f03bcbf2..66f6531d 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt @@ -34,14 +34,15 @@ class InMemoryCategoryRepository( ?: throw CategoryNotFoundException.EXCEPTION } - override fun findById(id: UUID): Category { - return categoryMap[id] - ?: throw CategoryNotFoundException.EXCEPTION - } - override fun findAllByDefaultActivated(defaultActivated: Boolean): List { return categoryMap.filter { it.value.defaultActivated == defaultActivated }.map { it.value } } + + override fun findByStartingWithTopic(topic: String): List { + return categoryMap.values.filter { + it.topic.startsWith(topic) + } + } } 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 12384cc1..c11737e9 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 @@ -21,25 +21,29 @@ class InMemorySettingRepository( .map { it.value }.firstOrNull() } - override fun saveSetting(category: Category, userId: UUID, isActivated: Boolean): Setting { - val setting = Setting(userId, category.id, isActivated) - settingMap[UUID.randomUUID()] = setting - - return setting + override fun saveSetting(categories: List, userId: UUID, isActivated: Boolean): List { + return categories.map { + val setting = Setting( + userId = userId, + notificationCategoryId = it.id, + isActivated = isActivated + ) + settingMap[setting.notificationCategoryId] = setting + setting + } } - override fun updateSetting(category: Category, userId: UUID, isActivated: Boolean): Setting { - return settingMap.filter { - it.value.notificationCategoryId == category.id && it.value.userId == userId - }.map { - it.value.changeIsActivate(isActivated) - it.value - }[0] + override fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List { + return categories.map { + val setting = findSetting(userId, it.id) + setting?.changeIsActivate(isActivated) + setting + }.filterNotNull() } - override fun settingExist(category: Category, userId: UUID): Boolean { - return settingMap.filter { - it.value.notificationCategoryId == category.id && it.value.userId == userId + override fun settingExist(categories: List, userId: UUID): Boolean { + return categories.mapNotNull { + findSetting(userId, it.id) }.isNotEmpty() } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt index 3fb65fdb..5cf6187e 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt @@ -1,8 +1,10 @@ package io.github.v1servicenotification.domain.category.domain.repository +import com.querydsl.jpa.impl.JPAQueryFactory import io.github.v1servicenotification.category.Category import io.github.v1servicenotification.category.spi.QueryCategoryRepositorySpi import io.github.v1servicenotification.category.spi.UpdateCategoryRepositorySpi +import io.github.v1servicenotification.domain.category.domain.QCategoryEntity.categoryEntity import io.github.v1servicenotification.domain.category.exception.CategoryNotFoundException import io.github.v1servicenotification.domain.category.mapper.CategoryMapper import io.github.v1servicenotification.global.extension.findOne @@ -13,7 +15,8 @@ import java.util.UUID @Repository class CustomCategoryRepositoryImpl( private val categoryMapper: CategoryMapper, - private val categoryRepository: CategoryRepository + private val categoryRepository: CategoryRepository, + private val jpaQueryFactory: JPAQueryFactory, ) : UpdateCategoryRepositorySpi, QueryCategoryRepositorySpi, SettingCategorySpi { override fun saveCategory(category: Category) { @@ -40,13 +43,14 @@ class CustomCategoryRepositoryImpl( return categoryMapper.categoryEntityToDomain(category) } - override fun findById(id: UUID): Category { - val category = categoryRepository.findById(id) - .orElseThrow { - CategoryNotFoundException.EXCEPTION + override fun findByStartingWithTopic(topic: String): List { + return jpaQueryFactory + .selectFrom(categoryEntity) + .where(categoryEntity.topic.startsWith(topic)) + .fetch() + .map { + categoryMapper.categoryEntityToDomain(it) } - - return categoryMapper.categoryEntityToDomain(category) } override fun findAllByDefaultActivated(defaultActivated: Boolean): List { 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 1a6e62e4..846ebf63 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 @@ -21,30 +21,33 @@ class CustomSettingRepositoryImpl( private val categoryMapper: CategoryMapper, private val jpaQueryFactory: JPAQueryFactory ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { - override fun saveSetting(category: Category, userId: UUID, isActivated: Boolean): Setting { - return settingMapper.settingEntityToDomain( - settingRepository.save( - SettingEntity( - settingId = getSettingId(category, userId), - isActivated = isActivated - ) - ) - ) + override fun saveSetting(categories: List, userId: UUID, isActivated: Boolean): List { + return getSettingIdList(categories, userId).map { + saveSettingId(it, isActivated) + } + } + + override fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List { + return getSettingIdList(categories, userId).map { + saveSettingId(it, isActivated) + } } - override fun updateSetting(category: Category, userId: UUID, isActivated: Boolean): Setting { + private fun saveSettingId(settingId: SettingId, isActivated: Boolean): Setting { return settingMapper.settingEntityToDomain( settingRepository.save( SettingEntity( - settingId = getSettingId(category, userId), + settingId = settingId, isActivated = isActivated ) ) ) } - override fun settingExist(category: Category, userId: UUID): Boolean { - return settingRepository.existsById(getSettingId(category, userId)) + override fun settingExist(categories: List, userId: UUID): Boolean { + return getSettingIdList(categories, userId).map { settingId -> + settingRepository.existsById(settingId) + }.all { it } } override fun queryActivatedCategory(userId: UUID): List { @@ -66,11 +69,13 @@ class CustomSettingRepositoryImpl( } } - private fun getSettingId(category: Category, userId: UUID): SettingId { - return SettingId( - userId = userId, - categoryEntity = categoryMapper.categoryDomainToEntity(category) - ) + private fun getSettingIdList(categories: List, userId: UUID): List { + return categories.map { category -> + SettingId( + userId = userId, + categoryEntity = categoryMapper.categoryDomainToEntity(category) + ) + } } override fun findAllUserIdByTopicAndIsActivated(topic: String, isActivated: Boolean): List { 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 fa0d773c..efe438c1 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 @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.DeleteMapping +import org.springframework.web.bind.annotation.RequestParam import java.util.UUID @Tag(name = "알림 카테고리 활성화 설정", description = "알림 카테고리 활성화 관련 Api 입니다.") @@ -33,31 +34,21 @@ class SettingController( } @Operation(summary = "알림 카테고리 활성화") - @ApiResponses(value = [ - ApiResponse(responseCode = CustomHttpStatus.CREATED), - ApiResponse(responseCode = CustomHttpStatus.NO_CONTENT) - ]) - @PatchMapping("/{category-uuid}") - fun activateNotificationCategory(@PathVariable("category-uuid") categoryId: UUID): ResponseEntity { + @ApiResponses( + value = [ + ApiResponse(responseCode = CustomHttpStatus.CREATED), + ApiResponse(responseCode = CustomHttpStatus.NO_CONTENT) + ] + ) + @PatchMapping + fun activateNotificationCategory( + @RequestParam("is-activate") isActivate: Boolean, + @RequestParam("topic") topic: String + ): ResponseEntity { return ResponseEntity( HttpStatus.valueOf( - settingApi.activateCategory(categoryId, getUserId()) + settingApi.activateCategory(isActivate, topic, getUserId()) ) ) } - - @Operation(summary = "알림 카테고리 비활성회") - @ApiResponses(value = [ - ApiResponse(responseCode = CustomHttpStatus.CREATED), - ApiResponse(responseCode = CustomHttpStatus.NO_CONTENT) - ]) - @DeleteMapping("/{category-uuid}") - fun deActivateNotificationCategory(@PathVariable("category-uuid") categoryId: UUID): ResponseEntity { - return ResponseEntity( - HttpStatus.valueOf( - settingApi.deActivateCategory(categoryId, getUserId()) - ) - ) - } - -} \ No newline at end of file +} From e23880cd0fc4b9e21a38a6708e8abe4f8759c7b8 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 21:21:48 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=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 | 4 ++-- .../setting/spi/SettingRepositorySpi.kt | 4 ++-- .../stubs/InMemorySettingRepository.kt | 4 ++-- .../v1servicenotification/detail/DetailApiImplTest.kt | 6 +++--- .../setting/SettingApiImplTest.kt | 2 +- .../domain/repository/CustomSettingRepositoryImpl.kt | 10 +++++----- 6 files changed, 15 insertions(+), 15 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 d35ce852..bf372964 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 @@ -26,10 +26,10 @@ class SettingApiImpl( val category = settingCategorySpi.findByStartingWithTopic(topic) return if (settingRepositorySpi.settingExist(category, userId)) { - settingRepositorySpi.updateSetting(category, userId, isActivate) + settingRepositorySpi.updateAllSetting(category, userId, isActivate) 204 } else { - settingRepositorySpi.saveSetting(category, userId, isActivate) + settingRepositorySpi.saveAllSetting(category, userId, isActivate) 201 } } 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 d29827f7..735b4cfd 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,8 +7,8 @@ import java.util.UUID @Spi interface SettingRepositorySpi { - fun saveSetting(categories: List, userId: UUID, isActivated: Boolean): List - fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List + fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List + fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List fun settingExist(categories: 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 c11737e9..1a7703d4 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 @@ -21,7 +21,7 @@ class InMemorySettingRepository( .map { it.value }.firstOrNull() } - override fun saveSetting(categories: List, userId: UUID, isActivated: Boolean): List { + override fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { return categories.map { val setting = Setting( userId = userId, @@ -33,7 +33,7 @@ class InMemorySettingRepository( } } - override fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List { + override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { return categories.map { val setting = findSetting(userId, it.id) setting?.changeIsActivate(isActivated) diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt index 2c3c6f41..f5ea51b6 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt @@ -69,7 +69,7 @@ class DetailApiImplTest { categorySpi.saveCategory(category) - settingSpi.saveSetting(category, userId, true) + settingSpi.saveAllSetting(category, userId, true) detailSpi.save(category) @@ -104,7 +104,7 @@ class DetailApiImplTest { categorySpi.saveCategory(category) - settingSpi.saveSetting(category, userId, false) + settingSpi.saveAllSetting(category, userId, false) detailSpi.save(category) @@ -137,7 +137,7 @@ class DetailApiImplTest { categorySpi.saveCategory(category) - settingSpi.saveSetting(category, userId, false) + settingSpi.saveAllSetting(category, userId, false) detailSpi.save(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 98eba945..b26ec5d5 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 @@ -26,7 +26,7 @@ class SettingApiImplTest { settingSpi.saveCategory(category) - settingSpi.saveSetting( + settingSpi.saveAllSetting( category, userId, true 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 846ebf63..5ca91b20 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 @@ -21,19 +21,19 @@ class CustomSettingRepositoryImpl( private val categoryMapper: CategoryMapper, private val jpaQueryFactory: JPAQueryFactory ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { - override fun saveSetting(categories: List, userId: UUID, isActivated: Boolean): List { + override fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { return getSettingIdList(categories, userId).map { - saveSettingId(it, isActivated) + updateIsActiveById(it, isActivated) } } - override fun updateSetting(categories: List, userId: UUID, isActivated: Boolean): List { + override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { return getSettingIdList(categories, userId).map { - saveSettingId(it, isActivated) + updateIsActiveById(it, isActivated) } } - private fun saveSettingId(settingId: SettingId, isActivated: Boolean): Setting { + private fun updateIsActiveById(settingId: SettingId, isActivated: Boolean): Setting { return settingMapper.settingEntityToDomain( settingRepository.save( SettingEntity( From d0a1ffecad802664381420c686b46106f1ace5d1 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Sun, 21 May 2023 22:33:06 +0900 Subject: [PATCH 3/7] =?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=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/CustomSettingRepositoryImpl.kt | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) 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 5ca91b20..f9931b83 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 @@ -21,27 +21,28 @@ class CustomSettingRepositoryImpl( private val categoryMapper: CategoryMapper, private val jpaQueryFactory: JPAQueryFactory ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { + override fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - return getSettingIdList(categories, userId).map { - updateIsActiveById(it, isActivated) + val settingEntities = categories.map { category -> + SettingEntity( + settingId = SettingId(userId, categoryMapper.categoryDomainToEntity(category)), + isActivated = isActivated + ) } + val savedSettingEntities = settingRepository.saveAll(settingEntities) + return savedSettingEntities.map { settingMapper.settingEntityToDomain(it) } } - override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - return getSettingIdList(categories, userId).map { - updateIsActiveById(it, isActivated) - } - } - private fun updateIsActiveById(settingId: SettingId, isActivated: Boolean): Setting { - return settingMapper.settingEntityToDomain( - settingRepository.save( - SettingEntity( - settingId = settingId, - isActivated = isActivated - ) + override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { + val settingEntities = categories.map { category -> + SettingEntity( + settingId = SettingId(userId, categoryMapper.categoryDomainToEntity(category)), + isActivated = isActivated ) - ) + } + val savedSettingEntities = settingRepository.saveAll(settingEntities) + return savedSettingEntities.map { settingMapper.settingEntityToDomain(it) } } override fun settingExist(categories: List, userId: UUID): Boolean { @@ -50,6 +51,15 @@ class CustomSettingRepositoryImpl( }.all { it } } + private fun getSettingIdList(categories: List, userId: UUID): List { + return categories.map { category -> + SettingId( + userId = userId, + categoryEntity = categoryMapper.categoryDomainToEntity(category) + ) + } + } + override fun queryActivatedCategory(userId: UUID): List { return jpaQueryFactory .select(categoryEntity) @@ -69,15 +79,6 @@ class CustomSettingRepositoryImpl( } } - private fun getSettingIdList(categories: List, userId: UUID): List { - return categories.map { category -> - SettingId( - userId = userId, - categoryEntity = categoryMapper.categoryDomainToEntity(category) - ) - } - } - override fun findAllUserIdByTopicAndIsActivated(topic: String, isActivated: Boolean): List { return jpaQueryFactory .select(settingEntity.settingId.userId) From 273727e7f1389f3917d27289c226d5a9b6256576 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 21:24:54 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=93=91=20::=20SettingNotFoundExceptio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/v1servicenotification/error/ErrorCode.kt | 4 +++- .../setting/exception/SettingNotFoundException.kt | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/exception/SettingNotFoundException.kt diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt index 03ec9d7e..dc9d7d61 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/error/ErrorCode.kt @@ -22,5 +22,7 @@ enum class ErrorCode( INTERNAL_SERVER_ERROR(500, "GLOBAL-500-1", "Internal Server Error."), - DEVICE_TOKEN_LENGTH(401, "DEVICE-400-1", "Device Token Length Error.") + DEVICE_TOKEN_LENGTH(401, "DEVICE-400-1", "Device Token Length Error."), + + SETTING_NOT_FOUND(404, "SETTING-404-1", "Setting Not Found.") } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/exception/SettingNotFoundException.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/exception/SettingNotFoundException.kt new file mode 100644 index 00000000..c352b791 --- /dev/null +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/exception/SettingNotFoundException.kt @@ -0,0 +1,11 @@ +package io.github.v1servicenotification.setting.exception + +import io.github.v1servicenotification.error.ErrorCode +import io.github.v1servicenotification.error.NotificationException + +class SettingNotFoundException private constructor(): NotificationException(ErrorCode.CATEGORY_NOT_FOUND) { + companion object { + @JvmField + val EXCEPTION = SettingNotFoundException() + } +} From 214544ac6ce07bcdadb76cb1882bfad9c67bf134 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Mon, 22 May 2023 21:25:31 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20save=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/api/SettingApi.kt | 2 +- .../setting/service/SettingApiImpl.kt | 20 ++----- .../setting/spi/SettingCategorySpi.kt | 3 +- .../setting/spi/SettingRepositorySpi.kt | 6 +- .../stubs/InMemoryCategoryRepository.kt | 8 ++- .../stubs/InMemorySettingRepository.kt | 38 ++++-------- .../setting/SettingApiImplTest.kt | 4 +- .../CustomCategoryRepositoryImpl.kt | 9 ++- .../repository/CustomSettingRepositoryImpl.kt | 59 +++++++++++-------- .../setting/presentation/SettingController.kt | 27 ++------- 10 files changed, 73 insertions(+), 103 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 3268d3aa..db21a695 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,6 +4,6 @@ import io.github.v1servicenotification.category.api.response.CategoryListRespons import java.util.UUID interface SettingApi { - fun activateCategory(isActivate: Boolean, topic: String, userId: UUID): Int + fun activateOrDeActivateCategory(isActivate: Boolean, topic: String, userId: UUID) fun queryActivatedCategory(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 bf372964..b92c2393 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,7 @@ 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.exception.SettingNotFoundException import io.github.v1servicenotification.setting.spi.SettingCategorySpi import java.util.UUID @@ -14,24 +15,13 @@ class SettingApiImpl( private val settingCategorySpi: SettingCategorySpi ) : SettingApi { - override fun activateCategory(isActivate: Boolean, topic: String, userId: UUID): Int { - return saveOrUpdateSetting( - isActivate = isActivate, - topic = topic, - userId = userId, - ) - } - - private fun saveOrUpdateSetting(isActivate: Boolean, topic: String, userId: UUID): Int { + override fun activateOrDeActivateCategory(isActivate: Boolean, topic: String, userId: UUID) { val category = settingCategorySpi.findByStartingWithTopic(topic) - return if (settingRepositorySpi.settingExist(category, userId)) { - settingRepositorySpi.updateAllSetting(category, userId, isActivate) - 204 - } else { - settingRepositorySpi.saveAllSetting(category, userId, isActivate) - 201 + if (!settingRepositorySpi.settingExist(category, userId)) { + throw SettingNotFoundException.EXCEPTION } + settingRepositorySpi.updateAllSetting(category, userId, isActivate) } override fun queryActivatedCategory(userId: UUID): CategoryListResponse { diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt index 6c7e05ba..91ebbabf 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt @@ -1,7 +1,8 @@ package io.github.v1servicenotification.setting.spi import io.github.v1servicenotification.category.Category +import java.util.* interface SettingCategorySpi { - fun findByStartingWithTopic(topic: String): List + fun findByStartingWithTopic(topic: String): List } 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 735b4cfd..6dff788d 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,13 +2,11 @@ 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 saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List - fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List - fun settingExist(categories: List, userId: UUID): Boolean + 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/InMemoryCategoryRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt index 66f6531d..c8825a3c 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryCategoryRepository.kt @@ -40,9 +40,11 @@ class InMemoryCategoryRepository( }.map { it.value } } - override fun findByStartingWithTopic(topic: String): List { - return categoryMap.values.filter { - it.topic.startsWith(topic) + override fun findByStartingWithTopic(topic: String): List { + return categoryMap.filter { + it.value.topic.startsWith(topic) + }.map { + it.key } } } 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 1a7703d4..4556c093 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 @@ -15,35 +15,17 @@ class InMemorySettingRepository( categoryMap[category.id] = category } - fun findSetting(userId: UUID, categoryId: UUID): Setting? { - return settingMap - .filter { it.value.userId == userId && it.value.notificationCategoryId == categoryId } - .map { it.value }.firstOrNull() - } - - override fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - return categories.map { - val setting = Setting( - userId = userId, - notificationCategoryId = it.id, - isActivated = isActivated - ) - settingMap[setting.notificationCategoryId] = setting - setting - } - } - override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - return categories.map { - val setting = findSetting(userId, it.id) + override fun updateAllSetting(categoryIds: List, userId: UUID, isActivated: Boolean) { + categoryIds.forEach { + val setting = findSetting(userId, it) setting?.changeIsActivate(isActivated) - setting - }.filterNotNull() + } } - override fun settingExist(categories: List, userId: UUID): Boolean { - return categories.mapNotNull { - findSetting(userId, it.id) + override fun settingExist(categoryIds: List, userId: UUID): Boolean { + return categoryIds.mapNotNull { + findSetting(userId, it) }.isNotEmpty() } @@ -54,6 +36,12 @@ class InMemorySettingRepository( }.map { it.value } } + private fun findSetting(userId: UUID, categoryId: UUID): Setting? { + return settingMap + .filter { it.value.userId == userId && it.value.notificationCategoryId == categoryId } + .map { it.value }.firstOrNull() + } + override fun findAllUserIdByTopicAndIsActivated(topic: String, isActivated: Boolean): List { return settingMap.values.filter { it.isActivated == isActivated && categoryMap[it.notificationCategoryId]?.topic == topic 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 b26ec5d5..97db4721 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 @@ -60,9 +60,9 @@ class SettingApiImplTest { categorySpi.saveCategory( Category(categoryId, "Test name", "Test destination", false, "ALL") ) - assertThat(settingApi.activateCategory(categoryId, userId)) + assertThat(settingApi.activateOrDeActivateCategory(categoryId, userId)) .isEqualTo(201) - assertThat(settingApi.activateCategory(categoryId, userId)) + assertThat(settingApi.activateOrDeActivateCategory(categoryId, userId)) .isEqualTo(204) } } diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt index 5cf6187e..6e496508 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/category/domain/repository/CustomCategoryRepositoryImpl.kt @@ -43,14 +43,13 @@ class CustomCategoryRepositoryImpl( return categoryMapper.categoryEntityToDomain(category) } - override fun findByStartingWithTopic(topic: String): List { + override fun findByStartingWithTopic(topic: String): List { return jpaQueryFactory - .selectFrom(categoryEntity) + .select(categoryEntity.id) + .from(categoryEntity) .where(categoryEntity.topic.startsWith(topic)) .fetch() - .map { - categoryMapper.categoryEntityToDomain(it) - } + } override fun findAllByDefaultActivated(defaultActivated: Boolean): List { 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 f9931b83..ba16d9f3 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 @@ -4,55 +4,57 @@ 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.QCategoryEntity.categoryEntity +import io.github.v1servicenotification.domain.category.domain.repository.CategoryRepository import io.github.v1servicenotification.domain.category.mapper.CategoryMapper import io.github.v1servicenotification.domain.setting.domain.QSettingEntity.settingEntity -import io.github.v1servicenotification.domain.setting.domain.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 +import javax.transaction.Transactional @Repository class CustomSettingRepositoryImpl( private val settingRepository: SettingRepository, - private val settingMapper: SettingMapper, private val categoryMapper: CategoryMapper, - private val jpaQueryFactory: JPAQueryFactory + private val jpaQueryFactory: JPAQueryFactory, + private val categoryRepository: CategoryRepository, ) : SettingRepositorySpi, PostDetailSettingRepositorySpi { - override fun saveAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - val settingEntities = categories.map { category -> - SettingEntity( - settingId = SettingId(userId, categoryMapper.categoryDomainToEntity(category)), - isActivated = isActivated - ) + @Transactional + override fun updateAllSetting(categoryIds: List, userId: UUID, isActivated: Boolean) { + categoryIds.forEach { + jpaQueryFactory + .update(settingEntity) + .set(settingEntity.isActivated, isActivated) + .where( + settingEntity.settingId.categoryEntity.id.eq(it) + .and(settingEntity.settingId.userId.eq(userId)) + ) + .execute() } - val savedSettingEntities = settingRepository.saveAll(settingEntities) - return savedSettingEntities.map { settingMapper.settingEntityToDomain(it) } } - - override fun updateAllSetting(categories: List, userId: UUID, isActivated: Boolean): List { - val settingEntities = categories.map { category -> - SettingEntity( - settingId = SettingId(userId, categoryMapper.categoryDomainToEntity(category)), - isActivated = isActivated - ) + private fun setSettingIsActivate(categoryIds: List, userId: UUID, isActivated: Boolean) { + categoryIds.forEach { + jpaQueryFactory + .update(settingEntity) + .set(settingEntity.isActivated, isActivated) + .where( + settingEntity.settingId.categoryEntity.id.eq(it) + .and(settingEntity.settingId.userId.eq(userId)) + ) } - val savedSettingEntities = settingRepository.saveAll(settingEntities) - return savedSettingEntities.map { settingMapper.settingEntityToDomain(it) } } - override fun settingExist(categories: List, userId: UUID): Boolean { - return getSettingIdList(categories, userId).map { settingId -> + override fun settingExist(categoryIds: List, userId: UUID): Boolean { + return getSettingIdList(categoryIds, userId).map { settingId -> settingRepository.existsById(settingId) }.all { it } } - private fun getSettingIdList(categories: List, userId: UUID): List { - return categories.map { category -> + private fun getSettingIdList(categoryIds: List, userId: UUID): List { + return getCategoryById(categoryIds).map { category -> SettingId( userId = userId, categoryEntity = categoryMapper.categoryDomainToEntity(category) @@ -60,6 +62,11 @@ class CustomSettingRepositoryImpl( } } + private fun getCategoryById(categoryId: List): List { + return categoryRepository.findAllById(categoryId) + .map { categoryMapper.categoryEntityToDomain(it) } + } + override fun queryActivatedCategory(userId: UUID): List { return jpaQueryFactory .select(categoryEntity) 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 efe438c1..60c59f53 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 @@ -2,23 +2,17 @@ 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.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.responses.ApiResponse -import io.swagger.v3.oas.annotations.responses.ApiResponses import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.RequestParam -import java.util.UUID @Tag(name = "알림 카테고리 활성화 설정", description = "알림 카테고리 활성화 관련 Api 입니다.") @RequestMapping("/tags") @@ -33,22 +27,13 @@ class SettingController( return settingApi.queryActivatedCategory(getUserId()) } - @Operation(summary = "알림 카테고리 활성화") - @ApiResponses( - value = [ - ApiResponse(responseCode = CustomHttpStatus.CREATED), - ApiResponse(responseCode = CustomHttpStatus.NO_CONTENT) - ] - ) + @Operation(summary = "알림 카테고리 활성화 / 비활성화") + @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping fun activateNotificationCategory( - @RequestParam("is-activate") isActivate: Boolean, + @RequestParam("is-activated") isActivate: Boolean, @RequestParam("topic") topic: String - ): ResponseEntity { - return ResponseEntity( - HttpStatus.valueOf( - settingApi.activateCategory(isActivate, topic, getUserId()) - ) - ) + ) { + settingApi.activateOrDeActivateCategory(isActivate, topic, getUserId()) } } From e79f76c045ca2a7101275582addd743c91b46970 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 13:44:33 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20Test=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stubs/InMemorySettingRepository.kt | 4 +-- .../detail/DetailApiImplTest.kt | 12 +++++-- .../setting/SettingApiImplTest.kt | 33 +++---------------- 3 files changed, 15 insertions(+), 34 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 4556c093..69d8afab 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,9 +24,7 @@ class InMemorySettingRepository( } override fun settingExist(categoryIds: List, userId: UUID): Boolean { - return categoryIds.mapNotNull { - findSetting(userId, it) - }.isNotEmpty() + return categoryIds.map { findSetting(userId, it) }.any { it != null } } override fun queryActivatedCategory(userId: UUID): List { diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt index f5ea51b6..c465bc40 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt @@ -67,9 +67,11 @@ class DetailApiImplTest { topic = "ALL" ) + val categoryIds = listOf(category.id) + categorySpi.saveCategory(category) - settingSpi.saveAllSetting(category, userId, true) + settingSpi.updateAllSetting(categoryIds, userId, true) detailSpi.save(category) @@ -102,9 +104,11 @@ class DetailApiImplTest { topic = "ALL" ) + val categoryIds = listOf(category.id) + categorySpi.saveCategory(category) - settingSpi.saveAllSetting(category, userId, false) + settingSpi.updateAllSetting(categoryIds, userId, false) detailSpi.save(category) @@ -135,9 +139,11 @@ class DetailApiImplTest { topic = "ALL" ) + val categoryIds = listOf(category.id) + categorySpi.saveCategory(category) - settingSpi.saveAllSetting(category, userId, false) + settingSpi.updateAllSetting(categoryIds, userId, false) detailSpi.save(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 97db4721..3a144184 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 @@ -26,8 +26,11 @@ class SettingApiImplTest { settingSpi.saveCategory(category) - settingSpi.saveAllSetting( - category, + val categoryIds = listOf(category.id) + + + settingSpi.updateAllSetting( + categoryIds, userId, true ) @@ -39,30 +42,4 @@ class SettingApiImplTest { assertThat(result.destination).isEqualTo(category.destination) } - - @Test - fun deActivatedCategory() { - val userId = UUID.randomUUID() - val categoryId = UUID.randomUUID() - categorySpi.saveCategory( - Category(categoryId, "Test name", "Test destination", false, "ALL") - ) - Assertions.assertThat(settingApi.deActivateCategory(categoryId, userId)) - .isEqualTo(201) - Assertions.assertThat(settingApi.deActivateCategory(categoryId, userId)) - .isEqualTo(204) - } - - @Test - fun activateCategory() { - val userId = UUID.randomUUID() - val categoryId = UUID.randomUUID() - categorySpi.saveCategory( - Category(categoryId, "Test name", "Test destination", false, "ALL") - ) - assertThat(settingApi.activateOrDeActivateCategory(categoryId, userId)) - .isEqualTo(201) - assertThat(settingApi.activateOrDeActivateCategory(categoryId, userId)) - .isEqualTo(204) - } } From e00ac46b3484838329aa92a94ee318f3ea886a57 Mon Sep 17 00:00:00 2001 From: lyutvs Date: Wed, 24 May 2023 13:47:02 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20code=20smell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../setting/spi/SettingCategorySpi.kt | 1 - .../domain/repository/CustomSettingRepositoryImpl.kt | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt index 91ebbabf..7fef1258 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/setting/spi/SettingCategorySpi.kt @@ -1,6 +1,5 @@ package io.github.v1servicenotification.setting.spi -import io.github.v1servicenotification.category.Category import java.util.* interface SettingCategorySpi { 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 ba16d9f3..f91ea1d1 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 @@ -35,18 +35,6 @@ class CustomSettingRepositoryImpl( } } - private fun setSettingIsActivate(categoryIds: List, userId: UUID, isActivated: Boolean) { - categoryIds.forEach { - jpaQueryFactory - .update(settingEntity) - .set(settingEntity.isActivated, isActivated) - .where( - settingEntity.settingId.categoryEntity.id.eq(it) - .and(settingEntity.settingId.userId.eq(userId)) - ) - } - } - override fun settingExist(categoryIds: List, userId: UUID): Boolean { return getSettingIdList(categoryIds, userId).map { settingId -> settingRepository.existsById(settingId)