-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
72 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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
2 changes: 2 additions & 0 deletions
2
src/main/kotlin/org/store/clothstar/product/domain/ItemAttribute.kt
This file contains 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 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 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 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 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 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
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/org/store/clothstar/product/repository/ProductRepository.kt
This file contains 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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package org.store.clothstar.product.repository | ||
|
||
import org.springframework.data.jpa.repository.EntityGraph | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
import org.store.clothstar.product.domain.Product | ||
import java.util.* | ||
|
||
@Repository | ||
interface ProductRepository : JpaRepository<Product, Long> { | ||
fun findByProductIdIn(productLineIds: List<Long>): List<Product?> | ||
|
||
@EntityGraph(attributePaths = ["productOptions", "items", "imageList"]) | ||
fun findWithDetailsByProductId(productId: Long): Optional<Product> | ||
} |
This file contains 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
23 changes: 14 additions & 9 deletions
23
src/main/kotlin/org/store/clothstar/product/service/ProductService.kt
This file contains 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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
package org.store.clothstar.product.service | ||
|
||
import jakarta.persistence.EntityNotFoundException | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.web.server.ResponseStatusException | ||
import org.store.clothstar.product.domain.Product | ||
import org.store.clothstar.product.dto.response.ProductResponse | ||
import org.store.clothstar.product.repository.ItemRepository | ||
import org.store.clothstar.product.repository.OptionValueRepository | ||
import org.store.clothstar.product.repository.ProductOptionRepository | ||
import org.store.clothstar.product.repository.ProductRepository | ||
|
||
@Service | ||
class ProductService( | ||
private val productRepository: ProductRepository, | ||
) { | ||
@Transactional | ||
fun createProduct(product: Product): Product { | ||
return productRepository.save(product) | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
fun getProductDetails(productId: Long): ProductResponse { | ||
val product = productRepository.findWithDetailsByProductId(productId) | ||
.orElseThrow { EntityNotFoundException("상품을 찾을 수 없습니다.") } | ||
|
||
return ProductResponse.from(product) | ||
} | ||
|
||
fun findByProductIdIn(productIds: List<Long>): List<Product> { | ||
return productRepository.findByProductIdIn(productIds).map { | ||
it ?: throw IllegalArgumentException("상품을 조회할 수 없습니다.") | ||
} | ||
} | ||
|
||
@Transactional | ||
fun createProduct(product: Product): Product { | ||
return productRepository.save(product) | ||
} | ||
} |
This file contains 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