Skip to content

Commit

Permalink
[feat #55] 안읽음 컨텐츠 api 추가 (#66)
Browse files Browse the repository at this point in the history
* fix: 오탈자 수정

* rename: 폴더 구조 변경

* feat: 즐겨찾기 리마인드 api

* fix: 필요없는 코드 제거

* fix: domain 임시 모킹

* rename: 폴더구조 변경

* refactor: 주석제거 (#53)

* feat: 페이징 처리

* feat: response 칼럼추가

* feat: response 칼럼 추가

* feat: domain 의존 분리

* feat: 읽지 않음 컨텐츠 조회
  • Loading branch information
jimin3263 authored Aug 4, 2024
1 parent 3ccbcb7 commit 1600711
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import com.pokit.common.dto.SliceResponseDto
import com.pokit.common.wrapper.ResponseWrapper.wrapOk
import com.pokit.common.wrapper.ResponseWrapper.wrapSlice
import com.pokit.common.wrapper.ResponseWrapper.wrapUnit
import com.pokit.content.dto.ContentsResponse
import com.pokit.content.dto.request.ContentSearchParams
import com.pokit.content.dto.request.CreateContentRequest
import com.pokit.content.dto.request.UpdateContentRequest
import com.pokit.content.dto.request.toDto
import com.pokit.content.dto.response.BookMarkContentResponse
import com.pokit.content.dto.response.ContentResponse
import com.pokit.content.dto.response.toResponse
import com.pokit.content.dto.response.*
import com.pokit.content.exception.ContentErrorCode
import com.pokit.content.port.`in`.ContentUseCase
import io.swagger.v3.oas.annotations.Operation
Expand Down Expand Up @@ -113,6 +110,7 @@ class ContentController(
condition.copy(categoryId = categoryId).toDto(),
pageable
)
.map { it.toResponse() }
.wrapSlice()
.wrapOk()
}
Expand Down Expand Up @@ -145,6 +143,7 @@ class ContentController(
condition.toDto(),
pageable
)
.map { it.toResponse() }
.wrapSlice()
.wrapOk()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,20 @@ class RemindController(
.map { it.toResponse() }
.wrapSlice()
.wrapOk()

@GetMapping("/unread")
@Operation(summary = "읽지 않음 컨텐츠 조회 API")
fun getUnreadContents(
@AuthenticationPrincipal user: PrincipalUser,
@PageableDefault(
page = 0,
size = 10,
sort = ["createdAt"],
direction = Sort.Direction.DESC
) pageable: Pageable,
): ResponseEntity<SliceResponseDto<RemindContentResponse>> =
contentUseCase.getUnreadContents(user.id, pageable)
.map { it.toResponse() }
.wrapSlice()
.wrapOk()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.pokit.content.dto.response

import java.time.format.DateTimeFormatter

data class ContentsResponse(
val contentId: Long,
val categoryId: Long,
val categoryName: String,
val data: String,
val domain: String,
val title: String,
val memo: String,
val alertYn: String,
val createdAt: String,
val isRead: Boolean,
val thumbNail: String,
)

fun ContentsResult.toResponse(): ContentsResponse {
val formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd")

return ContentsResponse(
contentId = this.contentId,
categoryId = this.categoryId,
categoryName = this.categoryName,
data = this.data,
domain = this.domain,
title = this.title,
memo = this.memo,
alertYn = this.alertYn,
createdAt = this.createdAt.format(formatter),
isRead = this.isRead,
thumbNail = this.thumbNail
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pokit.out.persistence.content.impl

import com.pokit.content.dto.ContentsResponse
import com.pokit.content.dto.response.ContentsResult
import com.pokit.content.dto.request.ContentSearchCondition
import com.pokit.content.model.Content
import com.pokit.content.port.out.ContentPort
Expand Down Expand Up @@ -53,7 +53,7 @@ class ContentAdapter(
userId: Long,
condition: ContentSearchCondition,
pageable: Pageable,
): Slice<ContentsResponse> {
): Slice<ContentsResult> {
var hasNext = false
val order = pageable.sort.getOrderFor("createdAt")

Expand All @@ -72,6 +72,7 @@ class ContentAdapter(
dateBetween(condition.startDate, condition.endDate),
categoryIn(condition.categoryIds)
)
.groupBy(contentEntity)
.orderBy(getSort(contentEntity.createdAt, order!!))
.limit(pageable.pageSize + 1L)

Expand All @@ -84,7 +85,7 @@ class ContentAdapter(
}

val contents = contentEntityList.map {
ContentsResponse.of(
ContentsResult.of(
it[contentEntity]!!.toDomain(),
it[categoryEntity.name]!!,
it[userLogEntity.count()]!!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pokit.content.port.`in`

import com.pokit.content.dto.request.ContentCommand
import com.pokit.content.dto.ContentsResponse
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
Expand All @@ -26,9 +26,11 @@ interface ContentUseCase {
userId: Long,
condition: ContentSearchCondition,
pageable: Pageable,
): Slice<ContentsResponse>
): Slice<ContentsResult>

fun getContent(userId: Long, contentId: Long): GetContentResponse

fun getBookmarkContents(userId: Long, pageable: Pageable): Slice<RemindContentResult>

fun getUnreadContents(userId: Long, pageable: Pageable): Slice<RemindContentResult>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pokit.content.port.out

import com.pokit.content.dto.ContentsResponse
import com.pokit.content.dto.response.ContentsResult
import com.pokit.content.dto.request.ContentSearchCondition
import com.pokit.content.model.Content
import org.springframework.data.domain.Pageable
Expand All @@ -19,7 +19,7 @@ interface ContentPort {
userId: Long,
condition: ContentSearchCondition,
pageable: Pageable,
): Slice<ContentsResponse>
): Slice<ContentsResult>

fun deleteByUserId(userId: Long)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.pokit.common.exception.NotFoundCustomException
import com.pokit.content.dto.request.ContentCommand
import com.pokit.content.dto.request.toDomain
import com.pokit.content.dto.response.*
import com.pokit.content.dto.ContentsResponse
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
Expand Down Expand Up @@ -50,9 +50,9 @@ class ContentService(
@Transactional
override fun create(user: User, contentCommand: ContentCommand): Content {
verifyCategory(contentCommand.categoryId, user.id)
return contentPort.persist(
contentCommand.toDomain()
)
val content = contentCommand.toDomain()
content.parseDomain()
return contentPort.persist(content)
}

@Transactional
Expand Down Expand Up @@ -80,7 +80,7 @@ class ContentService(
userId: Long,
condition: ContentSearchCondition,
pageable: Pageable,
): Slice<ContentsResponse> {
): Slice<ContentsResult> {
val contents = contentPort.loadAllByUserIdAndContentId(
userId,
condition,
Expand Down Expand Up @@ -120,6 +120,22 @@ class ContentService(
return SliceImpl(remindContents, pageable, bookMarks.hasNext())
}

override fun getUnreadContents(userId: Long, pageable: Pageable): Slice<RemindContentResult> {
val contentSearchCondition = ContentSearchCondition(
isRead = false,
categoryId = null,
favorites = null,
startDate = null,
endDate = null,
categoryIds = null
)

val unreadContents = contentPort.loadAllByUserIdAndContentId(userId, contentSearchCondition, pageable)
val remindContents = unreadContents.content.map { it.toRemindContentResult() }

return SliceImpl(remindContents, pageable, unreadContents.hasNext())
}

private fun verifyContent(userId: Long, contentId: Long): Content {
return contentPort.loadByUserIdAndId(userId, contentId)
?: throw NotFoundCustomException(ContentErrorCode.NOT_FOUND_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.pokit.content.dto
package com.pokit.content.dto.response

import com.pokit.content.model.Content
import java.time.format.DateTimeFormatter
import java.time.LocalDateTime

data class ContentsResponse(
data class ContentsResult(
val contentId: Long,
val categoryId: Long,
val categoryName: String,
Expand All @@ -12,14 +12,13 @@ data class ContentsResponse(
val title: String,
val memo: String,
val alertYn: String,
val createdAt: String,
val isRead: Boolean
val createdAt: LocalDateTime,
val isRead: Boolean,
val thumbNail: String = "https://pokit-storage.s3.ap-northeast-2.amazonaws.com/category-image/-3+1.png" // TODO 추가 예정
) {
companion object {
fun of(content: Content, categoryName: String, isRead: Long): ContentsResponse {
val formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd")

return ContentsResponse(
fun of(content: Content, categoryName: String, isRead: Long): ContentsResult {
return ContentsResult(
contentId = content.id,
categoryId = content.categoryId,
categoryName = categoryName,
Expand All @@ -28,7 +27,7 @@ data class ContentsResponse(
title = content.title,
memo = content.memo,
alertYn = content.alertYn,
createdAt = content.createdAt.format(formatter),
createdAt = content.createdAt,
isRead = isRead > 0
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ fun Content.toRemindContentResult(isRead: Boolean, category: RemindCategory): Re
title = this.title,
createdAt = this.createdAt,
isRead = isRead,
domain = this.domain
domain = this.domain,
)
}

fun ContentsResult.toRemindContentResult(): RemindContentResult {
return RemindContentResult(
contentId = this.contentId,
category = RemindCategory(this.categoryId, this.categoryName),
data = this.data,
title = this.title,
createdAt = this.createdAt,
domain = this.domain,
isRead = this.isRead,
thumbNail = this.thumbNail
)
}

0 comments on commit 1600711

Please sign in to comment.