diff --git a/src/main/java/com/dailyon/auctionservice/facade/BidFacade.java b/src/main/java/com/dailyon/auctionservice/facade/BidFacade.java index addc31f..1e35b96 100644 --- a/src/main/java/com/dailyon/auctionservice/facade/BidFacade.java +++ b/src/main/java/com/dailyon/auctionservice/facade/BidFacade.java @@ -54,7 +54,14 @@ public Mono start(String auctionId) { } public Mono end(String auctionId) { - ChatPayload payload = ChatPayload.of(ChatCommand.AUCTION_CLOSE, null); - return auctionService.endAuction(auctionId).flatMap(auction -> chatHandler.broadCast(payload)); + + return auctionService + .endAuction(auctionId) + .flatMap( + auction -> { + ChatPayload payload = ChatPayload.of(ChatCommand.AUCTION_CLOSE, null); + chatHandler.broadCast(payload); + return Mono.empty(); + }); } } diff --git a/src/main/java/com/dailyon/auctionservice/service/AuctionService.java b/src/main/java/com/dailyon/auctionservice/service/AuctionService.java index 60f114f..cdc7a1a 100644 --- a/src/main/java/com/dailyon/auctionservice/service/AuctionService.java +++ b/src/main/java/com/dailyon/auctionservice/service/AuctionService.java @@ -161,17 +161,16 @@ public Mono startAuction(String auctionId) { } public Mono 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)); + }); } }