-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] : 경매 입찰 종료 시 스케줄러로 경매, 입찰 상태 변경 (#107)
* [feat] : 경매 최근 waiting 상태 bidding 조회 동적 쿼리 추가 * [test] : test auditing config 추가 * [test] : 경매 최근 waiting 상태 bidding 조회 동적 쿼리 추가 테스트 * [feat] : 변경된 메서드 서비스 로직에 반영 * [test] : 변경된 메서드 서비스 테스트에 반영 * [test] : 거래 취소 통합 테스트 구체화 * [refactor] : 불필요한 로직 삭제 * [feat] : 입찰 최초 생성 시 입찰 상태 바꾸는 로직 삭제 * [refactor] : 불필요한 로직 삭제 * [feat] : 마감일 지난 경매 최근 입찰 상태 준비중으로 변경 동적 쿼리 추가 * [test] : 마감일이 지난 경매의 최근 입찰 상태 준비중으로 변경 동적 쿼리 테스트 * [feat] : 입찰 종료시 최근 입찰 상태 준비중으로 변경 스케줄러 추가 * [feat] : 벌크 연산 jpql -> 동적 쿼리로 수정 * [test] : 벌크 연산 jpql -> 동적 쿼리로 수정 테스트 반영 * [feat] : auction 상태 완료 로직 추가 * [feat] : 거래 완료 시 Auction 상태 변경 로직 추가 * [test] : 거래 완료 시 Auction 상태 변경 로직 테스트 반영 * [style] : 코드 리포멧팅 * [refactor] : 교체로 안 쓰는 로직 삭제 * [feat] : 스케줄러에 경매 상태 변경 동적 쿼리 반영 * [test] : 테스트에 경매 상태 변경 동적 쿼리 반영
- Loading branch information
Showing
18 changed files
with
314 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
core/src/main/java/dev/handsup/auction/repository/auction/AuctionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,17 @@ | ||
package dev.handsup.auction.repository.auction; | ||
|
||
import java.time.LocalDate; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import dev.handsup.auction.domain.Auction; | ||
import dev.handsup.auction.domain.auction_field.AuctionStatus; | ||
import dev.handsup.user.domain.User; | ||
|
||
public interface AuctionRepository extends JpaRepository<Auction, Long> { | ||
Boolean existsByStatus(AuctionStatus status); | ||
|
||
@Query("select distinct b.auction from Bookmark b " + | ||
"where b.user = :user") | ||
Slice<Auction> findBookmarkAuction(@Param("user") User user, Pageable pageable); | ||
|
||
@Transactional | ||
@Modifying(clearAutomatically = true) | ||
@Query("update Auction a set a.status = :newStatus " | ||
+ "where a.status = :currentStatus and a.endDate < :todayDate") | ||
void updateAuctionStatus( | ||
@Param("currentStatus") AuctionStatus currentStatus, | ||
@Param("newStatus") AuctionStatus newStatus, | ||
@Param("todayDate") LocalDate todayDate | ||
); | ||
} |
11 changes: 3 additions & 8 deletions
11
core/src/main/java/dev/handsup/auction/scheduler/AuctionScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
package dev.handsup.auction.scheduler; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDate; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import dev.handsup.auction.domain.auction_field.AuctionStatus; | ||
import dev.handsup.auction.repository.auction.AuctionRepository; | ||
import dev.handsup.auction.repository.auction.AuctionQueryRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class AuctionScheduler { | ||
private final AuctionRepository auctionRepository; | ||
private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); | ||
private final AuctionQueryRepository auctionQueryRepository; | ||
|
||
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") | ||
public void updateAuctionStatus() { | ||
auctionRepository.updateAuctionStatus(AuctionStatus.BIDDING, AuctionStatus.TRADING, LocalDate.now()); | ||
auctionQueryRepository.updateAuctionStatusTrading(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/dev/handsup/bidding/repository/BiddingQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.handsup.bidding.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import dev.handsup.auction.domain.Auction; | ||
import dev.handsup.bidding.domain.Bidding; | ||
|
||
public interface BiddingQueryRepository { | ||
|
||
Optional<Bidding> findWaitingBiddingLatest(Auction auction); | ||
|
||
void updateBiddingTradingStatus(); | ||
} |
57 changes: 57 additions & 0 deletions
57
core/src/main/java/dev/handsup/bidding/repository/BiddingQueryRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package dev.handsup.bidding.repository; | ||
|
||
import static dev.handsup.bidding.domain.QBidding.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import dev.handsup.auction.domain.Auction; | ||
import dev.handsup.auction.domain.QAuction; | ||
import dev.handsup.bidding.domain.Bidding; | ||
import dev.handsup.bidding.domain.QBidding; | ||
import dev.handsup.bidding.domain.TradingStatus; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BiddingQueryRepositoryImpl implements BiddingQueryRepository { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Optional<Bidding> findWaitingBiddingLatest(Auction auction) { | ||
Bidding bidding = queryFactory.select(QBidding.bidding) | ||
.from(QBidding.bidding) | ||
.where( | ||
QAuction.auction.eq(auction), | ||
QBidding.bidding.tradingStatus.eq(TradingStatus.WAITING) | ||
) | ||
.orderBy(QBidding.bidding.createdAt.desc()) | ||
.fetchFirst(); | ||
return Optional.ofNullable(bidding); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void updateBiddingTradingStatus() { | ||
//하루 지난 각 경매들에 대한 최신 입찰 조회 | ||
List<Long> latestBiddingIdsPerAuctions = queryFactory | ||
.select(bidding.id.max()) | ||
.from(bidding) | ||
.where(bidding.auction.endDate.eq(LocalDate.now().minusDays(1))) | ||
.groupBy(bidding.auction) | ||
.fetch(); | ||
|
||
// 해당 최신 입찰 상태를 준비중으로 업데이트 | ||
queryFactory | ||
.update(bidding) | ||
.set(bidding.tradingStatus, TradingStatus.PREPARING) | ||
.where(bidding.id.in(latestBiddingIdsPerAuctions)) | ||
.execute(); | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
core/src/main/java/dev/handsup/bidding/repository/BiddingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
package dev.handsup.bidding.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import dev.handsup.bidding.domain.Bidding; | ||
import dev.handsup.bidding.domain.TradingStatus; | ||
|
||
public interface BiddingRepository extends JpaRepository<Bidding, Long> { | ||
|
||
@Query("SELECT MAX(b.biddingPrice) FROM Bidding b WHERE b.auction.id = :auctionId") | ||
Integer findMaxBiddingPriceByAuctionId(Long auctionId); | ||
|
||
Slice<Bidding> findByAuctionIdOrderByBiddingPriceDesc(Long auctionId, Pageable pageable); | ||
|
||
Optional<Bidding> findFirstByTradingStatus(TradingStatus tradingStatus); | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/java/dev/handsup/bidding/scheduler/BiddingScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.handsup.bidding.scheduler; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import dev.handsup.bidding.repository.BiddingQueryRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class BiddingScheduler { | ||
|
||
private BiddingQueryRepository biddingQueryRepository; | ||
|
||
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul") | ||
public void updateTradingStatus() { | ||
biddingQueryRepository.updateBiddingTradingStatus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.