From 92efab8912449320a6c96087961bf74f61da53b9 Mon Sep 17 00:00:00 2001 From: Jong1 <44349716+donsonioc2010@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:31:41 +0900 Subject: [PATCH] Merge branch 'dev' into feat/52-bid-history (#73) # Conflicts: # Api/src/main/java/picasso/server/api/auction/controller/PictureBidHistoryRestController.java # Api/src/main/java/picasso/server/api/auction/service/PictureBidHistoryService.java # Domain/src/main/java/picasso/server/domain/domains/picture/repository/PictureBidHistoryRepository.java --- .../api/admin/service/AdminService.java | 3 + .../scheduler/EndAuctionScheduler.java | 1 - .../scheduler/StartAuctionScheduler.java | 5 +- .../api/auction/service/PictureService.java | 9 +- .../server/api/mail/MailPathConstants.java | 8 -- .../api/mail/service/SendMailService.java | 67 +++++++---- .../main/resources/templates/imageList.html | 105 +++++------------- .../templates/mail/approve-picture-mail.html | 4 +- .../domains/picture/items/PictureInfo.java | 2 + .../user/repository/UserRepository.java | 1 - 10 files changed, 89 insertions(+), 116 deletions(-) diff --git a/Api/src/main/java/picasso/server/api/admin/service/AdminService.java b/Api/src/main/java/picasso/server/api/admin/service/AdminService.java index 2cbefb4a..b9a22458 100644 --- a/Api/src/main/java/picasso/server/api/admin/service/AdminService.java +++ b/Api/src/main/java/picasso/server/api/admin/service/AdminService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import picasso.server.api.admin.exception.AlreadyChangePictureException; +import picasso.server.api.mail.service.SendMailService; import picasso.server.common.exception.NotFoundException; import picasso.server.domain.domains.picture.items.Picture; import picasso.server.domain.domains.picture.repository.PictureRepository; @@ -25,6 +26,7 @@ public class AdminService { private final PictureRepository pictureRepository; private final UserRepository userRepository; + private final SendMailService sendMailService; // TODO : 추후 Pagenation으로의 수정 필요함. @Transactional(readOnly = true) @@ -56,6 +58,7 @@ public void approvePicture(Long pictureId) { pictureRepository.save(picture); log.info("ApprovePicture Success >>> Picture Id : {}, Title : {}", picture.getPictureId(), picture.getPictureName()); + sendMailService.adminApproveMail(picture); return; } log.warn("ApprovePicture Failure >>> Picture Id : {}, Title : {}", diff --git a/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java b/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java index b7c37243..3c2eb436 100644 --- a/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java +++ b/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java @@ -47,7 +47,6 @@ public void startAuction() { } } ); - pictureService.saveAllPictureList(todayEndPictursList); log.info("Today End Auctions Schedule End Time >>> {}", LocalDateTime.now()); } diff --git a/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java b/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java index 440f4dda..c2148b0f 100644 --- a/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java +++ b/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java @@ -14,6 +14,7 @@ import java.time.LocalDateTime; import static picasso.server.domain.domains.picture.items.PictureStatus.AFTER_APPROVE; +import static picasso.server.domain.domains.picture.items.PictureStatus.BEFORE_APPROVE; import static picasso.server.domain.domains.picture.items.PictureStatus.BIDDING; /** @@ -33,7 +34,7 @@ public class StartAuctionScheduler { public void startApprovePictureToBiddingAuction() { log.info("Start Todays Auctions Open Schedule Runtime : NowTime >>> {}", LocalDateTime.now()); pictureService - .changePictureStatusByPictureStatusAndBidEndDate(AFTER_APPROVE, BIDDING, LocalDate.now()) + .changePictureStatusByPictureStatusAndBidStartDate(AFTER_APPROVE, BIDDING, LocalDate.now()) .forEach(sendMailService::startBiddingMail); log.info("End Todays Auctions Open Schedule Runtime : NowTime >>> {}", LocalDateTime.now()); } @@ -44,7 +45,7 @@ public void startApprovePictureToBiddingAuction() { public void startNotApprovePictureToRejectAuction() { log.info("Start Reject Picture Schedule Runtime : NowTime >>> {}", LocalDateTime.now()); pictureService - .changePictureStatusByPictureStatusAndBidEndDate(AFTER_APPROVE, BIDDING, LocalDate.now()) + .changePictureStatusByPictureStatusAndBidStartDate(BEFORE_APPROVE, BIDDING, LocalDate.now()) .forEach(sendMailService::pictureRejectMailWithNotApproveAdmin); log.info("End Todays Auctions Open Schedule Runtime : NowTime >>> {}", LocalDateTime.now()); } diff --git a/Api/src/main/java/picasso/server/api/auction/service/PictureService.java b/Api/src/main/java/picasso/server/api/auction/service/PictureService.java index 0faa7472..5effa84c 100644 --- a/Api/src/main/java/picasso/server/api/auction/service/PictureService.java +++ b/Api/src/main/java/picasso/server/api/auction/service/PictureService.java @@ -1,18 +1,19 @@ package picasso.server.api.auction.service; -import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import picasso.server.domain.domains.picture.items.Picture; import picasso.server.domain.domains.picture.items.PictureInfo; import picasso.server.domain.domains.picture.items.PictureStatus; import picasso.server.domain.domains.picture.repository.PictureRepository; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -54,6 +55,9 @@ private PictureInfo mapToPictureInfo(Picture picture) { pictureInfo.setStartPrice(picture.getStartingPrice()); pictureInfo.setIncrementAmount(picture.getIncrementAmount()); pictureInfo.setEndDay(picture.getBidEndDate()); + pictureInfo.setStartDate(picture.getBidStartDate().format(DateTimeFormatter.ofPattern("yy/MM/dd"))); + pictureInfo.setEndDate(picture.getBidEndDate().format(DateTimeFormatter.ofPattern("yy/MM/dd"))); + return pictureInfo; } @@ -92,6 +96,7 @@ public List changePictureStatusByPictureStatusAndBidStartDate(PictureSt * @param bidEndDate 찾아야 하는 경매 종료 일자 * @return Picture List를 반환한다. */ + @Transactional(readOnly = true) public List changePictureStatusByPictureStatusAndBidEndDate(PictureStatus searchStatus, PictureStatus updateStatus, LocalDate bidEndDate) { List result = pictureRepository .findAllByPictureStatusAndBidEndDate(searchStatus, bidEndDate); @@ -100,7 +105,7 @@ public List changePictureStatusByPictureStatusAndBidEndDate(PictureStat return result; } - @org.springframework.transaction.annotation.Transactional(readOnly = true) + @Transactional(readOnly = true) public List findPictureStatusByStatusAndBidEndDate(PictureStatus searchStatus, LocalDate bidEndDate) { return pictureRepository .findAllByPictureStatusAndBidEndDate(searchStatus, bidEndDate); diff --git a/Api/src/main/java/picasso/server/api/mail/MailPathConstants.java b/Api/src/main/java/picasso/server/api/mail/MailPathConstants.java index d662f8f4..2f1f57e9 100644 --- a/Api/src/main/java/picasso/server/api/mail/MailPathConstants.java +++ b/Api/src/main/java/picasso/server/api/mail/MailPathConstants.java @@ -15,13 +15,5 @@ public class MailPathConstants { // 경매 시작 안내 메일 public static final String PICTURE_BIDDING_MAIL = "mail/bidding-picture-mail"; - /*TODO : 시간 될 떄 추가구현!*/ - // 게시물 관리자 승인 안내 메일 public static final String PICTURE_APPROVE_MAIL = "mail/approve-picture-mail"; - - // 입찰자 추가 발생 안내 ( 판매자 ) - public static final String PICTURE_NEW_BID_SELLER_MAIL = "mail/new-bid-picture-mail-seller"; - - // 입찰자 추가 발생 안내 ( 구매자 ) - public static final String PICTURE_NEW_BID_BUYER_MAIL = "mail/new-bid-picture-mail-buyer"; } diff --git a/Api/src/main/java/picasso/server/api/mail/service/SendMailService.java b/Api/src/main/java/picasso/server/api/mail/service/SendMailService.java index 0bba6f54..02e033f4 100644 --- a/Api/src/main/java/picasso/server/api/mail/service/SendMailService.java +++ b/Api/src/main/java/picasso/server/api/mail/service/SendMailService.java @@ -5,17 +5,23 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import picasso.server.common.exception.NotFoundException; import picasso.server.common.mail.SendMailUtil; import picasso.server.common.properties.PicassoProperties; import picasso.server.domain.domains.picture.items.Picture; +import picasso.server.domain.domains.picture.items.PictureBidHistory; +import picasso.server.domain.domains.picture.repository.PictureBidHistoryRepository; import java.util.HashMap; +import static picasso.server.api.mail.MailPathConstants.PICTURE_APPROVE_MAIL; import static picasso.server.api.mail.MailPathConstants.PICTURE_BIDDING_MAIL; import static picasso.server.api.mail.MailPathConstants.PICTURE_NOT_APPROVE_REJECT_MAIL; import static picasso.server.api.mail.MailPathConstants.PICTURE_NO_BID_REJECT_MAIL; +import static picasso.server.api.mail.MailPathConstants.PICTURE_SUCCESSBID_MAIL; import static picasso.server.api.mail.MailTitleConstant.BIDDING; import static picasso.server.api.mail.MailTitleConstant.REJECT; +import static picasso.server.api.mail.MailTitleConstant.SUCCESS_BID; /** * 모든 메일 발송에 대한 기능은 해당 Service에서 담당하여 발송합니다 @@ -28,6 +34,7 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class SendMailService { + private final PictureBidHistoryRepository pictureBidHistoryRepository; private final SendMailUtil sendMailUtil; private final PicassoProperties picassoProperties; @@ -39,12 +46,12 @@ public class SendMailService { @Async public void adminApproveMail(Picture picture) { sendMailUtil.sendMail( - "donsonic@naver.com", + picture.getUser().getEmail(), REJECT.getMailTitle(), - PICTURE_NOT_APPROVE_REJECT_MAIL, + PICTURE_APPROVE_MAIL, new HashMap<>() {{ put("pictureName", picture.getPictureName()); - put("bidEndDate", picture.getBidEndDate().toString()); + put("startBidDate", picture.getBidStartDate().toString()); put("link", picassoProperties.getDomain() + "pictures/" + picture.getPictureId()); }} ); @@ -58,7 +65,7 @@ public void adminApproveMail(Picture picture) { @Async public void startBiddingMail(Picture picture) { sendMailUtil.sendMail( - "donsonic@naver.com", + picture.getUser().getEmail(), BIDDING.getMailTitle(), PICTURE_BIDDING_MAIL, new HashMap<>() {{ @@ -69,18 +76,6 @@ public void startBiddingMail(Picture picture) { ); } - - /** - * 경매 새로운 입찰이 발생하는 경우 경매 물품 등록자, 입찰자한테 메일을 발송하는 기능 - * - * @param picture - */ - @Async - public void newBidMail(Picture picture) { - - } - - /** * 등록한 미술품이 기간이 모두 종료되고, 낙찰자가 존해자여 낙찰자, 등록자한테 메일 발송 * @@ -88,7 +83,32 @@ public void newBidMail(Picture picture) { */ @Async public void pictureSuccessBidMail(Picture picture) { + PictureBidHistory topHistory = pictureBidHistoryRepository.findTopByPictureOrderByBidAmountDesc(picture) + .orElseThrow(() -> NotFoundException.EXCEPTION); + + //등록자 한테 한테 메일 발송 + sendMailUtil.sendMail( + picture.getUser().getEmail(), + SUCCESS_BID.getMailTitle(), + PICTURE_SUCCESSBID_MAIL, + new HashMap<>() {{ + put("pictureName", picture.getPictureName()); + put("bidAmount", topHistory.getBidAmount()); + put("link", picassoProperties.getDomain() + "pictures/" + picture.getPictureId()); + }} + ); + // 낙찰자한테 메일 발송 + sendMailUtil.sendMail( + topHistory.getUser().getEmail(), + SUCCESS_BID.getMailTitle(), + PICTURE_SUCCESSBID_MAIL, + new HashMap<>() {{ + put("pictureName", picture.getPictureName()); + put("bidAmount", topHistory.getBidAmount()); + put("link", picassoProperties.getDomain() + "pictures/" + picture.getPictureId()); + }} + ); } /** @@ -98,7 +118,15 @@ public void pictureSuccessBidMail(Picture picture) { */ @Async public void pictureRejectMailWithNotApproveAdmin(Picture picture) { - + sendMailUtil.sendMail( + picture.getUser().getEmail(), + REJECT.getMailTitle(), + PICTURE_NOT_APPROVE_REJECT_MAIL, + new HashMap<>() {{ + put("pictureName", picture.getPictureName()); + put("link", picassoProperties.getDomain() + "pictures/" + picture.getPictureId()); + }} + ); } /** @@ -109,16 +137,13 @@ public void pictureRejectMailWithNotApproveAdmin(Picture picture) { @Async public void pictureRejectMailWithFinishDate(Picture picture) { sendMailUtil.sendMail( - "donsonic@naver.com", + picture.getUser().getEmail(), REJECT.getMailTitle(), PICTURE_NO_BID_REJECT_MAIL, new HashMap<>() {{ put("pictureName", picture.getPictureName()); - put("bidEndDate", picture.getBidEndDate().toString()); put("link", picassoProperties.getDomain() + "pictures/" + picture.getPictureId()); }} ); } - - } diff --git a/Api/src/main/resources/templates/imageList.html b/Api/src/main/resources/templates/imageList.html index f8262116..f7d2ad42 100644 --- a/Api/src/main/resources/templates/imageList.html +++ b/Api/src/main/resources/templates/imageList.html @@ -1,77 +1,16 @@ - + +
+ - - - - - 경매 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
+
@@ -80,12 +19,17 @@ class="card-img-top" alt="Picture">
-
-

Details:

-

Painter Name:

-

Starting Price:

-

Increment Amount:

-

경매 종료 날짜:

+
+ +
+ +
+
+
+ ~ + +
+
@@ -94,7 +38,7 @@
-
+ - + + \ No newline at end of file diff --git a/Api/src/main/resources/templates/mail/approve-picture-mail.html b/Api/src/main/resources/templates/mail/approve-picture-mail.html index 1d9af4db..61db6f8c 100644 --- a/Api/src/main/resources/templates/mail/approve-picture-mail.html +++ b/Api/src/main/resources/templates/mail/approve-picture-mail.html @@ -39,7 +39,7 @@ 등록하신 작품명 물품이 경매 승인되었습니다.
- 경매 시작일은 09:00시에 경매가 진행될 예정입니다. + 경매 시작일은 09:00시에 경매가 진행될 예정입니다. @@ -48,7 +48,7 @@ - 게시물 바로가기 diff --git a/Domain/src/main/java/picasso/server/domain/domains/picture/items/PictureInfo.java b/Domain/src/main/java/picasso/server/domain/domains/picture/items/PictureInfo.java index 284bc0bf..2053b36d 100644 --- a/Domain/src/main/java/picasso/server/domain/domains/picture/items/PictureInfo.java +++ b/Domain/src/main/java/picasso/server/domain/domains/picture/items/PictureInfo.java @@ -16,4 +16,6 @@ public class PictureInfo { private Integer startPrice; private Integer incrementAmount; private LocalDate endDay; + private String startDate; + private String endDate; } diff --git a/Domain/src/main/java/picasso/server/domain/domains/user/repository/UserRepository.java b/Domain/src/main/java/picasso/server/domain/domains/user/repository/UserRepository.java index ffd7a7eb..1f58e232 100644 --- a/Domain/src/main/java/picasso/server/domain/domains/user/repository/UserRepository.java +++ b/Domain/src/main/java/picasso/server/domain/domains/user/repository/UserRepository.java @@ -12,7 +12,6 @@ public interface UserRepository extends JpaRepository { List findByUserRole(UserRole userRole); - Optional findByEmail(String email); Optional findByEmailAndPassword(String email, String password);