Skip to content

Commit

Permalink
fix: 활성화된 카테고리 정보만 제공되도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 26, 2024
1 parent 72d192b commit 2165d25
Showing 5 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -9,10 +9,7 @@ import com.oksusu.susu.common.extension.withMDCContext
import com.oksusu.susu.domain.category.domain.Category
import com.oksusu.susu.domain.category.infrastructure.CategoryRepository
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service

@@ -33,8 +30,9 @@ class CategoryService(
logger.info { "start refresh categories" }

categories = runCatching {
findAllByIsActive(true)
findAll()
.map { category -> CategoryModel.from(category) }
.sortedBy { category -> category.seq }
.associateBy { category -> category.id }
}.onFailure { e ->
logger.resolveCancellation("refreshCategories", e)
@@ -44,14 +42,20 @@ class CategoryService(
}
}

suspend fun getAll(): List<CategoryModel> {
return categories.values.toList()
suspend fun getAllByActive(active: Boolean = true): List<CategoryModel> {
return categories.values
.filter { category -> category.isActive }
.toList()
}

suspend fun findAllByIsActive(isActive: Boolean): List<Category> {
return withMDCContext { categoryRepository.findAllByIsActive(isActive) }
}

suspend fun findAll(): List<Category> {
return withContext(Dispatchers.IO) { categoryRepository.findAll() }
}

fun getCategory(id: Long): CategoryModel {
return categories[id] ?: throw NotFoundException(ErrorCode.NOT_FOUND_CATEGORY_ERROR)
}
Original file line number Diff line number Diff line change
@@ -11,14 +11,17 @@ data class CategoryModel(
val name: String,
/** category style */
val style: String,
/** 활성화 여부 */
val isActive: Boolean,
) {
companion object {
fun from(category: Category): CategoryModel {
return CategoryModel(
id = category.id,
seq = category.seq,
name = category.name,
style = category.style
style = category.style,
isActive = category.isActive
)
}
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RestController
class CategoryResource(
private val categoryService: CategoryService,
) {
@Operation(summary = "카테고리 전체 조회")
@Operation(summary = "카테고리 전체 조회, 활성화된 정보만 제공")
@GetMapping
suspend fun getCategories() = categoryService.getAll().wrapOk()
suspend fun getCategories() = categoryService.getAllByActive().wrapOk()
}
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@ import org.springframework.stereotype.Service
class EnvelopeConfigService(
private val categoryService: CategoryService,
private val relationshipService: RelationshipService,
private val envelopeService: com.oksusu.susu.api.envelope.application.EnvelopeService,
private val envelopeService: EnvelopeService,
) {
suspend fun getCreateEnvelopesConfig(user: AuthUser): CreateEnvelopesConfigResponse {
val categories = categoryService.getAll()
val categories = categoryService.getAllByActive()
val relationships = relationshipService.getAll()

return CreateEnvelopesConfigResponse(categories, relationships)
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import com.oksusu.susu.api.category.model.CategoryModel
import com.oksusu.susu.api.friend.model.RelationshipModel

data class CreateEnvelopesConfigResponse(
/** 카테고리 정보 */
/** 카테고리 정보, 활성화된 정보만 제공 */
val categories: List<CategoryModel>,
/** 관계 정보 */
val relationships: List<RelationshipModel>,

0 comments on commit 2165d25

Please sign in to comment.