Skip to content

Commit

Permalink
refactor: 입찰 시 입찰하고자 하는 내용이 유효한지 검증하는 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonyj1022 committed Nov 22, 2023
1 parent 25c0e46 commit 8b0526d
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -84,18 +83,18 @@ private void checkInvalidAuction(final Auction auction) {
}

private void checkInvalidBid(final Auction auction, final User bidder, final CreateBidDto bidDto) {
final Optional<Bid> 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) {
Expand Down

0 comments on commit 8b0526d

Please sign in to comment.