From 3e9af5264d45c00aa48be8bc6f91209476e94447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= <54973090+dlswns2480@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:23:39 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=BB=A8=ED=85=90=EC=B8=A0=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EC=A1=B0=ED=9A=8C=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=EC=97=90=20Category=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pokit/content/ContentController.kt | 2 +- .../content/dto/response/ContentResponse.kt | 39 +++++++++---- .../pokit/content/port/in/ContentUseCase.kt | 4 +- .../content/port/service/ContentService.kt | 5 +- .../dto/response/GetContentResponse.kt | 55 ------------------- .../content/dto/response/GetContentResult.kt | 30 ++++++++++ 6 files changed, 63 insertions(+), 72 deletions(-) delete mode 100644 domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResponse.kt create mode 100644 domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt diff --git a/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt b/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt index 765ba344..759f559f 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/content/ContentController.kt @@ -142,7 +142,7 @@ class ContentController( fun getContent( @AuthenticationPrincipal user: PrincipalUser, @PathVariable("contentId") contentId: Long - ): ResponseEntity { + ): ResponseEntity { return contentUseCase.getContent(user.id, contentId) .toResponse() .wrapOk() diff --git a/adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/ContentResponse.kt b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/ContentResponse.kt index 06bf3fa4..4c4d0fb7 100644 --- a/adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/ContentResponse.kt +++ b/adapters/in-web/src/main/kotlin/com/pokit/content/dto/response/ContentResponse.kt @@ -1,7 +1,8 @@ package com.pokit.content.dto.response -import com.fasterxml.jackson.annotation.JsonFormat +import com.pokit.content.model.CategoryInfo import com.pokit.content.model.Content +import java.time.format.DateTimeFormatter data class ContentResponse( val contentId: Long, @@ -10,7 +11,17 @@ data class ContentResponse( val title: String, val memo: String, val alertYn: String, - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:") + val createdAt: String, + val favorites: Boolean = false +) + +data class GetContentResponse( + val contentId: Long, + val category: CategoryInfo, + val data: String, + val title: String, + val memo: String, + val alertYn: String, val createdAt: String, val favorites: Boolean = false ) @@ -25,13 +36,17 @@ fun Content.toResponse() = ContentResponse( createdAt = this.createdAt.toString() ) -fun GetContentResponse.toResponse() = ContentResponse( - contentId = this.contentId, - categoryId = this.categoryId, - data = this.data, - title = this.title, - memo = this.memo, - alertYn = this.alertYn, - createdAt = this.createdAt.toString(), - favorites = this.favorites -) +fun GetContentResult.toResponse(): GetContentResponse { + val formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd") + + return GetContentResponse( + contentId = this.contentId, + category = this.category, + data = this.data, + title = this.title, + memo = this.memo, + alertYn = this.alertYn, + createdAt = this.createdAt.format(formatter), + favorites = this.favorites + ) +} diff --git a/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt b/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt index e4151726..abf49116 100644 --- a/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt +++ b/application/src/main/kotlin/com/pokit/content/port/in/ContentUseCase.kt @@ -4,7 +4,7 @@ import com.pokit.content.dto.request.ContentCommand import com.pokit.content.dto.response.ContentsResult import com.pokit.content.dto.request.ContentSearchCondition import com.pokit.content.dto.response.BookMarkContentResponse -import com.pokit.content.dto.response.GetContentResponse +import com.pokit.content.dto.response.GetContentResult import com.pokit.content.dto.response.RemindContentResult import com.pokit.content.model.Content import com.pokit.user.model.User @@ -30,7 +30,7 @@ interface ContentUseCase { fun getContentsByCategoryName(userId: Long, categoryName: String, pageable: Pageable): Slice - fun getContent(userId: Long, contentId: Long): GetContentResponse + fun getContent(userId: Long, contentId: Long): GetContentResult fun getBookmarkContents(userId: Long, pageable: Pageable): Slice 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 1d659b33..c365b279 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 @@ -94,16 +94,17 @@ class ContentService( @Transactional - override fun getContent(userId: Long, contentId: Long): GetContentResponse { + override fun getContent(userId: Long, contentId: Long): GetContentResult { val userLog = UserLog( contentId, userId, LogType.READ ) userLogPort.persist(userLog) // 읽음 처리 val content = verifyContent(userId, contentId) + val category = verifyCategory(content.categoryId, userId) val bookmarkStatus = bookMarkPort.isBookmarked(contentId, userId) - return content.toGetContentResponse(bookmarkStatus) + return content.toGetContentResponse(bookmarkStatus, category) } override fun getBookmarkContents(userId: Long, pageable: Pageable): Slice { diff --git a/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResponse.kt b/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResponse.kt deleted file mode 100644 index 0970cf76..00000000 --- a/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResponse.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.pokit.content.dto.response - -import com.pokit.bookmark.model.Bookmark -import com.pokit.content.model.Content -import java.time.LocalDateTime - -data class GetContentResponse( - val contentId: Long, - val categoryId: Long, - val data: String, - val title: String, - val memo: String, - val alertYn: String, - val createdAt: LocalDateTime, - val favorites: Boolean = false -) - -fun Content.toGetContentResponse(bookmark: Bookmark): GetContentResponse { - return GetContentResponse( - contentId = this.id, - categoryId = this.categoryId, - data = this.data, - title = this.title, - memo = this.memo, - alertYn = this.alertYn, - createdAt = this.createdAt, - favorites = true - ) -} - -fun Content.toGetContentResponse(favorites: Boolean): GetContentResponse { - return GetContentResponse( - contentId = this.id, - categoryId = this.categoryId, - data = this.data, - title = this.title, - memo = this.memo, - alertYn = this.alertYn, - createdAt = this.createdAt, - favorites = favorites - ) -} - -fun Content.toGetContentResponse(): GetContentResponse { - return GetContentResponse( - contentId = this.id, - categoryId = this.categoryId, - data = this.data, - title = this.title, - memo = this.memo, - alertYn = this.alertYn, - createdAt = this.createdAt, - favorites = false - ) -} 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 new file mode 100644 index 00000000..2a55a1b2 --- /dev/null +++ b/domain/src/main/kotlin/com/pokit/content/dto/response/GetContentResult.kt @@ -0,0 +1,30 @@ +package com.pokit.content.dto.response + +import com.pokit.category.model.Category +import com.pokit.content.model.CategoryInfo +import com.pokit.content.model.Content +import java.time.LocalDateTime + +data class GetContentResult( + val contentId: Long, + val category: CategoryInfo, + val data: String, + val title: String, + val memo: String, + val alertYn: String, + val createdAt: LocalDateTime, + val favorites: Boolean = false +) + +fun Content.toGetContentResponse(favorites: Boolean, category: Category): GetContentResult { + return GetContentResult( + contentId = this.id, + category = CategoryInfo(category.categoryId, category.categoryName), + data = this.data, + title = this.title, + memo = this.memo, + alertYn = this.alertYn, + createdAt = this.createdAt, + favorites = favorites + ) +}