Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

입찰 시 이전 사용자에게 알림을 보낼 때 Optional 로직 변경 #735

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,36 @@ 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<User> previousBidder = auction.findLastBidder();

final Bid saveBid = saveAndUpdateLastBid(bidDto, auction, bidder);

publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder);
auction.findLastBidder()
.ifPresent(previousBidder ->
publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필수

saveAndUpdateLastBid()를 수행하고 나서 findLastBidder()를 하게 되면 saveAndUpdateLastBid()를 수행해서 lastBidder가 바뀐 뒤에 findLastBidder()가 수행되게 됩니다. 그러면 알림 대상이 이전 입찰자가 아니라 현재 입찰하고 있는 사람이 되기 때문에 findLastBidder()를 하고 나서 saveAndUpadateLastBid()를 해주어야 합니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러네요 요 부분은 또 놓쳤네요
좀 더 고민을 해보겠습니다

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

헐 그러네요 엔초........
왜 저는 이걸 생각 못했을까요..?
엔초 진짜 멋지다..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제이미의 리뷰 적용 전으로 롤백했습니다


return saveBid.getId();
}

private void publishBidNotificationEvent(
final String auctionImageAbsoluteUrl,
final AuctionAndImageDto auctionAndImageDto,
final Optional<User> 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("이미 종료된 경매입니다");
}
Expand Down
Loading