diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/BidService.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/BidService.java index d2c6a4e97..287cbddad 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/BidService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/BidService.java @@ -47,37 +47,34 @@ public Long create(final CreateBidDto bidDto, final String auctionImageAbsoluteU .orElseThrow(() -> new AuctionNotFoundException("해당 경매를 찾을 수 없습니다.")); final Auction auction = auctionAndImageDto.auction(); + checkInvalidAuction(auction); checkInvalidBid(auction, bidder, bidDto); - final Optional previousBidder = auction.findLastBidder(); - - final Bid saveBid = saveAndUpdateLastBid(bidDto, auction, bidder); + auction.findLastBidder() + .ifPresent(previousBidder -> + publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder)); - publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder); - - return saveBid.getId(); + return saveAndUpdateLastBid(bidDto, auction, bidder).getId(); } private void publishBidNotificationEvent( final String auctionImageAbsoluteUrl, final AuctionAndImageDto auctionAndImageDto, - final Optional previousBidder + final User previousBidder ) { - if (previousBidder.isEmpty()) { - return; - } - final BidDto bidDto = new BidDto( - previousBidder.get().getId(), + previousBidder.getId(), auctionAndImageDto, auctionImageAbsoluteUrl ); + bidEventPublisher.publishEvent(new BidNotificationEvent(bidDto)); } private void checkInvalidAuction(final Auction auction) { final LocalDateTime now = LocalDateTime.now(); + if (auction.isClosed(now)) { throw new InvalidAuctionToBidException("이미 종료된 경매입니다"); }