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..15ac91f 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-api/src/main/resources/static/docs/index.html b/lovebird-api/src/main/resources/static/docs/index.html index fc1bc65..a383425 100644 --- a/lovebird-api/src/main/resources/static/docs/index.html +++ b/lovebird-api/src/main/resources/static/docs/index.html @@ -4585,7 +4585,7 @@

diff --git a/lovebird-api/src/test/kotlin/com/lovebird/api/controller/diary/DiaryControllerTest.kt b/lovebird-api/src/test/kotlin/com/lovebird/api/controller/diary/DiaryControllerTest.kt index af60737..dd63930 100644 --- a/lovebird-api/src/test/kotlin/com/lovebird/api/controller/diary/DiaryControllerTest.kt +++ b/lovebird-api/src/test/kotlin/com/lovebird/api/controller/diary/DiaryControllerTest.kt @@ -124,6 +124,37 @@ class DiaryControllerTest( } } + describe("GET : /api/v1/diaries") { + val user = CommonTestFixture.getUser(1L, "uniqueProviderId") + val url = "$baseUrl" + + context("다이어리 전체 조회 요청한다면") { + val request = request(HttpMethod.GET, url) + .header(HttpHeaders.AUTHORIZATION, "Bearer access-token") + val diaries = DiaryTestFixture.getDiarySimpleResponseList(user, null, 5) + val response = DiarySimpleListResponse.of(diaries) + + it("1000 SUCCESS") { + every { diaryService.findAll(any()) } returns response + + mockMvc + .perform(request) + .andExpect(status().isOk) + .andDocument( + "1000-diary-list-all", + requestHeaders( + "Authorization" headerMeans "액세스 토큰" + ), + envelopeResponseBody( + "data.diaries" type ARRAY means "다이어리 목록", + "data.totalCount" type NUMBER means "캘린더 개수" + ) + .andWithPrefix("data.diaries[].", getSimpleDiaryDetailResponseSnippet()) + ) + } + } + } + describe("GET : /api/v1/diaries/{diaryId}") { val user = CommonTestFixture.getUser(1L, "uniqueProviderId") val diary = DiaryTestFixture.getDiaryByUser(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) + } }