From 21d815cdb84657adb136c03091e82ab97745c4a4 Mon Sep 17 00:00:00 2001 From: JunYong Sun Date: Sat, 20 Jan 2024 13:49:21 +0900 Subject: [PATCH] =?UTF-8?q?[TEST]=20=EC=A2=85=EB=A3=8C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auctionservice/facade/BidFacade.java | 11 +++++++-- .../service/AuctionService.java | 23 +++++++++---------- 2 files changed, 20 insertions(+), 14 deletions(-) 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)); + }); } }