Skip to content

Commit

Permalink
Merge pull request #83 from ClothingStoreService/feature/productLine-…
Browse files Browse the repository at this point in the history
…list

Feature/product line list
  • Loading branch information
Ogu1208 authored Jul 11, 2024
2 parents 18700cf + aa8edf4 commit d25e730
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.hibernate.query.Page;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -15,33 +17,41 @@
import org.store.clothstar.productLine.dto.response.ProductLineWithProductsJPAResponse;
import org.store.clothstar.productLine.service.ProductLineService;

import java.awt.print.Pageable;
import java.net.URI;
import java.util.List;

@Tag(name = "ProductLines", description = "ProductLine 관련 API 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/productLines")
//@RequestMapping("/v1/productLines")
public class ProductLineController {

private final ProductLineService productLineService;

@Operation(summary = "전체 상품 조회", description = "삭제되지 않은 모든 상품을 조회한다.")
@GetMapping
@GetMapping("/v1/productLines")
public ResponseEntity<List<ProductLineResponse>> getAllProductLines() {
List<ProductLineResponse> productLineResponses = productLineService.getAllProductLines();
return ResponseEntity.ok().body(productLineResponses);
}

@Operation(summary = "전체 상품 조회", description = "삭제되지 않은 모든 상품을 조회한다.")
@GetMapping("/v1/productLines")
public ResponseEntity<Page<ProductLineResponse>> getAllProductLines(@PageableDefault(size = 18) Pageable pageable) {
List<ProductLineResponse> productLineResponses = productLineService.getAllProductLines();
return ResponseEntity.ok().body(productLineResponses);
}

@Operation(summary = "상품 상세 조회", description = "productLineId로 상품과 하위 옵션들을 상세 조회한다.")
@GetMapping("/{productLineId}")
@GetMapping("/v1/productLines/{productLineId}")
public ResponseEntity<ProductLineWithProductsJPAResponse> getProductLine(@PathVariable("productLineId") Long productLineId) {
ProductLineWithProductsJPAResponse productLineWithProducts = productLineService.getProductLineWithProducts(productLineId);
return ResponseEntity.ok().body(productLineWithProducts);
}

@Operation(summary = "상품 등록", description = "카테고리 아이디, 상품 이름, 내용, 가격, 상태를 입력하여 상품을 신규 등록한다.")
@PostMapping
@PostMapping("/v1/productLines")
public ResponseEntity<URI> createProductLine(@Validated @RequestBody CreateProductLineRequest createProductLineRequest) {
Long productLineId = productLineService.createProductLine(createProductLineRequest);
URI location = URIBuilder.buildURI(productLineId);
Expand All @@ -50,7 +60,7 @@ public ResponseEntity<URI> createProductLine(@Validated @RequestBody CreateProdu
}

@Operation(summary = "상품 수정", description = "상품 이름, 가격, 재고, 상태를 입력하여 상품 정보를 수정한다.")
@PutMapping("/{productLineId}")
@PutMapping("/v1/productLines/{productLineId}")
public ResponseEntity<MessageDTO> updateProductLine(
@PathVariable Long productLineId,
@Validated @RequestBody UpdateProductLineRequest updateProductLineRequest) {
Expand All @@ -60,7 +70,7 @@ public ResponseEntity<MessageDTO> updateProductLine(
return ResponseEntity.ok().body(new MessageDTO(HttpStatus.OK.value(), "ProductLine updated successfully"));
}

@DeleteMapping("/{productLineId}")
@DeleteMapping("/v1/productLines/{productLineId}")
public ResponseEntity<Void> deleteProductLine(@PathVariable("productLineId") Long productLineId) {
productLineService.setDeletedAt(productLineId);
return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,20 @@
public class ProductLineWithProductsJPAResponse {

private Long productLineId;
private CategoryResponse category;
private String name;
private String content;
private int price;
private Long totalStock;
private ProductLineStatus status;
// private List<ProductEntity> productList;
private List<ProductResponse> productList;
private Long saleCount; // ~개 판매중
private MemberSimpleResponse member;
private SellerSimpleResponse seller;
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
// private LocalDateTime deletedAt;

// @QueryProjection
// public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Category category, SellerEntity seller, Member member, Long totalStock) {
// public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, Category category, SellerEntity seller, MemberEntity member, Long totalStock) {
// this.productLineId = productLine.getProductLineId();
// this.category = CategoryResponse.from(category);
// this.name = productLine.getName();
Expand All @@ -64,21 +60,19 @@ public class ProductLineWithProductsJPAResponse {
// }

// 추가된 생성자
public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, CategoryEntity category, Seller seller, Member member, Long totalStock, List<ProductResponse> productList) {
public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, CategoryEntity category, SellerEntity seller, MemberEntity member, Long totalStock, List<ProductResponse> productList) {
this(productLine, category, seller, member, totalStock);
this.productList = productList != null ? productList : new ArrayList<>();
}

@QueryProjection
public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, CategoryEntity category, Seller seller, Member member, Long totalStock) {
public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, SellerEntity seller, Long totalStock) {
this.productLineId = productLine.getProductLineId();
this.category = CategoryResponse.from(category);
this.name = productLine.getName();
this.price = productLine.getPrice();
this.totalStock = totalStock;
this.status = productLine.getStatus();
this.saleCount = productLine.getSaleCount();
this.member = MemberSimpleResponse.from(member);
this.seller = SellerSimpleResponse.from(seller);
this.createdAt = productLine.getCreatedAt();
this.modifiedAt = productLine.getModifiedAt();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Page<ProductLineWithProductsJPAResponse> getProductLinesWithOptions(Pagea
ProductEntity product = tuple.get(qProduct);

ProductLineWithProductsJPAResponse response = productLineMap.computeIfAbsent(productLine.getProductLineId(),
id -> new ProductLineWithProductsJPAResponse(productLine, category, seller, member, productLine.getProducts().stream().mapToLong(ProductEntity::getStock).sum()));
id -> new ProductLineWithProductsJPAResponse(productLine, seller, productLine.getProducts().stream().mapToLong(ProductEntity::getStock).sum()));

if (product != null) {
response.getProductList().add(ProductResponse.from(product));
Expand All @@ -91,15 +91,11 @@ public Optional<ProductLineWithProductsJPAResponse> findProductLineWithOptionsBy
ProductLineWithProductsJPAResponse result = jpaQueryFactory
.select(new QProductLineWithProductsJPAResponse(
qProductLine,
qCategory,
qSeller,
qMember,
totalStockExpression
))
.from(qProductLine)
.innerJoin(qProductLine.seller, qSeller)
.innerJoin(qSeller.member, qMember)
.innerJoin(qProductLine.category, qCategory)
.leftJoin(qProductLine.products, qProduct)
.where(qProductLine.productLineId.eq(productLineId)
.and(qProductLine.deletedAt.isNull()))
Expand Down
Loading

0 comments on commit d25e730

Please sign in to comment.