Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public ResponseEntity<ApiResult<String>> getAuctionStatus(@PathVariable Long auc
@GetMapping
@Operation(summary = "Get all auctions", description = "Retrieves all auctions.")
@ApiResponse(responseCode = "200", description = "All auctions retrieved successfully")
public ResponseEntity<ApiResult<List<AuctionResponse>>> getAllAuctions(@RequestParam(required = false) AuctionRequest.AuctionCategoryParam auctionCategory, @RequestParam(required = false) AuctionRequest.ProductCategoryParam productCategory) {
List<AuctionResponse> auctions = auctionService.getAuctionsByFilter(productCategory, auctionCategory);
public ResponseEntity<ApiResult<List<AuctionResponse>>> getAllAuctions(@RequestBody AuctionRequest.SearchCondition searchCondition) {
List<AuctionResponse> auctions = auctionService.getAuctionsByFilter(searchCondition);
return ResponseEntity.ok(ApiResult.success(ApiResponseMessages.ALL_AUCTIONS_RETRIEVED, auctions));
}
Comment thread
polyglot-k marked this conversation as resolved.
Outdated

Comment thread
na0th marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,24 @@ public ProductCategoryParam(String productCategory) {
this.productCategory = ProductCategory.fromDisplayName(productCategory);
}
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AuctionStatusParam {
AuctionStatus auctionStatus;

public AuctionStatusParam(String auctionStatus) {
this.auctionStatus = AuctionStatus.fromDisplayName(auctionStatus);
}

}
@Getter
@AllArgsConstructor
public static class SearchCondition{
String auctionCategory;
String productCategory;
LocalDateTime endTime;
String auctionStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ public enum AuctionStatus {
PENDING,
ACTIVE,
CLOSED,
CANCELED
CANCELED;

public static AuctionStatus fromDisplayName(String auctionStatus) {
try {
return AuctionStatus.valueOf(auctionStatus.toUpperCase()); // 대문자로 변환하여 비교
} catch (IllegalArgumentException e) {
return AuctionStatus.ACTIVE; // 유효하지 않은 값일 경우 기본값으로 ACTIVE 반환
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.tasksprints.auction.domain.auction.model.AuctionCategory;
import com.tasksprints.auction.domain.auction.repository.support.AuctionCriteriaRepository;
import com.tasksprints.auction.domain.product.model.ProductCategory;
import com.tasksprints.auction.domain.auction.model.AuctionStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

Expand All @@ -24,5 +26,6 @@ public interface AuctionRepository extends JpaRepository<Auction, Long>, Auction
List<Auction> findAuctionsByAuctionCategory(AuctionCategory auctionCategory);

List<Auction> findAuctionByProduct_Category(ProductCategory productCategory);
List<Auction> findAuctionsByEndTimeBetweenAndAuctionStatusOrderByEndTimeAsc(LocalDateTime now, LocalDateTime next24Hours, AuctionStatus auctionStatus);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘도 어떻게보면, 필터 계열로 쓰일 수 있는 것이라고 생각이 듭니다. 기존 함수에서 인자 값을 추가 해주는 것은 어떨까라는 생각이 들어서 조금 아쉽습니다!!

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

import com.tasksprints.auction.domain.auction.model.Auction;
import com.tasksprints.auction.domain.auction.model.AuctionCategory;
import com.tasksprints.auction.domain.auction.model.AuctionStatus;
import com.tasksprints.auction.domain.product.model.ProductCategory;


import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

public interface AuctionCriteriaRepository {
public List<Auction> getAuctionsByFilters(ProductCategory productCategory,
AuctionCategory category);
AuctionCategory category,
LocalDateTime now,
LocalDateTime endTime,
AuctionStatus status);
//삭제해야 함
public List<Auction> getAuctionsEndWith24Hours(LocalDateTime now, LocalDateTime next24Hours, AuctionStatus auctionStatus);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 있던 것을 활용해서 되었을 것 같습니다. 인자가 많다면, 묶어서 Condition 이라는 DTO 를 통해서 연결 하면 더 좋을 듯 합니다.

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.tasksprints.auction.domain.auction.repository.support;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.tasksprints.auction.domain.auction.model.Auction;
import com.tasksprints.auction.domain.auction.model.AuctionCategory;
import com.tasksprints.auction.domain.auction.model.AuctionStatus;
import com.tasksprints.auction.domain.auction.model.QAuction;
import com.tasksprints.auction.domain.product.model.ProductCategory;
import com.tasksprints.auction.domain.product.model.QProduct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

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

@RequiredArgsConstructor
Expand All @@ -17,16 +20,39 @@ public class AuctionCriteriaRepositoryImpl implements AuctionCriteriaRepository
private final JPAQueryFactory queryFactory;

public List<Auction> getAuctionsByFilters(ProductCategory productCategory,
AuctionCategory category
AuctionCategory category,
LocalDateTime now,
LocalDateTime endTime,
AuctionStatus status
) {
QAuction auction = QAuction.auction;
QProduct product = QProduct.product;
return queryFactory.selectFrom(auction)
.leftJoin(auction.product, product) // Auction과 Product 조인
.where(category != null ? auction.auctionCategory.eq(category) : null)
.where(productCategory != null ? product.category.eq(productCategory) : null) // ProductCategory 필터
.where((now != null && endTime != null) ? auction.endTime.between(now, endTime) : null)
.where(status != null ? auction.auctionStatus.eq(status) : null)
// orderBy는 성능 이슈로 일단 보류
// .orderBy(auction.endTime.asc())
.fetch();
}


@Deprecated
@Override
public List<Auction> getAuctionsEndWith24Hours(LocalDateTime now, LocalDateTime next24Hours, AuctionStatus auctionStatus) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 사용하는 함수의 역할과 크게 차이가 나지 않는다고 생각합니다.
위의 함수를 활용해도 동일 기능을 재현할 수 있을거 같습니다.

QAuction auction = QAuction.auction;

BooleanExpression endTimeBetween = auction.endTime.between(now, next24Hours);
BooleanExpression statusEquals = auction.auctionStatus.eq(auctionStatus);

return queryFactory
.selectFrom(auction)
.where(endTimeBetween.and(statusEquals))
.orderBy(auction.endTime.asc())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order by가 성능 저하의 병목지점이 될 수 있음에 유의 해야합니다! 이에 대한 방안을 고려해보고, 최선책으로 order by를 사용해야하는 근거를 가지고 오시면 좋을 것 같습니다.!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 제가 이전에 만든 filter 함수에 합치는게 더 낫지않을까요? 충분히 합칠 수 있다고 생각이 됩니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 노력하겠습니다

.fetch();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.tasksprints.auction.domain.auction.dto.request.AuctionRequest;
import com.tasksprints.auction.domain.auction.dto.response.AuctionResponse;

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

/**
Expand All @@ -25,5 +26,10 @@ public interface AuctionService {

List<AuctionResponse> getAuctionsByAuctionCategory(AuctionRequest.AuctionCategoryParam param);

List<AuctionResponse> getAuctionsByFilter(AuctionRequest.ProductCategoryParam productCategoryParam, AuctionRequest.AuctionCategoryParam auctionCategoryParam);
List<AuctionResponse> getAuctionsByFilter(AuctionRequest.SearchCondition searchCondition);

@Deprecated
List<AuctionResponse> getAuctionsByEndTimeBetweenOrderByEndTimeAsc(LocalDateTime now, LocalDateTime next24Hours);
@Deprecated
List<AuctionResponse> getAuctionsEndWith24Hours(LocalDateTime now, LocalDateTime next24Hours);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.tasksprints.auction.domain.auction.exception.AuctionNotFoundException;
import com.tasksprints.auction.domain.auction.exception.InvalidAuctionTimeException;
import com.tasksprints.auction.domain.auction.model.Auction;
import com.tasksprints.auction.domain.auction.model.AuctionCategory;
import com.tasksprints.auction.domain.auction.model.AuctionStatus;
import com.tasksprints.auction.domain.auction.repository.AuctionRepository;
import com.tasksprints.auction.domain.user.exception.UserNotFoundException;
Expand All @@ -15,6 +16,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Service
Expand Down Expand Up @@ -127,10 +129,52 @@ public List<AuctionResponse> getAuctionsByAuctionCategory(AuctionRequest.Auction
* NULL 안정성 보장을 해줬음
**/
@Override
public List<AuctionResponse> getAuctionsByFilter(AuctionRequest.ProductCategoryParam productCategoryParam, AuctionRequest.AuctionCategoryParam auctionCategoryParam) {
public List<AuctionResponse> getAuctionsByFilter(AuctionRequest.SearchCondition searchCondition) {
LocalDateTime now = null;
//now는 endTime이 SeachCondition에 들어왔을 때만 값이 있어야 한다. (현재 시각 ~ User가 정한 시각까지 경매 목록 조회)
if (searchCondition.getEndTime() != null) {
now = LocalDateTime.now();
}

List<Auction> foundAuctions = auctionRepository.getAuctionsByFilters(
productCategoryParam != null ? productCategoryParam.getProductCategory() : null,
auctionCategoryParam != null ? auctionCategoryParam.getAuctionCategory() : null);
// productCategoryParam != null ? productCategoryParam.getProductCategory() : null,
// auctionCategoryParam != null ? auctionCategoryParam.getAuctionCategory() : null,
searchCondition.getProductCategory() !=null ? new AuctionRequest.ProductCategoryParam(searchCondition.getProductCategory()).getProductCategory() : null,
searchCondition.getAuctionCategory() != null ? new AuctionRequest.AuctionCategoryParam(searchCondition.getAuctionCategory()).getAuctionCategory() : null,
now,
searchCondition.getEndTime() != null ? searchCondition.getEndTime(): null,
searchCondition.getAuctionStatus() != null ? new AuctionRequest.AuctionStatusParam(searchCondition.getAuctionStatus()).getAuctionStatus() : null
);

return foundAuctions.stream()
.map(AuctionResponse::of)
.toList();
}

@Deprecated
@Override
public List<AuctionResponse> getAuctionsByEndTimeBetweenOrderByEndTimeAsc(LocalDateTime now, LocalDateTime next24Hours) {
// auction의 endTime까지 24시간 이하로 남은 진행중인 경매 목록 조회
//LocalDateTime now = LocalDateTime.now();
//LocalDateTime next24Hours = now.plusHours(24);

//endTime이 now ~ now + 24hour에 포함되는 진행 상태인 경매 목록 조회
List<Auction> foundAuctions = auctionRepository.findAuctionsByEndTimeBetweenAndAuctionStatusOrderByEndTimeAsc(now, next24Hours, AuctionStatus.ACTIVE);

return foundAuctions.stream()
.map(AuctionResponse::of)
.toList();
}

@Deprecated
@Override
public List<AuctionResponse> getAuctionsEndWith24Hours(LocalDateTime now, LocalDateTime next24Hours) {
// auction의 endTime까지 24시간 이하로 남은 진행중인 경매 목록 조회
// LocalDateTime now = LocalDateTime.now();
// LocalDateTime next24Hours = now.plusHours(24);

//endTime이 now ~ now + 24hour에 포함되는 진행 상태인 경매 목록 조회
List<Auction> foundAuctions = auctionRepository.getAuctionsEndWith24Hours(now, next24Hours, AuctionStatus.ACTIVE);

return foundAuctions.stream()
.map(AuctionResponse::of)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public void testFindAuctionByUsingWrongAuctionCategory_Success() throws Exceptio
.andExpect(jsonPath("$.message").value(ApiResponseMessages.ALL_AUCTIONS_RETRIEVED));
}

Comment thread
polyglot-k marked this conversation as resolved.
@Test
@DisplayName("마감 기한이 24시간 이하로 남은 경매 목록 조회")
public void testFindAuctionsEndWithin24Hours_Success() throws Exception {

/*
테스트 코드 추가
* */

}

@Test
@DisplayName("입찰 제출 성공")
public void testSubmitBid_Success() throws Exception {
Expand Down
Loading