-
Notifications
You must be signed in to change notification settings - Fork 0
feature: 주문 내역 조회 api #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TaeyeonRoyce
wants to merge
13
commits into
develop
Choose a base branch
from
123-feature-주문-내역-조회-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "123-feature-\uC8FC\uBB38-\uB0B4\uC5ED-\uC870\uD68C-api"
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a50be2f
feat: 주문 내역 조회 쿼리 추가
TaeyeonRoyce 41373eb
feat: 주문 내역 조회 로직 추가
TaeyeonRoyce 9a3f073
refactor: 주문 상세 조회 URI 변경
TaeyeonRoyce 3d6f89d
refactor: 주문 상세 조회 메서드 이름 수정
TaeyeonRoyce eef2302
fix: 빈 값 조회시 WHERE IN 절에 적용 되지 않는 오류 수정
TaeyeonRoyce 4de21a6
feat: 주문 내역 조회 API 추가
TaeyeonRoyce dd18698
refactor: 최신순 정렬 시 ID로 정렬되도록 수정
TaeyeonRoyce df4c95e
refactor: 주문 페이징 조회 상한 개수 조정
TaeyeonRoyce 1f83de8
comment: 주문내역 조회 조건 description 수정
TaeyeonRoyce 088a87d
feat: 여러 주문번호로 해당하는 가장 최신의 orderPayment 조회 쿼리 추가
TaeyeonRoyce 7ca1935
enhancement: 주문 상태 조회시 발생하는 N+1 제거
TaeyeonRoyce 3510c12
style: 사용하지 않는 메서드 제거
TaeyeonRoyce d672574
refactor: 불필요한 어노테이션 제거
TaeyeonRoyce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/petqua/domain/order/OrderCustomRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.petqua.domain.order | ||
|
|
||
| import com.petqua.common.domain.dto.DEFAULT_LAST_VIEWED_ID | ||
| import com.petqua.common.domain.dto.PADDING_FOR_HAS_NEXT_PAGE | ||
|
|
||
| private const val ORDER_PAGING_LIMIT_CEILING = 5 | ||
|
|
||
| data class OrderPaging( | ||
| val lastViewedId: Long? = null, | ||
| val limit: Int = ORDER_PAGING_LIMIT_CEILING, | ||
| val lastViewedOrderNumber: OrderNumber? = null, | ||
| ) { | ||
|
|
||
| companion object { | ||
| fun of( | ||
| lastViewedId: Long, | ||
| limit: Int, | ||
| lastViewedOrderNumber: OrderNumber?, | ||
| ): OrderPaging { | ||
| val adjustedLastViewedId = if (lastViewedId == DEFAULT_LAST_VIEWED_ID) null else lastViewedId | ||
| val adjustedLimit = if (limit > ORDER_PAGING_LIMIT_CEILING) ORDER_PAGING_LIMIT_CEILING else limit | ||
| return OrderPaging(adjustedLastViewedId, adjustedLimit + PADDING_FOR_HAS_NEXT_PAGE, lastViewedOrderNumber) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| interface OrderCustomRepository { | ||
|
|
||
| fun findOrdersByMemberId( | ||
| memberId: Long, | ||
| orderPaging: OrderPaging, | ||
| ): List<Order> | ||
| } |
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/com/petqua/domain/order/OrderCustomRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package com.petqua.domain.order | ||
|
|
||
| import com.linecorp.kotlinjdsl.dsl.jpql.jpql | ||
| import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext | ||
| import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderer | ||
| import com.petqua.common.util.createQuery | ||
| import jakarta.persistence.EntityManager | ||
| import org.springframework.stereotype.Repository | ||
|
|
||
|
|
||
| @Repository | ||
| class OrderCustomRepositoryImpl( | ||
| private val entityManager: EntityManager, | ||
| private val jpqlRenderContext: JpqlRenderContext, | ||
| private val jpqlRenderer: JpqlRenderer, | ||
| ) : OrderCustomRepository { | ||
|
|
||
| override fun findOrdersByMemberId( | ||
| memberId: Long, | ||
| orderPaging: OrderPaging, | ||
| ): List<Order> { | ||
| val latestOrderNumbers = findLatestOrderNumbers(memberId, orderPaging) | ||
| if (latestOrderNumbers.isEmpty()) { | ||
| return emptyList() | ||
| } | ||
|
|
||
| val query = jpql { | ||
| select( | ||
| entity(Order::class), | ||
| ).from( | ||
| entity(Order::class), | ||
| ).where( | ||
| path(Order::orderNumber)(OrderNumber::value).`in`(latestOrderNumbers), | ||
| ).orderBy( | ||
| path(Order::id).desc() | ||
| ) | ||
| } | ||
|
|
||
| return entityManager.createQuery( | ||
| query, | ||
| jpqlRenderContext, | ||
| jpqlRenderer, | ||
| ) | ||
| } | ||
|
|
||
| private fun findLatestOrderNumbers( | ||
| memberId: Long, | ||
| paging: OrderPaging, | ||
| ): List<String> { | ||
| val query = jpql(OrderDynamicJpqlGenerator) { | ||
| selectDistinct( | ||
| path(Order::orderNumber)(OrderNumber::value) | ||
| ).from( | ||
| entity(Order::class) | ||
| ).whereAnd( | ||
| path(Order::memberId).eq(memberId), | ||
| orderIdLt(paging.lastViewedId), | ||
| orderNumberNotEq(paging.lastViewedOrderNumber), | ||
| ).orderBy( | ||
| path(Order::id).desc() | ||
| ) | ||
| } | ||
|
|
||
| return entityManager.createQuery<String>( | ||
| query, | ||
| jpqlRenderContext, | ||
| jpqlRenderer, | ||
| paging.limit, | ||
| ) | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/petqua/domain/order/OrderDynamicJpqlGenerator.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.petqua.domain.order | ||
|
|
||
| import com.linecorp.kotlinjdsl.dsl.jpql.Jpql | ||
| import com.linecorp.kotlinjdsl.dsl.jpql.JpqlDsl | ||
| import com.linecorp.kotlinjdsl.querymodel.jpql.predicate.Predicate | ||
|
|
||
| class OrderDynamicJpqlGenerator : Jpql() { | ||
| companion object Constructor : JpqlDsl.Constructor<OrderDynamicJpqlGenerator> { | ||
| override fun newInstance(): OrderDynamicJpqlGenerator = OrderDynamicJpqlGenerator() | ||
| } | ||
|
|
||
| fun Jpql.orderNumberNotEq(orderNumber: OrderNumber?): Predicate? { | ||
| return orderNumber?.let { path(Order::orderNumber).notEqual(it) } | ||
| } | ||
|
|
||
| fun Jpql.orderIdLt(lastViewedId: Long?): Predicate? { | ||
| return lastViewedId?.let { path(Order::id).lt(it) } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주문을 기준으로 페이징을 하기 위해 서브쿼리가 필요했습니다.
Kotlin-jdsl을 통해 1번에 해당하는 subquery를 작성하였는데요.
.asSubquery()를 통해 메인 쿼리에 추가하는 식으로 작성할 수 있습니다.하지만 Kotlin-jdsl은 쿼리 자체에서 limit를 제공하지 않고, JPQL로 렌더될 때
setMaxResult()를 통해 조회 개수를 설정합니다.결국 subquery에서 개수 제한을 사용하지 못해서 쿼리를 분리하여 사용했습니다. (방법이 있다면 알려주세요!)
JPQL을 직접 작성하려 했지만, 조회 조건이 동적으로 변하는 쿼리를 담아내기엔 어려움이 있어 2번의 쿼리로 구성했어요..!
리뷰하실때 참고하시면 좋을 것 같습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오... 생각을 못했는데 주문 조회에서 고려할 게 많았네요
저는 지금 방식 좋아요!!👍
더 공부하고 좋은 방식이 있다면 다시 리뷰 남기겠습니다!!🙇♀️