Skip to content
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

feature: 봉달 목록 조회 api #38

Merged
merged 12 commits into from
Feb 2, 2024

Conversation

TaeyeonRoyce
Copy link
Member

@TaeyeonRoyce TaeyeonRoyce commented Feb 1, 2024

📌 관련 이슈

📁 작업 설명

  • 봉달에 담겨 있는 상품 조회 API 구현
    간접 참조로 되어 있는 product를 조회하기 위해 findAllProductResponseByIdIn()을 추가 했습니다.

  • 테스트 fixture 개선
    fixture에서 id = 1L로 지정하다 보니 생성하고 저장할 때 동일한 객체로 판단해서 update 쿼리가 날아가는 이슈를 겪었습니다.. 수정했어요! 948eaf8

기타

- on #37

@TaeyeonRoyce TaeyeonRoyce force-pushed the 28-feature-봉달-목록-조회-api branch from 2802e9b to cae10d1 Compare February 2, 2024 04:55
@TaeyeonRoyce TaeyeonRoyce marked this pull request as ready for review February 2, 2024 04:55
Copy link

github-actions bot commented Feb 2, 2024

Test Results

16 files  ±0  16 suites  ±0   5s ⏱️ -1s
49 tests +7  49 ✅ +7  0 💤 ±0  0 ❌ ±0 
74 runs  +8  74 ✅ +8  0 💤 ±0  0 ❌ ±0 

Results for commit 5a50036. ± Comparison against base commit c2ad99b.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@hgo641 hgo641 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정 성 테 스 트 멋 져 요

Comment on lines 74 to 89
fun fromDeletedProduct(cartProduct: CartProduct): CartProductResponse {
return CartProductResponse(
id = cartProduct.id,
storeName = "",
productId = cartProduct.productId,
productName = "",
productThumbnailUrl = "",
productPrice = 0,
productDiscountRate = 0,
productDiscountPrice = 0,
quantity = cartProduct.quantity.value,
isMale = cartProduct.isMale,
deliveryMethod = cartProduct.deliveryMethod.name,
isOnSale = false,
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 디자인이 아직 안정해졌다고 해서 임의로 보내는 값인가요?.?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 경우에는 [품절]로 표기 하신다고 했어요!
client 입장에서 봉달 목록 data를 한번에 조회하게 되는데 품절인 상품과 그렇지 않은 상품의 응답 스키마가 달라지면 복잡해질 것 같더라고요.
그래서 그냥 임의 데이터로 채워 넣고 isOnSale로 품절 여부를 판단할 수 있게 두었습니다!

@Transactional(readOnly = true)
fun readAll(memberId: Long): List<CartProductResponse> {
memberRepository.existByIdOrThrow(memberId, MemberException(NOT_FOUND_MEMBER))
val cartProducts = cartProductRepository.findAllByMemberId(memberId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헛 저 찜 목록 조회할 때 이거까지 한 번에 조인해서 가져오게했는데, 혹시 cartProducts를 미리 조회해오신 이유가 있으신가요?

Copy link
Member Author

@TaeyeonRoyce TaeyeonRoyce Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Product가 제거된 cartProduct가 조회 되지 않을 것 같아서 분리했었습니다.
근데 outer join 하고 product가 null인 걸로 삭제 판단해도 될 것 같네요!
커넥션을 줄이는 방향으로 수정해보겠습니다!

productRepository.deleteById(productAId)
val results = cartProductService.readAll(memberId)

Then("빈 리스트를 반환 한다") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 Then 글 잘못된 것 같아요!

Copy link
Contributor

@Combi153 Combi153 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

질문 몇 가지 남겼어요~

Comment on lines 83 to 93
@Transactional(readOnly = true)
fun readAll(memberId: Long): List<CartProductResponse> {
memberRepository.existByIdOrThrow(memberId, MemberException(NOT_FOUND_MEMBER))
val cartProducts = cartProductRepository.findAllByMemberId(memberId)
val products = productByIds(cartProducts)
val findAll = productRepository.findAll()
return cartProducts.map {
products[it.id]?.let { product -> CartProductResponse.of(it, product) }
?: CartProductResponse.fromDeletedProduct(it)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

장바구니 전체 가격은 클라이언트에서 계산하는 걸까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 협의해보고 적용하겠습니다!

Comment on lines +101 to +111
val query = jpql {
selectNew<ProductResponse>(
entity(Product::class),
path(Store::name)
).from(
entity(Product::class),
join(Store::class).on(path(Product::storeId).eq(path(Store::id))),
).where(
predicateByIds(ids)
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멋지게 잘 쓰셨네요!
혹시 데이터 순서도 명시하면 어떨까요?

@@ -177,6 +177,22 @@ class ProductCustomRepositoryImplTest(
}
}

Given("다중 id로 ProductResponse를 조회 할 때") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines 377 to 387
When("봉달에 담은 상품이 삭제 되면") {
productRepository.delete(productA)
val response = requestReadAllCartProducts(memberAuthResponse.accessToken)

Then("삭제된 상품은 구매 불가능 하도록 조회된다") {
val responseBody = response.`as`(Array<CartProductResponse>::class.java)

assertSoftly(response) {
statusCode shouldBe HttpStatus.OK.value()
responseBody.size shouldBe 3
responseBody.find { it.productId == productA.id }!!.isOnSale shouldBe false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 너무 좋아요 👍

Copy link
Contributor

@Combi153 Combi153 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

업후르브!

Comment on lines 30 to 32
).where(
path(CartProduct::memberId).eq(memberId)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o..or..orderBy 해주시면 안될까요..ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영하겠습니다!! 깜빡했네요ㅠㅠ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5a50036 최신순으로 반영하였습니다!

Comment on lines +57 to +66
storeName = storeName ?: "",
productId = product?.id ?: 0L,
productName = product?.name ?: "",
productThumbnailUrl = product?.thumbnailUrl ?: "",
productPrice = product?.price?.intValueExact() ?: 0,
productDiscountRate = product?.discountRate ?: 0,
productDiscountPrice = product?.discountPrice?.intValueExact() ?: 0,
quantity = cartProduct.quantity.value,
isMale = cartProduct.isMale,
deliveryMethod = cartProduct.deliveryMethod.name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null 을 이렇게 사용할 수 있군요!

@TaeyeonRoyce TaeyeonRoyce merged commit 65016c2 into develop Feb 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: 봉달 목록 조회 API
3 participants