Skip to content

Commit

Permalink
Merge pull request #92 from ClothingStoreService/feature/category-pro…
Browse files Browse the repository at this point in the history
…duct-pagination

Feature/category product pagination
  • Loading branch information
Ogu1208 authored Jul 11, 2024
2 parents d25e730 + 8bb000b commit 54da983
Show file tree
Hide file tree
Showing 16 changed files with 993 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -13,6 +17,9 @@
import org.store.clothstar.category.service.CategoryService;
import org.store.clothstar.common.dto.MessageDTO;
import org.store.clothstar.common.util.URIBuilder;
import org.store.clothstar.productLine.dto.response.ProductLineResponse;
import org.store.clothstar.productLine.dto.response.ProductLineWithProductsJPAResponse;
import org.store.clothstar.productLine.service.ProductLineService;

import java.net.URI;
import java.util.List;
Expand All @@ -23,6 +30,7 @@
public class CategoryController {

private final CategoryService categoryService;
private final ProductLineService productLineService;

@Operation(summary = "전체 카테고리 조회", description = "모든 카테고리를 조회한다.")
@GetMapping
Expand Down Expand Up @@ -58,4 +66,24 @@ public ResponseEntity<MessageDTO> updateCategories(

return ResponseEntity.ok().body(new MessageDTO(HttpStatus.OK.value(), "Category updated successfully"));
}

@Operation(summary = "카테고리별 상품 조회 (Offset Paging)", description = "카테고리 ID로 해당 카테고리에 속하는 모든 상품을 Offset Paging을 통해 조회한다.")
@GetMapping("/{categoryId}/productLines/offset")
public ResponseEntity<Page<ProductLineWithProductsJPAResponse>> getProductLinesByCategory(
@PathVariable Long categoryId,
@PageableDefault(size = 18) Pageable pageable,
@RequestParam(required = false) String keyword) {
Page<ProductLineWithProductsJPAResponse> productLineResponses = productLineService.getProductLinesByCategoryWithOffsetPaging(categoryId, pageable, keyword);
return ResponseEntity.ok().body(productLineResponses);
}

@Operation(summary = "카테고리별 상품 조회 (Slice Paging)", description = "카테고리 ID로 해당 카테고리에 속하는 모든 상품을 Slice Paging을 통해 조회한다.")
@GetMapping("/{categoryId}/productLines/slice")
public ResponseEntity<Slice<ProductLineWithProductsJPAResponse>> getProductLinesByCategorySlice(
@PathVariable Long categoryId,
@PageableDefault(size = 18) Pageable pageable,
@RequestParam(required = false) String keyword) {
Slice<ProductLineWithProductsJPAResponse> productLineResponses = productLineService.getProductLinesByCategoryWithSlicePaging(categoryId, pageable, keyword);
return ResponseEntity.ok().body(productLineResponses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.store.clothstar.category.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class CategoryViewController {

@GetMapping("/categoryPagingOffset")
public String categoryPagingOffset() {
return "category-product_lines-offset";
}

@GetMapping("/categoryPagingSlice")
public String categoryPagingSlice() {
return "category-product_lines-slice";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.formLogin(AbstractHttpConfigurer::disable);

http.authorizeHttpRequests((auth) -> auth
.requestMatchers("/", "/login", "/userPage", "/sellerPage", "/adminPage", "/main"
, "/v1/members/login", "/signup", "/v1/members/email/**", "/v1/access",
.requestMatchers("/", "/login", "/userPage", "/sellerPage", "/adminPage", "/main",
"/v1/members/login", "/signup", "/v1/members/email/**", "/v1/access",
"/v1/categories/**", "/v1/products/**", "/v1/productLines/**", "/v2/productLines/**",
"/productLinePagingSlice", "/productLinePagingOffset",
"/v1/orderdetails", "/v1/orders", "membersPagingOffset", "membersPagingSlice",
"/v1/orderdetails", "/v1/orders", "/v2/orders", "/v3/orders", "/v1/orders/list",
"/v1/orders/list","/ordersPagingOffset","/ordersPagingSlice","/v2/orders/list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
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.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -36,10 +38,21 @@ public ResponseEntity<List<ProductLineResponse>> 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();
@Operation(summary = "전체 상품 Offset Paging 조회", description = "삭제되지 않은 모든 상품을 조회한다.")
@GetMapping("/v1/productLines/offset")
public ResponseEntity<Page<ProductLineWithProductsJPAResponse>> getAllProductLinesOffsetPaging(
@PageableDefault(size = 18) Pageable pageable,
@RequestParam(required = false) String keyword){
Page<ProductLineWithProductsJPAResponse> productLineResponses = productLineService.getAllProductLinesWithProductsOffsetPaging(pageable, keyword);
return ResponseEntity.ok().body(productLineResponses);
}

@Operation(summary = "전체 상품 Slice Paging 조회", description = "삭제되지 않은 모든 상품을 조회한다.")
@GetMapping("/v1/productLines/slice")
public ResponseEntity<Slice<ProductLineWithProductsJPAResponse>> getAllProductLinesSlicePaging(
@PageableDefault(size = 18) Pageable pageable,
@RequestParam(required = false) String keyword) {
Slice<ProductLineWithProductsJPAResponse> productLineResponses = productLineService.getAllProductLinesWithProductsSlicePaging(pageable, keyword);
return ResponseEntity.ok().body(productLineResponses);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.store.clothstar.productLine.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class ProductLineViewController {

@GetMapping("/productLinePagingOffset")
public String productLinePagingOffset() {
return "productLineOffsetList";
}

@GetMapping("/productLinePagingSlice")
public String productLinePagingSlice() {
return "productLineSliceList";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.querydsl.core.annotations.QueryProjection;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.store.clothstar.category.dto.response.CategoryResponse;
import org.store.clothstar.category.entity.CategoryEntity;
Expand All @@ -11,12 +12,14 @@
import org.store.clothstar.member.dto.response.MemberSimpleResponse;
import org.store.clothstar.member.dto.response.SellerSimpleResponse;
import org.store.clothstar.product.dto.response.ProductResponse;
import org.store.clothstar.product.entity.ProductEntity;
import org.store.clothstar.productLine.domain.type.ProductLineStatus;
import org.store.clothstar.productLine.entity.ProductLineEntity;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Builder
@Getter
Expand All @@ -25,62 +28,56 @@
@NoArgsConstructor
public class ProductLineWithProductsJPAResponse {

@Schema(description = "상품 id", example = "1")
private Long productLineId;

@Schema(description = "상품 이름", example = "우유 모자")
private String name;

@Schema(description = "상품 설명", example = "우유 모자입니다.")
private String content;

@Schema(description = "상품 가격", example = "10000")
private int price;

@Schema(description = "상품 전체 재고", example = "100")
private Long totalStock;

@Schema(description = "상품 상태", example = "FOR_SALE")
private ProductLineStatus status;
private List<ProductResponse> productList;

@Schema(description = "상품 옵션")
private List<ProductResponse> productList = new ArrayList<>();

@Schema(description = "상품 판매량", example = "10")
private Long saleCount; // ~개 판매중

@Schema(description = "판매자 정보")
private SellerSimpleResponse seller;

@Schema(description = "생성일시")
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;

// @QueryProjection
// 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();
// this.price = productLine.getPrice();
// this.totalStock = totalStock;
// this.status = productLine.getStatus();
// this.productList = productLine.getProducts()
// .stream()
// .map(ProductResponse::from)
// .toList();
//// this.productList = productLine.getProducts();
// this.saleCount = productLine.getSaleCount();
// this.member = MemberSimpleResponse.from(member);
// this.seller = SellerSimpleResponse.from(seller);
// this.createdAt = productLine.getCreatedAt();
// this.modifiedAt = productLine.getModifiedAt();
//// this.deletedAt = productLine.getDeletedAt();
// }

// 추가된 생성자
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<>();
}
@Schema(description = "수정일시")
private LocalDateTime modifiedAt;

@QueryProjection
public ProductLineWithProductsJPAResponse(ProductLineEntity productLine, SellerEntity seller, Long totalStock) {
this.productLineId = productLine.getProductLineId();
this.name = productLine.getName();
this.content = productLine.getContent();
this.price = productLine.getPrice();
this.totalStock = totalStock;
this.status = productLine.getStatus();
this.saleCount = productLine.getSaleCount();
this.seller = SellerSimpleResponse.from(seller);
this.createdAt = productLine.getCreatedAt();
this.modifiedAt = productLine.getModifiedAt();
this.productList = new ArrayList<>();
// this.productList = productLine.getProducts().stream().map(ProductResponse::from).collect(Collectors.toList());
}

public void setProductList(List<ProductResponse> productList) {
this.productList = productList != null ? productList : new ArrayList<>();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository;
import org.store.clothstar.productLine.dto.response.ProductLineWithProductsJPAResponse;
import org.store.clothstar.productLine.entity.ProductLineEntity;

import java.util.Optional;

Expand All @@ -13,4 +15,11 @@ public interface ProductLineRepositoryCustom {

Optional<ProductLineWithProductsJPAResponse> findProductLineWithOptionsById(Long productLineId);

Page<ProductLineWithProductsJPAResponse> findAllOffsetPaging(Pageable pageable, String keyword);

Slice<ProductLineWithProductsJPAResponse> findAllSlicePaging(Pageable pageable, String keyword);

Page<ProductLineEntity> findEntitiesByCategoryWithOffsetPaging(Long categoryId, Pageable pageable, String keyword);

Slice<ProductLineEntity> findEntitiesByCategoryWithSlicePaging(Long categoryId, Pageable pageable, String keyword);
}
Loading

0 comments on commit 54da983

Please sign in to comment.