Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…erver-v2 into develop
  • Loading branch information
mushroom1324 committed Aug 8, 2024
2 parents 135d26c + 5d9d9ed commit 582193e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.repick.domain.clothingSales.service.BoxService;
import com.example.repick.domain.clothingSales.service.ClothingSalesService;
import com.example.repick.domain.product.entity.ProductStateType;
import com.example.repick.global.page.DateCondition;
import com.example.repick.global.page.PageCondition;
import com.example.repick.global.page.PageResponse;
import com.example.repick.global.response.SuccessResponse;
Expand Down Expand Up @@ -105,8 +106,8 @@ public SuccessResponse<Boolean> updateProductPrice(@RequestBody List<PostProduct

@Operation(summary = "옷장 정리 현황")
@GetMapping("/status")
public SuccessResponse<PageResponse<List<GetClothingSales>>> getClothingSalesStatus(@ParameterObject PageCondition pageCondition) {
return SuccessResponse.success(clothingSalesService.getClothingSalesInformation(pageCondition));
public SuccessResponse<PageResponse<List<GetClothingSales>>> getClothingSalesStatus(@ParameterObject PageCondition pageCondition, @ParameterObject DateCondition dateCondition) {
return SuccessResponse.success(clothingSalesService.getClothingSalesInformation(pageCondition, dateCondition));
}

@Operation(summary = "옷장 정리 상태 업데이트")
Expand All @@ -117,8 +118,9 @@ public SuccessResponse<Boolean> updateClothingSalesStatus(@RequestBody PostCloth

@Operation(summary = "상품 종합 현황")
@GetMapping("/product-count")
public SuccessResponse<PageResponse<List<GetClothingSalesProductCount>>> getClothingSalesProductCount(@ParameterObject PageCondition pageCondition) {
return SuccessResponse.success(clothingSalesService.getClothingSalesProductCount(pageCondition));
public SuccessResponse<PageResponse<List<GetClothingSalesProductCount>>> getClothingSalesProductCount(@RequestParam(required = false) Long userId,
@ParameterObject PageCondition pageCondition) {
return SuccessResponse.success(clothingSalesService.getClothingSalesProductCount(userId, pageCondition));
}

@Operation(summary = "유저 상품 현황")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

public interface ClothingSalesRepository extends JpaRepository<ClothingSales, Long> {
Page<ClothingSales> findAllByOrderByCreatedDateDesc(Pageable pageable);
List<ClothingSales> findByUserAndClothingSalesState(User user, ClothingSalesStateType clothingSalesStateType);
Page<ClothingSales> findByCreatedDateBetweenOrderByCreatedDateDesc(LocalDateTime startDate, LocalDateTime endDate, Pageable pageable);
List<ClothingSales> findByUserOrderByCreatedDateDesc(User user);
Optional<ClothingSales> findByUserAndClothingSalesCount(User user, Integer clothingSalesCount);
int countByUser(User user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.example.repick.domain.clothingSales.entity.ClothingSales;
import com.example.repick.domain.clothingSales.entity.ClothingSalesState;
import com.example.repick.domain.clothingSales.entity.ClothingSalesStateType;
import com.example.repick.domain.clothingSales.repository.BagCollectRepository;
import com.example.repick.domain.clothingSales.repository.ClothingSalesRepository;
import com.example.repick.domain.clothingSales.repository.ClothingSalesStateRepository;
import com.example.repick.domain.clothingSales.validator.ClothingSalesValidator;
Expand All @@ -17,20 +16,22 @@
import com.example.repick.domain.user.entity.User;
import com.example.repick.domain.user.repository.UserRepository;
import com.example.repick.global.error.exception.CustomException;
import com.example.repick.global.page.DateCondition;
import com.example.repick.global.page.PageCondition;
import com.example.repick.global.page.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalTime;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.example.repick.global.error.exception.ErrorCode.*;

Expand Down Expand Up @@ -172,11 +173,23 @@ private ProductQuantityCounter countProductQuantity(List<GetProductByClothingSal
}

// Admin API
public PageResponse<List<GetClothingSales>> getClothingSalesInformation(PageCondition pageCondition){
// 수거 신청 정보 조회
Page<ClothingSales> clothingSalesPage = clothingSalesRepository.findAllByOrderByCreatedDateDesc(pageCondition.toPageable());
public PageResponse<List<GetClothingSales>> getClothingSalesInformation(PageCondition PageCondition, DateCondition dateCondition) {Page<ClothingSales> clothingSalesPage;
if (dateCondition.hasValidDateRange()) {
// 날짜 범위에 맞는 데이터 페이징 처리
LocalDateTime startDateTime = dateCondition.startDate().atStartOfDay(); // 시작일의 자정
LocalDateTime endDateTime = dateCondition.endDate().atTime(LocalTime.MAX); // 종료일의 마지막 시간
clothingSalesPage = clothingSalesRepository.findByCreatedDateBetweenOrderByCreatedDateDesc(
startDateTime, endDateTime, PageCondition.toPageable()
);
} else {
// 날짜 조건이 없으면 전체 데이터 페이징 처리
clothingSalesPage = clothingSalesRepository.findAllByOrderByCreatedDateDesc(PageCondition.toPageable());
}

List<GetClothingSales> clothingSalesList = clothingSalesPage.stream()
.map(GetClothingSales::of).toList();
.map(GetClothingSales::of)
.collect(Collectors.toList());
// 페이지 응답 반환
return PageResponse.of(clothingSalesList, clothingSalesPage.getTotalPages(), clothingSalesPage.getTotalElements());
}

Expand All @@ -196,10 +209,9 @@ public Boolean updateClothingSalesState(PostClothingSalesState postClothingSales
}

@Transactional
public PageResponse<List<GetClothingSalesProductCount>> getClothingSalesProductCount(PageCondition pageCondition) {
Page<GetClothingSalesProductCount> pages = productRepository.getClothingSalesProductCount(pageCondition.toPageable());
public PageResponse<List<GetClothingSalesProductCount>> getClothingSalesProductCount(Long userId, PageCondition pageCondition) {
Page<GetClothingSalesProductCount> pages = productRepository.getClothingSalesProductCount(pageCondition.toPageable(), userId);
return PageResponse.of(pages.getContent(), pages.getTotalPages(), pages.getTotalElements());

}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Page<GetProductThumbnail> findHighestDiscountProducts(

List<Product> findRecommendation(Long userId);

Page<GetClothingSalesProductCount> getClothingSalesProductCount(Pageable pageable);
Page<GetClothingSalesProductCount> getClothingSalesProductCount(Pageable pageable, Long userId);

Page<GetClothingSalesProduct> getClothingSalesPendingProduct(Long clothingSalesId, ProductStateType productStateType, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public List<Product> findRecommendation(Long userId) {
}

@Override
public Page<GetClothingSalesProductCount> getClothingSalesProductCount(Pageable pageable) {
public Page<GetClothingSalesProductCount> getClothingSalesProductCount(Pageable pageable, Long userId) {
JPAQuery<GetClothingSalesProductCount> query = jpaQueryFactory
.select(Projections.constructor(GetClothingSalesProductCount.class,
product.user.id.stringValue().concat("-").concat(product.clothingSalesCount.stringValue()),
Expand All @@ -395,9 +395,16 @@ public Page<GetClothingSalesProductCount> getClothingSalesProductCount(Pageable
))
.from(product)
.leftJoin(clothingSales).on(product.clothingSales.id.eq(clothingSales.id))
.groupBy(product.user.id, product.clothingSalesCount)
.groupBy(
product.clothingSales.id
)

.orderBy(clothingSales.createdDate.max().desc());

if (userId != null) {
query.where(product.user.id.eq(userId));
}

long total = query.stream().count();
List<GetClothingSalesProductCount> content = query
.offset(pageable.getOffset())
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/example/repick/global/page/DateCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.repick.global.page;

import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDate;

public record DateCondition(
@Schema(description = "검색 시작 날짜", nullable = true) LocalDate startDate,
@Schema(description = "검색 종료 날짜", nullable = true) LocalDate endDate
) {
public boolean hasValidDateRange() {
return startDate != null && endDate != null && !startDate.isAfter(endDate);
}
}

0 comments on commit 582193e

Please sign in to comment.