Skip to content

Commit

Permalink
[feat #96] 포킷 목록 조회 시 생성일 필드 추가 (#97)
Browse files Browse the repository at this point in the history
* fix : Cotent dto 관련 오류 수정

* feat : 포킷 목록 조회 시 createdAt 필드 추가
  • Loading branch information
dlswns2480 authored Aug 16, 2024
1 parent 3e9af52 commit 0de1f90
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,7 +51,7 @@ class CategoryController(
direction = Sort.Direction.DESC
) pageable: Pageable,
@RequestParam(defaultValue = "true") filterUncategorized: Boolean
): ResponseEntity<SliceResponseDto<Category>> =
): ResponseEntity<SliceResponseDto<CategoriesResponse>> =
categoryUseCase.getCategories(user.id, pageable, filterUncategorized)
.wrapSlice()
.wrapOk()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ fun CategoryEntity.toDomain() = Category(
categoryName = this.name,
categoryImage = this.image.toDomain(),
userId = this.userId,
createdAt = this.createdAt
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +13,6 @@ interface CategoryUseCase {
fun delete(categoryId: Long, userId: Long)
fun getTotalCount(userId: Long): Int
fun getAllCategoryImages(): List<CategoryImage>
fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice<Category>
fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice<CategoriesResponse>
fun getCategory(userId: Long, categoryId: Long): Category
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Category> {
override fun getCategories(userId: Long, pageable: Pageable, filterUncategorized: Boolean): Slice<CategoriesResponse> {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RemindContentResult> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
)
}
3 changes: 3 additions & 0 deletions domain/src/main/kotlin/com/pokit/category/model/Category.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 0de1f90

Please sign in to comment.