diff --git a/api/src/main/kotlin/com/oksusu/susu/api/category/application/CategoryService.kt b/api/src/main/kotlin/com/oksusu/susu/api/category/application/CategoryService.kt index cb6fc98b..1d2a682b 100644 --- a/api/src/main/kotlin/com/oksusu/susu/api/category/application/CategoryService.kt +++ b/api/src/main/kotlin/com/oksusu/susu/api/category/application/CategoryService.kt @@ -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 { - return categories.values.toList() + suspend fun getAllByActive(active: Boolean = true): List { + return categories.values + .filter { category -> category.isActive } + .toList() } suspend fun findAllByIsActive(isActive: Boolean): List { return withMDCContext { categoryRepository.findAllByIsActive(isActive) } } + suspend fun findAll(): List { + return withContext(Dispatchers.IO) { categoryRepository.findAll() } + } + fun getCategory(id: Long): CategoryModel { return categories[id] ?: throw NotFoundException(ErrorCode.NOT_FOUND_CATEGORY_ERROR) } diff --git a/api/src/main/kotlin/com/oksusu/susu/api/category/model/CategoryModel.kt b/api/src/main/kotlin/com/oksusu/susu/api/category/model/CategoryModel.kt index bff0589b..2627d187 100644 --- a/api/src/main/kotlin/com/oksusu/susu/api/category/model/CategoryModel.kt +++ b/api/src/main/kotlin/com/oksusu/susu/api/category/model/CategoryModel.kt @@ -11,6 +11,8 @@ data class CategoryModel( val name: String, /** category style */ val style: String, + /** 활성화 여부 */ + val isActive: Boolean, ) { companion object { fun from(category: Category): CategoryModel { @@ -18,7 +20,8 @@ data class CategoryModel( id = category.id, seq = category.seq, name = category.name, - style = category.style + style = category.style, + isActive = category.isActive ) } } diff --git a/api/src/main/kotlin/com/oksusu/susu/api/category/presentation/CategoryResource.kt b/api/src/main/kotlin/com/oksusu/susu/api/category/presentation/CategoryResource.kt index 4a053aa0..fd827d22 100644 --- a/api/src/main/kotlin/com/oksusu/susu/api/category/presentation/CategoryResource.kt +++ b/api/src/main/kotlin/com/oksusu/susu/api/category/presentation/CategoryResource.kt @@ -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() } diff --git a/api/src/main/kotlin/com/oksusu/susu/api/envelope/application/EnvelopeConfigService.kt b/api/src/main/kotlin/com/oksusu/susu/api/envelope/application/EnvelopeConfigService.kt index 1e3be6f0..3f5d679a 100644 --- a/api/src/main/kotlin/com/oksusu/susu/api/envelope/application/EnvelopeConfigService.kt +++ b/api/src/main/kotlin/com/oksusu/susu/api/envelope/application/EnvelopeConfigService.kt @@ -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) diff --git a/api/src/main/kotlin/com/oksusu/susu/api/envelope/model/response/CreateEnvelopesConfigResponse.kt b/api/src/main/kotlin/com/oksusu/susu/api/envelope/model/response/CreateEnvelopesConfigResponse.kt index c59486c3..d00c050f 100644 --- a/api/src/main/kotlin/com/oksusu/susu/api/envelope/model/response/CreateEnvelopesConfigResponse.kt +++ b/api/src/main/kotlin/com/oksusu/susu/api/envelope/model/response/CreateEnvelopesConfigResponse.kt @@ -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, /** 관계 정보 */ val relationships: List,