From eb2588d1169200886c6ee73bd9f1a9e4d3860e1a Mon Sep 17 00:00:00 2001 From: "sgb8170@naver.com" Date: Tue, 28 Feb 2023 17:53:08 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=9E=91=ED=92=88=20=EC=9E=AC?= =?UTF-8?q?=EB=93=B1=EB=A1=9D=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../art_work/service/ArtWorkService.java | 64 +++++++++++++++++++ .../art_work/web/ArtWorkController.java | 10 +++ 2 files changed, 74 insertions(+) diff --git a/src/main/java/com/sptp/backend/art_work/service/ArtWorkService.java b/src/main/java/com/sptp/backend/art_work/service/ArtWorkService.java index d8db1692..e64d49d9 100644 --- a/src/main/java/com/sptp/backend/art_work/service/ArtWorkService.java +++ b/src/main/java/com/sptp/backend/art_work/service/ArtWorkService.java @@ -592,4 +592,68 @@ public void deleteArtWork(Member member, Long artWorkId) { artWorkRepository.deleteById(artWorkId); } + + public void reRegisterArtWork(Member member, Long artWorkId) { + + // 작품 존재하는지 체크 + ArtWork findArtWork = artWorkRepository.findById(artWorkId) + .orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ARTWORK)); + + // 글쓴 당사자가 맞는지 체크 + if (!findArtWork.getMember().getId().equals(member.getId())) { + throw new CustomException(ErrorCode.PERMISSION_DENIED); + } + + // 예정된 경매가 있는지 체크 + List latestScheduledAuction = auctionRepository.findLatestScheduledAuction(); + if (latestScheduledAuction.size() == 0) { + throw new CustomException(ErrorCode.NOT_FOUND_AUCTION_SCHEDULED); + } + + List findArtWorkImages = artWorkImageRepository.findByArtWorkId(artWorkId); + List findArtWorkKeywords = artWorkKeywordRepository.findByArtWorkId(artWorkId); + + // 기존 작품과 동일한 작품 객체 생성(현재 예정된 경매 정보만 새로 반영) + ArtWork newArtWork = reBuildNewArtWork(findArtWork, member, latestScheduledAuction); + + artWorkRepository.save(newArtWork); + reRegisterArtWorkImages(findArtWorkImages, newArtWork); + reRegisterArtWorkKeywords(findArtWorkKeywords, newArtWork); + } + + private void reRegisterArtWorkImages(List findArtWorkImages, ArtWork artWork) { + + for (ArtWorkImage artWorkImage : findArtWorkImages) { + artWorkImageRepository.save(ArtWorkImage.builder().image(artWorkImage.getImage()).artWork(artWork).build()); + } + } + + private void reRegisterArtWorkKeywords(List findArtWorkKeywords, ArtWork artWork) { + + for (ArtWorkKeyword artWorkKeyword : findArtWorkKeywords) { + artWorkKeywordRepository.save(ArtWorkKeyword.builder().keywordId(artWorkKeyword.getKeywordId()).artWork(artWork).build()); + } + } + + private ArtWork reBuildNewArtWork(ArtWork findArtWork, Member member, List latestScheduledAuction) { + + return ArtWork.builder() + .member(member) + .title(findArtWork.getTitle()) + .material(findArtWork.getMaterial()) + .price(findArtWork.getPrice()) + .status(findArtWork.getStatus()) + .statusDescription(findArtWork.getStatusDescription()) + .guaranteeImage(findArtWork.getGuaranteeImage()) + .mainImage(findArtWork.getMainImage()) + .genre(findArtWork.getGenre()) + .artWorkSize(findArtWork.getArtWorkSize()) + .frame(findArtWork.isFrame()) + .description(findArtWork.getDescription()) + .productionYear(findArtWork.getProductionYear()) + .auction(latestScheduledAuction.get(0)) + .saleStatus(ArtWorkStatus.REGISTERED.getType()) + .biddingList(new ArrayList<>()) + .build(); + } } diff --git a/src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java b/src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java index 3881ab1c..53bf165d 100644 --- a/src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java +++ b/src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java @@ -114,4 +114,14 @@ public ResponseEntity deleteArtWork(@AuthenticationPrincipal CustomUserDet return ResponseEntity.ok().build(); } + + // 작품 재등록 + @PostMapping("/{artWorkId}") + public ResponseEntity reRegisterArtWork(@AuthenticationPrincipal CustomUserDetails userDetails, + @PathVariable("artWorkId") Long artWorkId) { + + artWorkService.reRegisterArtWork(userDetails.getMember(), artWorkId); + + return ResponseEntity.ok().build(); + } }