diff --git a/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryController.kt b/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryController.kt index 0f7c2664..e2e1464a 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryController.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/category/CategoryController.kt @@ -2,13 +2,13 @@ package com.pokit.category import com.pokit.auth.config.ErrorOperation import com.pokit.auth.model.PrincipalUser +import com.pokit.category.dto.CategoriesResponse import com.pokit.category.dto.request.CreateCategoryRequest import com.pokit.category.dto.request.toDto import com.pokit.category.dto.response.CategoryCountResponse import com.pokit.category.dto.response.CategoryResponse import com.pokit.category.dto.response.toResponse import com.pokit.category.exception.CategoryErrorCode -import com.pokit.category.model.Category import com.pokit.category.model.CategoryImage import com.pokit.category.port.`in`.CategoryUseCase import com.pokit.common.dto.SliceResponseDto @@ -51,7 +51,7 @@ class CategoryController( direction = Sort.Direction.DESC ) pageable: Pageable, @RequestParam(defaultValue = "true") filterUncategorized: Boolean - ): ResponseEntity> = + ): ResponseEntity> = categoryUseCase.getCategories(user.id, pageable, filterUncategorized) .wrapSlice() .wrapOk() diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryEntity.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryEntity.kt index c6484254..a2aa2bcb 100644 --- a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryEntity.kt +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/category/persist/CategoryEntity.kt @@ -47,4 +47,5 @@ fun CategoryEntity.toDomain() = Category( categoryName = this.name, categoryImage = this.image.toDomain(), userId = this.userId, + createdAt = this.createdAt ) diff --git a/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt b/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt index 4e52d512..97a8e47d 100644 --- a/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt +++ b/application/src/main/kotlin/com/pokit/category/port/in/CategoryUseCase.kt @@ -1,5 +1,6 @@ package com.pokit.category.port.`in` +import com.pokit.category.dto.CategoriesResponse import com.pokit.category.dto.CategoryCommand import com.pokit.category.model.Category import com.pokit.category.model.CategoryImage @@ -12,6 +13,6 @@ interface CategoryUseCase { fun delete(categoryId: Long, userId: Long) fun getTotalCount(userId: Long): Int fun getAllCategoryImages(): List - fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice + fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice fun getCategory(userId: Long, categoryId: Long): Category } diff --git a/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt b/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt index fa9101f0..ea625a32 100644 --- a/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt +++ b/application/src/main/kotlin/com/pokit/category/port/service/CategoryService.kt @@ -1,6 +1,8 @@ package com.pokit.category.port.service +import com.pokit.category.dto.CategoriesResponse import com.pokit.category.dto.CategoryCommand +import com.pokit.category.dto.toCategoriesRespoonse import com.pokit.category.exception.CategoryErrorCode import com.pokit.category.model.Category import com.pokit.category.model.CategoryImage @@ -77,12 +79,13 @@ class CategoryService( override fun getTotalCount(userId: Long): Int = categoryPort.countByUserId(userId) - override fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice { + override fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice { val categoriesSlice = categoryPort.loadAllByUserId(userId, pageable) val categories = categoriesSlice.content.map { category -> val contentCount = contentPort.fetchContentCountByCategoryId(category.categoryId) category.copy(contentCount = contentCount) + category.toCategoriesRespoonse() } val filteredCategories = if (filterUncategorized) { diff --git a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt index c365b279..dac9bf8f 100644 --- a/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt +++ b/application/src/main/kotlin/com/pokit/content/port/service/ContentService.kt @@ -104,7 +104,7 @@ class ContentService( val category = verifyCategory(content.categoryId, userId) val bookmarkStatus = bookMarkPort.isBookmarked(contentId, userId) - return content.toGetContentResponse(bookmarkStatus, category) + return content.toGetContentResult(bookmarkStatus, category) } override fun getBookmarkContents(userId: Long, pageable: Pageable): Slice { diff --git a/domain/src/main/kotlin/com/pokit/category/dto/CategoriesResponse.kt b/domain/src/main/kotlin/com/pokit/category/dto/CategoriesResponse.kt new file mode 100644 index 00000000..30830e38 --- /dev/null +++ b/domain/src/main/kotlin/com/pokit/category/dto/CategoriesResponse.kt @@ -0,0 +1,27 @@ +package com.pokit.category.dto + +import com.pokit.category.model.Category +import com.pokit.category.model.CategoryImage +import java.time.format.DateTimeFormatter + +data class CategoriesResponse( + val categoryId: Long, + val userId: Long, + var categoryName: String, + var categoryImage: CategoryImage, + var contentCount: Int, + val createdAt: String +) + +fun Category.toCategoriesRespoonse(): CategoriesResponse { + val formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd") + + return CategoriesResponse( + categoryId = this.categoryId, + userId = this.userId, + categoryName = this.categoryName, + categoryImage = this.categoryImage, + contentCount = this.contentCount, + createdAt = this.createdAt.format(formatter) + ) +} diff --git a/domain/src/main/kotlin/com/pokit/category/model/Category.kt b/domain/src/main/kotlin/com/pokit/category/model/Category.kt index dd03ca62..b3d24056 100644 --- a/domain/src/main/kotlin/com/pokit/category/model/Category.kt +++ b/domain/src/main/kotlin/com/pokit/category/model/Category.kt @@ -1,11 +1,14 @@ package com.pokit.category.model +import java.time.LocalDateTime + data class Category( val categoryId: Long = 0L, val userId: Long, var categoryName: String, var categoryImage: CategoryImage, var contentCount: Int = 0, + val createdAt: LocalDateTime = LocalDateTime.now() ) { fun update(categoryName: String, categoryImage: CategoryImage) { this.categoryName = categoryName diff --git a/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt b/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt index 2a55a1b2..7fea244c 100644 --- a/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt +++ b/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt @@ -16,7 +16,7 @@ data class GetContentResult( val favorites: Boolean = false ) -fun Content.toGetContentResponse(favorites: Boolean, category: Category): GetContentResult { +fun Content.toGetContentResult(favorites: Boolean, category: Category): GetContentResult { return GetContentResult( contentId = this.id, category = CategoryInfo(category.categoryId, category.categoryName),