Skip to content

Commit

Permalink
Merge pull request #209 from SKY-HORSE-MAN-POWER/develop
Browse files Browse the repository at this point in the history
[DEPLOYMENT] 경매 대기 시간 끝나면 경매 활성화 상태가 되도록 수정
  • Loading branch information
chanchanwoong authored Jun 23, 2024
2 parents 9a0c7f1 + b531ae2 commit 8aa0a0d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface AuctionService {
void offerBiddingPrice(OfferBiddingPriceDto offerBiddingPriceDto);

void auctionClose(String auctionUuid);

void auctionStateChangeTrue(String auctionUuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.skyhorsemanpower.auction.status.AuctionStateEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -32,9 +31,6 @@
public class AuctionServiceImpl implements AuctionService {

private final AuctionHistoryRepository auctionHistoryRepository;
private final AuctionHistoryReactiveRepository auctionHistoryReactiveRepository;
private final MongoTemplate mongoTemplate;
private final RoundInfoReactiveRepository roundInfoReactiveRepository;
private final RoundInfoRepository roundInfoRepository;
private final AuctionCloseStateRepository auctionCloseStateRepository;
private final KafkaProducerCluster producer;
Expand Down Expand Up @@ -83,7 +79,6 @@ public void auctionClose(String auctionUuid) {
producer.sendMessage(Topics.AUCTION_CLOSE.getTopic(), AuctionStateEnum.AUCTION_NO_PARTICIPANTS);
return;
}
;

log.info("auction_history is exist!");

Expand Down Expand Up @@ -123,7 +118,7 @@ public void auctionClose(String auctionUuid) {
if (memberUuids.size() == numberOfParticipants) break;
}

log.info("memberUuids >>> {}", memberUuids.toString());
log.info("memberUuids >>> {}", memberUuids);

// 낙찰가는 마지막 이전 라운드에서 biddingPrice로 결정
BigDecimal price = lastMinusOneRoundAuctionHistory.get(0).getBiddingPrice();
Expand Down Expand Up @@ -157,10 +152,26 @@ public void auctionClose(String auctionUuid) {
.build());
}

@Override
public void auctionStateChangeTrue(String auctionUuid) {
RoundInfo roundInfo = roundInfoRepository.findFirstByAuctionUuidOrderByCreatedAtDesc(auctionUuid).orElseThrow(
() -> new CustomException(ResponseStatus.NO_DATA)
);

try {
RoundInfo standbyAuction = RoundInfo.setIsActiveTrue(roundInfo);
log.info("Auction Change isActive >>> {}", standbyAuction.toString());
roundInfoRepository.save(standbyAuction);
} catch (Exception e) {
throw new CustomException(ResponseStatus.MONGODB_ERROR);
}
}

private void updateRoundInfo(RoundInfo roundInfo) {
RoundInfo updatedRoundInfo;

// 다음 라운드로 round_info 도큐먼트 갱신
// isActive 대기 상태로 변경
if (roundInfo.getLeftNumberOfParticipants().equals(1L)) {
updatedRoundInfo = RoundInfo.nextRoundUpdate(roundInfo);
}
Expand Down Expand Up @@ -201,7 +212,6 @@ private void checkBiddingRound(String biddingUuid, int round) {
if (auctionHistoryRepository.findByBiddingUuidAndRound(biddingUuid, round).isPresent()) {
throw new CustomException(ResponseStatus.ALREADY_BID_IN_ROUND);
}
;
}

private void checkLeftNumberOfParticipant(Long leftNumberOfParticipants) {
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/skyhorsemanpower/auction/domain/RoundInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static RoundInfo nextRoundUpdate(RoundInfo roundInfo) {
.roundEndTime(nextRoundEndTime)
.incrementUnit(roundInfo.getIncrementUnit())
.price(nextPrice)
.isActive(true)
.isActive(false) // 대기 상태로 변경
.numberOfParticipants(roundInfo.getNumberOfParticipants())
.leftNumberOfParticipants(roundInfo.getNumberOfParticipants())
.build();
Expand All @@ -81,4 +81,19 @@ public static RoundInfo currentRoundUpdate(RoundInfo roundInfo) {
.leftNumberOfParticipants(nextNumberOfParticipants)
.build();
}

public static RoundInfo setIsActiveTrue(RoundInfo roundInfo) {
return RoundInfo.builder()
.auctionUuid(roundInfo.getAuctionUuid())
.round(roundInfo.getRound())
.roundStartTime(roundInfo.getRoundStartTime())
.roundEndTime(roundInfo.getRoundEndTime())
.incrementUnit(roundInfo.getIncrementUnit())
.price(roundInfo.getPrice())
.isActive(true)
.numberOfParticipants(roundInfo.getNumberOfParticipants())
.leftNumberOfParticipants(roundInfo.getLeftNumberOfParticipants())
.createdAt(LocalDateTime.now())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ public SuccessResponse<Object> auctionClose(
auctionService.auctionClose(auctionUuid);
return new SuccessResponse<>(null);
}

// 라운드 진행 중에서 대기 중으로 상태 변경
@PutMapping("/auction-standby-end/{auctionUuid}")
@Operation(summary = "경매 라운드 진행 API", description = "대기 시간 끝나서 라운드 진행 중으로 상태 변경")
public SuccessResponse<Object> auctionStateChangeTrue(
@PathVariable("auctionUuid") String auctionUuid) {
// round_info의 isActive를 true(진행 중)로 변경
auctionService.auctionStateChangeTrue(auctionUuid);
return new SuccessResponse<>(null);
}
}

0 comments on commit 8aa0a0d

Please sign in to comment.