-
Notifications
You must be signed in to change notification settings - Fork 0
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
The head ref may contain hidden characters: "28-feature-\uBD09\uB2EC-\uBAA9\uB85D-\uC870\uD68C-api"
Changes from 11 commits
0b08c0e
8262f3a
19e6e83
d381460
69cac7d
4843bd4
cae10d1
713425c
9093334
a66f802
f7a2d80
5a50036
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.petqua.domain.cart | ||
|
||
import com.petqua.application.cart.dto.CartProductResponse | ||
|
||
interface CartProductCustomRepository { | ||
|
||
fun findAllCartResultsByMemberId(memberId: Long): List<CartProductResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.petqua.domain.cart | ||
|
||
import com.linecorp.kotlinjdsl.dsl.jpql.jpql | ||
import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderContext | ||
import com.linecorp.kotlinjdsl.render.jpql.JpqlRenderer | ||
import com.petqua.application.cart.dto.CartProductResponse | ||
import com.petqua.common.util.createQuery | ||
import com.petqua.domain.product.Product | ||
import com.petqua.domain.store.Store | ||
import jakarta.persistence.EntityManager | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class CartProductCustomRepositoryImpl( | ||
private val entityManager: EntityManager, | ||
private val jpqlRenderContext: JpqlRenderContext, | ||
private val jpqlRenderer: JpqlRenderer, | ||
) : CartProductCustomRepository { | ||
|
||
override fun findAllCartResultsByMemberId(memberId: Long): List<CartProductResponse> { | ||
val query = jpql { | ||
selectNew<CartProductResponse>( | ||
entity(CartProduct::class), | ||
entity(Product::class), | ||
path(Store::name) | ||
).from( | ||
entity(CartProduct::class), | ||
leftJoin(Product::class).on(path(CartProduct::productId).eq(path(Product::id))), | ||
leftJoin(Store::class).on(path(Product::storeId).eq(path(Store::id))), | ||
).where( | ||
path(CartProduct::memberId).eq(memberId) | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. o..or..orderBy 해주시면 안될까요..ㅎㅎ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영하겠습니다!! 깜빡했네요ㅠㅠ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5a50036 최신순으로 반영하였습니다! |
||
} | ||
|
||
return entityManager.createQuery( | ||
query, | ||
jpqlRenderContext, | ||
jpqlRenderer | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,26 @@ class ProductCustomRepositoryImpl( | |
jpqlRenderer | ||
) | ||
} | ||
|
||
override fun findAllProductResponseByIdIn(ids: List<Long>): List<ProductResponse> { | ||
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) | ||
) | ||
} | ||
Comment on lines
+101
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 멋지게 잘 쓰셨네요! |
||
|
||
return entityManager.createQuery( | ||
query, | ||
jpqlRenderContext, | ||
jpqlRenderer | ||
) | ||
} | ||
|
||
private fun Jpql.predicateByIds(ids: List<Long>) = if (ids.isEmpty()) null else path(Product::id).`in`(ids) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,22 @@ class ProductCustomRepositoryImplTest( | |
} | ||
} | ||
|
||
Given("다중 id로 ProductResponse를 조회 할 때") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
val product1 = productRepository.save(product(name = "상품1", storeId = store.id)) | ||
val product2 = productRepository.save(product(name = "상품2", storeId = store.id)) | ||
|
||
When("id 목록을 입력하면") { | ||
val products = productRepository.findAllProductResponseByIdIn(listOf(product1.id, product2.id)) | ||
|
||
Then("해당 id의 ProductResponse를 반환한다") { | ||
products shouldContainExactly listOf( | ||
ProductResponse(product1, store.name), | ||
ProductResponse(product2, store.name), | ||
) | ||
} | ||
} | ||
} | ||
|
||
afterContainer { | ||
dataCleaner.clean() | ||
} | ||
|
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.
null 을 이렇게 사용할 수 있군요!