-
Notifications
You must be signed in to change notification settings - Fork 7
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/BE] 제품에 카테고리를 추가 #258
Changes from 3 commits
fba6a1b
ccfa440
c3b0847
4a9e4d5
88129bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[[Product]] | ||
== Product API | ||
|
||
=== 제품 단일 상품 조회 | ||
|
||
operation::keyboards-get[snippets='http-request,http-response'] | ||
|
||
=== 제품 목록 페이지 조회 | ||
|
||
==== category 조건 | ||
|
||
- `keyboard` (키보드) | ||
- `mouse` (마우스) | ||
- `monitor` (모니터) | ||
- `stand` (거치대) | ||
- `software` (소프트웨어) | ||
- 없을 경우 모든 제품 조회 | ||
|
||
==== sort 조건 | ||
|
||
- `rating,desc`(평점순) | ||
- `reviewCount,desc`(리뷰 많은순) | ||
- 없을 경우 등록 순서 | ||
|
||
operation::keyboards-page-get[snippets='http-request,http-response'] |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.woowacourse.f12.application.product; | ||
|
||
import com.woowacourse.f12.domain.product.Category; | ||
import com.woowacourse.f12.domain.product.Product; | ||
import com.woowacourse.f12.domain.product.ProductRepository; | ||
import com.woowacourse.f12.dto.response.product.ProductPageResponse; | ||
import com.woowacourse.f12.dto.response.product.ProductResponse; | ||
import com.woowacourse.f12.exception.notfound.KeyboardNotFoundException; | ||
import com.woowacourse.f12.presentation.product.CategoryConstant; | ||
import java.util.Objects; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class ProductService { | ||
|
||
private final ProductRepository productRepository; | ||
|
||
public ProductService(final ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
} | ||
|
||
public ProductResponse findById(final Long id) { | ||
final Product product = productRepository.findById(id) | ||
.orElseThrow(KeyboardNotFoundException::new); | ||
return ProductResponse.from(product); | ||
} | ||
|
||
public ProductPageResponse findPage(CategoryConstant categoryConstant, final Pageable pageable) { | ||
if (Objects.isNull(categoryConstant)) { | ||
return ProductPageResponse.from(productRepository.findPageBy(pageable)); | ||
} | ||
|
||
final Category category = categoryConstant.toDomain(); | ||
return ProductPageResponse.from(productRepository.findPageByCategory(category, pageable)); | ||
} | ||
} | ||
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. 매개변수에 final이 빠졌군요! 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. 반영했습니다 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.woowacourse.f12.domain.inventoryproduct; | ||
|
||
import com.woowacourse.f12.domain.product.Keyboard; | ||
import com.woowacourse.f12.domain.product.Product; | ||
import java.util.Objects; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
|
@@ -31,17 +31,17 @@ public class InventoryProduct { | |
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "keyboard_id") | ||
private Keyboard keyboard; | ||
private Product product; | ||
|
||
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. joinColum 에서 keyboard_id 가 아닌 product_id로 해주세요! 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. 반영했습니다. |
||
protected InventoryProduct() { | ||
} | ||
|
||
@Builder | ||
private InventoryProduct(final Long id, final boolean selected, final Long memberId, final Keyboard keyboard) { | ||
private InventoryProduct(final Long id, final boolean selected, final Long memberId, final Product product) { | ||
this.id = id; | ||
this.selected = selected; | ||
this.memberId = memberId; | ||
this.keyboard = keyboard; | ||
this.product = product; | ||
} | ||
|
||
public void updateSelected(boolean selected) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package com.woowacourse.f12.domain.inventoryproduct; | ||
|
||
import com.woowacourse.f12.domain.product.Keyboard; | ||
import com.woowacourse.f12.domain.product.Product; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface InventoryProductRepository extends JpaRepository<InventoryProduct, Long> { | ||
|
||
List<InventoryProduct> findByMemberId(Long memberId); | ||
|
||
boolean existsByMemberIdAndKeyboard(Long memberId, Keyboard keyboard); | ||
boolean existsByMemberIdAndProduct(Long memberId, Product product); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.woowacourse.f12.domain.product; | ||
|
||
public enum Category { | ||
KEYBOARD, | ||
MOUSE, | ||
MONITOR, | ||
STAND, | ||
SOFTWARE | ||
} | ||
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. 반영했습니다 |
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.
final 키워드를 써보는건 어떨까요?!
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.
반영했습니다.