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 all 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,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<User> 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();
Comment on lines +54 to +58
Copy link
Member

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.

그러네요 그 부분은 놓쳤습니다
순서를 변경하도록 하겠습니다

}

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