Skip to content

Commit

Permalink
[TEST] 종료 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjy4974 committed Jan 20, 2024
1 parent b608b63 commit 21d815c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/dailyon/auctionservice/facade/BidFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ public Mono<Void> start(String auctionId) {
}

public Mono<Void> end(String auctionId) {
ChatPayload<Object> payload = ChatPayload.of(ChatCommand.AUCTION_CLOSE, null);
return auctionService.endAuction(auctionId).flatMap(auction -> chatHandler.broadCast(payload));

return auctionService
.endAuction(auctionId)
.flatMap(
auction -> {
ChatPayload<Object> payload = ChatPayload.of(ChatCommand.AUCTION_CLOSE, null);
chatHandler.broadCast(payload);
return Mono.empty();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,16 @@ public Mono<Auction> startAuction(String auctionId) {
}

public Mono<Auction> endAuction(String auctionId) {
Auction auction =
auctionRepository
.findById(auctionId)
.orElseThrow(() -> new RuntimeException("존재하지 않는 경매입니다"));

// 아직 시작하지 않았거나, 이미 끝난 경매라면 종료 불가능
if (!auction.isStarted() || auction.isEnded()) {
throw new RuntimeException("종료 가능한 상태가 아닙니다");
}

auction.setEnded(true);
return Mono.just(auctionRepository.save(auction));
return Mono.justOrEmpty(auctionRepository.findById(auctionId))
.switchIfEmpty(Mono.error(new RuntimeException("존재하지 않는 경매입니다")))
.flatMap(
auction -> {
// 아직 시작 가능 시간 전이라면 시작 불가
if (!auction.isStarted() || auction.isEnded()) {
return Mono.error(new RuntimeException("종료 가능한 상태가 아닙니다"));
}
auction.setEnded(true);
return Mono.justOrEmpty(auctionRepository.save(auction));
});
}
}

0 comments on commit 21d815c

Please sign in to comment.