Skip to content

Commit

Permalink
feat: 다이어리 전체 조회 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YongsHub committed Feb 25, 2024
1 parent c185439 commit 8fad36a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class DiaryController(
return ApiResponse.success(diaryService.findAllByMemoryDate(request, user))
}

@GetMapping
fun findAll(
@AuthorizedUser user: User
): ApiResponse<DiaryListResponse> {
return ApiResponse.success(diaryService.findAll(user))
}

@GetMapping("/cursor")
fun findAllByCursor(
@AuthorizedUser user: User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ class DiaryService(
diaryWriter.delete(diary)
}

@Transactional(readOnly = true)
fun findAll(user: User): DiarySimpleListResponse {
val coupleEntry: CoupleEntry? = coupleEntryReader.findByUser(user)
val partner: User? = coupleEntry?.partner
val diaries: List<DiarySimpleResponseParam> = diaryReader.findAll(user.id!!, partner?.id)

decryptDiariesOfSimple(diaries)

return DiarySimpleListResponse.of(diaries)
}

@Transactional(readOnly = true)
fun findAllByMemoryDate(request: DiaryListRequest.SearchByMemoryDateRequest, user: User): DiarySimpleListResponse {
val coupleEntry: CoupleEntry? = coupleEntryReader.findByUser(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ class DiaryQueryRepository(
.fetch()
}

fun findAll(userId: Long, partnerId: Long?): List<DiarySimpleResponseParam> {
return queryFactory
.select(
Projections.constructor(
DiarySimpleResponseParam::class.java,
diary.id,
diary.user.id,
diary.title,
diary.memoryDate,
diary.place,
diary.content,
diary.diaryImages.get(0)
)
)
.from(diary)
.innerJoin(user)
.on(eqUserId(user.id))
.where(eqCouple(userId, partnerId))
.orderBy(ascDiaryId())
.fetch()
}

private fun eqDiary(diary: QDiary): BooleanExpression = diary.eq(diary)

private fun eqCouple(userId: Long, partnerId: Long?): BooleanExpression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ class DiaryReader(
fun findAllByMemoryDate(param: DiarySimpleRequestParam): List<DiarySimpleResponseParam> {
return diaryQueryRepository.findAllByMemoryDate(param)
}

fun findAll(userId: Long, partnerId: Long?): List<DiarySimpleResponseParam> {
return diaryQueryRepository.findAll(userId, partnerId)
}
}

0 comments on commit 8fad36a

Please sign in to comment.