Skip to content

Commit

Permalink
⚡️:: Response에 맞게 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
lyutvs committed May 21, 2023
1 parent 1b106dc commit fcec085
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Category>
fun queryUserIdSetting(userId: UUID): List<Setting>
fun queryUserCategory(userId: UUID): List<Category>
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,14 @@ class InMemorySettingRepository(
}.isNotEmpty()
}

override fun queryActivatedCategory(userId: UUID): List<Category> {
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<UUID> {
return settingMap.values.filter {
it.isActivated == isActivated && categoryMap[it.notificationCategoryId]?.topic == topic
}.map { it.userId }
}

override fun queryUserIdSetting(userId: UUID): List<Setting> {
return settingMap.filter { it.value.userId == userId }.map { it.value }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,19 +48,21 @@ class CustomSettingRepositoryImpl(
return settingRepository.existsById(getSettingId(category, userId))
}

override fun queryActivatedCategory(userId: UUID): List<Category> {

override fun queryUserIdSetting(userId: UUID): List<Setting> {
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<Category> {
return jpaQueryFactory
.selectFrom(categoryEntity)
.where(categoryEntity.eq(settingEntity.settingId.categoryEntity))
.fetch()
.map {
categoryMapper.categoryEntityToDomain(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "알림 카테고리 활성화")
Expand Down

0 comments on commit fcec085

Please sign in to comment.