diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/domain/Auction.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/domain/Auction.java index 5d8025753..af22792ea 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/domain/Auction.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/domain/Auction.java @@ -191,4 +191,8 @@ public Optional findLastBidder() { return Optional.of(lastBid.getBidder()); } + + public Optional findLastBid() { + return Optional.ofNullable(lastBid); + } } 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..044bf3b2f 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 @@ -87,18 +87,18 @@ private void checkInvalidAuction(final Auction auction) { } private void checkInvalidBid(final Auction auction, final User bidder, final CreateBidDto bidDto) { - final Optional lastBid = bidRepository.findLastBidByAuctionId(bidDto.auctionId()); - final BidPrice bidPrice = processBidPrice(bidDto.bidPrice()); - checkIsSeller(auction, bidder); - if (lastBid.isPresent()) { - checkIsNotLastBidder(lastBid.get(), bidder); - checkInvalidBidPrice(lastBid.get(), bidPrice); - return; - } + final BidPrice bidPrice = processBidPrice(bidDto.bidPrice()); - checkInvalidFirstBidPrice(auction, bidPrice); + auction.findLastBid() + .ifPresentOrElse( + lastBid -> { + checkIsNotLastBidder(lastBid, bidder); + checkInvalidBidPrice(lastBid, bidPrice); + }, + () -> checkInvalidFirstBidPrice(auction, bidPrice) + ); } private BidPrice processBidPrice(final int value) {