Skip to content

Commit 2d2a49a

Browse files
committed
[FEAT] 세일 탭 조회 기능 구현
1 parent 4acee37 commit 2d2a49a

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

src/main/java/com/freshman/freshmanbackend/domain/product/controller/ProductController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.freshman.freshmanbackend.domain.product.dto.request.ReviewCommentModifyRequest;
1414
import com.freshman.freshmanbackend.domain.product.dto.request.ReviewEntryRequest;
1515
import com.freshman.freshmanbackend.domain.product.dto.request.ReviewModifyRequest;
16+
import com.freshman.freshmanbackend.domain.product.dto.request.SaleProductListRequest;
1617
import com.freshman.freshmanbackend.domain.product.dto.response.ProductRankingResponse;
1718
import com.freshman.freshmanbackend.domain.product.service.SearchLogService;
1819
import com.freshman.freshmanbackend.domain.product.service.command.category.ProductCategoryDeleteService;
@@ -420,4 +421,13 @@ public ResponseEntity<?> getRankingProducts() {
420421
ProductRankingResponse rankingProducts = productListService.getRankingProducts();
421422
return ResponseEntity.ok(new ListResponse(rankingProducts.getProducts()));
422423
}
424+
425+
/**
426+
* 세일 상품 조회
427+
*/
428+
@GetMapping("/sale-rank")
429+
public ResponseEntity<?> getSaleRanks(@ModelAttribute SaleProductListRequest request) {
430+
NoOffsetPageResponse saleList = productListService.getSaleList(request);
431+
return ResponseEntity.ok(saleList);
432+
}
423433
}

src/main/java/com/freshman/freshmanbackend/domain/product/dao/ProductListDao.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.freshman.freshmanbackend.domain.product.domain.enums.ProductSortType;
77
import com.freshman.freshmanbackend.domain.product.dto.request.ProductListRequest;
88
import com.freshman.freshmanbackend.domain.product.dto.request.ProductSearchRequest;
9+
import com.freshman.freshmanbackend.domain.product.dto.request.SaleProductListRequest;
910
import com.freshman.freshmanbackend.domain.product.dto.response.ProductListResponse;
1011
import com.querydsl.core.BooleanBuilder;
1112
import com.querydsl.core.types.ConstructorExpression;
@@ -65,6 +66,23 @@ public List<Long> getProductsPageSeqList(ProductListRequest param) {
6566
.fetch();
6667
}
6768

69+
/**
70+
* 세일 상품 아이디 목록 조회
71+
*
72+
* @param request
73+
* @return
74+
*/
75+
public List<Long> getSaleProductPageList(SaleProductListRequest request) {
76+
QProductSale sale = QProductSale.productSale;
77+
78+
return queryFactory.select(sale.productSeq)
79+
.from(sale)
80+
.where(getSaleCondition(request))
81+
.orderBy(sale.productSeq.desc())
82+
.limit(PAGE_SIZE + 1)
83+
.fetch();
84+
}
85+
6886
/**
6987
* 상품 정보 조회
7088
*
@@ -175,6 +193,21 @@ private BooleanBuilder getCondition(ProductListRequest param) {
175193
return booleanBuilder;
176194
}
177195

196+
private BooleanBuilder getSaleCondition(SaleProductListRequest request) {
197+
BooleanBuilder booleanBuilder = new BooleanBuilder();
198+
LocalDateTime now = LocalDateTime.now();
199+
QProductSale sale = QProductSale.productSale;
200+
201+
booleanBuilder.and(sale.saleStartAt.loe(now));
202+
booleanBuilder.and(sale.saleEndAt.gt(now));
203+
204+
if (request.getNextSeq() != null) {
205+
booleanBuilder.and(sale.productSeq.loe(request.getNextSeq()));
206+
}
207+
208+
return booleanBuilder;
209+
}
210+
178211
/**
179212
* 상품 검색 조회 조건 반환
180213
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.freshman.freshmanbackend.domain.product.dto.request;
2+
3+
import lombok.Getter;
4+
import lombok.NoArgsConstructor;
5+
6+
@NoArgsConstructor
7+
@Getter
8+
public class SaleProductListRequest {
9+
/**
10+
* 다음에 읽어올 productSeq
11+
*/
12+
private Long nextSeq;
13+
}

