diff --git a/lovebird-api/src/main/kotlin/com/lovebird/api/controller/diary/DiaryController.kt b/lovebird-api/src/main/kotlin/com/lovebird/api/controller/diary/DiaryController.kt index 7f7c38a..6c248d9 100644 --- a/lovebird-api/src/main/kotlin/com/lovebird/api/controller/diary/DiaryController.kt +++ b/lovebird-api/src/main/kotlin/com/lovebird/api/controller/diary/DiaryController.kt @@ -43,6 +43,13 @@ class DiaryController( return ApiResponse.success(diaryService.findAllByMemoryDate(request, user)) } + @GetMapping + fun findAll( + @AuthorizedUser user: User + ): ApiResponse { + return ApiResponse.success(diaryService.findAll(user)) + } + @GetMapping("/cursor") fun findAllByCursor( @AuthorizedUser user: User, diff --git a/lovebird-api/src/main/kotlin/com/lovebird/api/service/diary/DiaryService.kt b/lovebird-api/src/main/kotlin/com/lovebird/api/service/diary/DiaryService.kt index d04630c..2b354b1 100644 --- a/lovebird-api/src/main/kotlin/com/lovebird/api/service/diary/DiaryService.kt +++ b/lovebird-api/src/main/kotlin/com/lovebird/api/service/diary/DiaryService.kt @@ -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 = 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) diff --git a/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/query/DiaryQueryRepository.kt b/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/query/DiaryQueryRepository.kt index 1405b63..e8f4a2d 100644 --- a/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/query/DiaryQueryRepository.kt +++ b/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/query/DiaryQueryRepository.kt @@ -113,6 +113,28 @@ class DiaryQueryRepository( .fetch() } + fun findAll(userId: Long, partnerId: Long?): List { + 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 { diff --git a/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/reader/DiaryReader.kt b/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/reader/DiaryReader.kt index 57f4577..b184f7c 100644 --- a/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/reader/DiaryReader.kt +++ b/lovebird-domain/src/main/kotlin/com/lovebird/domain/repository/reader/DiaryReader.kt @@ -32,4 +32,8 @@ class DiaryReader( fun findAllByMemoryDate(param: DiarySimpleRequestParam): List { return diaryQueryRepository.findAllByMemoryDate(param) } + + fun findAll(userId: Long, partnerId: Long?): List { + return diaryQueryRepository.findAll(userId, partnerId) + } }