From 8fad36acae89d3f0edf14791981c1cdeeb187cca Mon Sep 17 00:00:00 2001 From: Yong Date: Sun, 25 Feb 2024 18:24:40 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=8B=A4=EC=9D=B4=EC=96=B4=EB=A6=AC=20?= =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/diary/DiaryController.kt | 7 ++++++ .../api/service/diary/DiaryService.kt | 11 ++++++++++ .../repository/query/DiaryQueryRepository.kt | 22 +++++++++++++++++++ .../domain/repository/reader/DiaryReader.kt | 4 ++++ 4 files changed, 44 insertions(+) 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) + } }