Skip to content

Commit

Permalink
Hotfix | #81 | @YongsHub | v1.0.1 출시 위해 임시 다이어리 전체 조회 API 추가
Browse files Browse the repository at this point in the history
* feat: 다이어리 전체 조회 API 추가

* test: 다이어리 전체 조회 테스트 추가
  • Loading branch information
YongsHub authored Feb 25, 2024
1 parent c185439 commit 39cae17
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 1 deletion.
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<DiarySimpleListResponse> {
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
2 changes: 1 addition & 1 deletion lovebird-api/src/main/resources/static/docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4585,7 +4585,7 @@ <h4 id="_다이어리_삭제_response_fields"><a class="link" href="#_다이어
<div id="footer">
<div id="footer-text">
Version 1.0.2-SNAPSHOT<br>
Last updated 2024-02-06 12:23:01 +0900
Last updated 2024-02-12 13:10:39 +0900
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 39cae17

Please sign in to comment.