From 1f7a154f9042382e2e198dd2f66fa7f33f3042cb Mon Sep 17 00:00:00 2001 From: apptie Date: Tue, 7 Nov 2023 16:18:08 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20=EC=9E=85=EC=B0=B0=20=EC=84=B1?= =?UTF-8?q?=EA=B3=B5=20=EC=8B=9C=20=EC=95=8C=EB=A6=BC=20=EC=A0=84=EC=86=A1?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20Optional=20=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ddang/bid/application/BidService.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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("이미 종료된 경매입니다"); } From d600701d3485d2b32d12b350b8ec72e7b31b43a4 Mon Sep 17 00:00:00 2001 From: apptie Date: Wed, 8 Nov 2023 10:17:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EC=9E=85=EC=B0=B0=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=95=20=EC=A4=91=20=EC=98=88=EC=99=B8=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EB=A9=B4=20=EC=95=8C=EB=A6=BC=EC=9D=B4=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20=EC=8B=A4=ED=96=89=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ddang/ddang/bid/application/BidService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 287cbddad..b710d0bd8 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 @@ -51,11 +51,13 @@ public Long create(final CreateBidDto bidDto, final String auctionImageAbsoluteU checkInvalidAuction(auction); checkInvalidBid(auction, bidder, bidDto); + final Bid saveBid = saveAndUpdateLastBid(bidDto, auction, bidder); + auction.findLastBidder() .ifPresent(previousBidder -> publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder)); - return saveAndUpdateLastBid(bidDto, auction, bidder).getId(); + return saveBid.getId(); } private void publishBidNotificationEvent( From 239716c067981e3ed3fe6abda9aba134ffac421d Mon Sep 17 00:00:00 2001 From: apptie Date: Wed, 8 Nov 2023 10:47:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=EC=9E=85=EC=B0=B0=20=EA=B3=BC?= =?UTF-8?q?=EC=A0=95=20=EC=A4=91=20=EC=98=88=EC=99=B8=EA=B0=80=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=98=EB=A9=B4=20=EC=95=8C=EB=A6=BC=EC=9D=B4=20?= =?UTF-8?q?=EC=A0=84=EC=86=A1=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20=EC=8B=A4=ED=96=89=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/ddang/ddang/bid/application/BidService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 b710d0bd8..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 @@ -51,13 +51,11 @@ public Long create(final CreateBidDto bidDto, final String auctionImageAbsoluteU checkInvalidAuction(auction); checkInvalidBid(auction, bidder, bidDto); - final Bid saveBid = saveAndUpdateLastBid(bidDto, auction, bidder); - auction.findLastBidder() .ifPresent(previousBidder -> publishBidNotificationEvent(auctionImageAbsoluteUrl, auctionAndImageDto, previousBidder)); - return saveBid.getId(); + return saveAndUpdateLastBid(bidDto, auction, bidder).getId(); } private void publishBidNotificationEvent(