src/main/java/com/freshman/freshmanbackend/domain/product/service/query/product/ProductListService.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.freshman.freshmanbackend.domain.product.domain.enums.ProductSortType;
55
import com.freshman.freshmanbackend.domain.product.dto.request.ProductListRequest;
66
import com.freshman.freshmanbackend.domain.product.dto.request.ProductSearchRequest;
7+
import com.freshman.freshmanbackend.domain.product.dto.request.SaleProductListRequest;
78
import com.freshman.freshmanbackend.domain.product.dto.response.ProductListResponse;
89
import com.freshman.freshmanbackend.domain.product.dto.response.ProductRankingResponse;
910
import com.freshman.freshmanbackend.domain.product.service.SearchLogService;
@@ -35,7 +36,7 @@ public class ProductListService {
3536
*/
3637
@Transactional(readOnly = true)
3738
public NoOffsetPageResponse getList(ProductListRequest param) {
38-
Boolean isEnd = true;
39+
boolean isEnd = true;
3940
Long nextSeq = null;
4041
Long nextPrice = null;
4142
Integer nextOrderCount = null;
@@ -69,7 +70,7 @@ public NoOffsetPageResponse getList(ProductListRequest param) {
6970
*/
7071
@Transactional(readOnly = true)
7172
public NoOffsetPageResponse getList(ProductSearchRequest param) {
72-
Boolean isEnd = true;
73+
boolean isEnd = true;
7374
// 최근 검색어 등록
7475
searchLogService.entry(param.getKeyword());
7576
List<ProductListResponse> products = productListDao.select(param);
@@ -80,9 +81,15 @@ public NoOffsetPageResponse getList(ProductSearchRequest param) {
8081
return new NoOffsetPageResponse(products, isEnd);
8182
}
8283

84+
/**
85+
* 어드민용 전체 상품 조회
86+
*
87+
* @param page 페이지
88+
* @return 상품 리스트
89+
*/
8390
@Transactional(readOnly = true)
8491
public NoOffsetPageResponse getAllList(int page) {
85-
Boolean isEnd = true;
92+
boolean isEnd = true;
8693
List<ProductListResponse> products = productListDao.selectAll(page);
8794
if (products.size() == PAGE_SIZE + 1) {
8895
products.remove(PAGE_SIZE);
@@ -91,6 +98,25 @@ public NoOffsetPageResponse getAllList(int page) {
9198
return new NoOffsetPageResponse(products, isEnd);
9299
}
93100

101+
/**
102+
* 세일 상품 목록 조회
103+
*/
104+
@Transactional(readOnly = true)
105+
public NoOffsetPageResponse getSaleList(SaleProductListRequest request) {
106+
List<Long> products = productListDao.getSaleProductPageList(request);
107+
if (products.size() == PAGE_SIZE + 1) {
108+
Long nextSeq = products.get(PAGE_SIZE);
109+
products.remove(PAGE_SIZE);
110+
List<ProductListResponse> productInfos = productListDao.getProductInfo(products,
111+
ProductSortType.NEWEST.getCode());
112+
return new NoOffsetPageResponse(productInfos, false, nextSeq);
113+
} else {
114+
List<ProductListResponse> productInfos = productListDao.getProductInfo(products,
115+
ProductSortType.NEWEST.getCode());
116+
return new NoOffsetPageResponse(productInfos, true);
117+
}
118+
}
119+
94120
/**
95121
* 랭킹 조회
96122
*/
@@ -103,6 +129,9 @@ public ProductRankingResponse getRankingProducts() {
103129
return new ProductRankingResponse(productInfo);
104130
}
105131

132+
/**
133+
* 캐시 최신화
134+
*/
106135
@CachePut(value = "ranking")
107136
public ProductRankingResponse cacheUpdate() {
108137
List<Long> productsPageSeqList = productListDao.getProductsPageSeqList(

src/main/java/com/freshman/freshmanbackend/global/common/response/NoOffsetPageResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ public NoOffsetPageResponse(Collection<?> list, Boolean isEnd, Long nextSeq, Lon
3030
this.nextOrderCount = nextOrderCount;
3131
}
3232

33-
public NoOffsetPageResponse(Collection<?> list, Boolean isEnd, Long nextSeq,
34-
Integer nextOrderCount) {
33+
public NoOffsetPageResponse(Collection<?> list, Boolean isEnd, Long nextSeq) {
3534
this.list = list;
3635
this.isEnd = isEnd;
3736
this.count = list == null ? 0 : list.size();
3837
this.nextSeq = nextSeq;
39-
this.nextOrderCount = nextOrderCount;
4038
}
4139
}

0 commit comments

Comments
 (0)