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

feat : 작품 재등록 api 구현 #200

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -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<Auction> latestScheduledAuction = auctionRepository.findLatestScheduledAuction();
if (latestScheduledAuction.size() == 0) {
throw new CustomException(ErrorCode.NOT_FOUND_AUCTION_SCHEDULED);
}

List<ArtWorkImage> findArtWorkImages = artWorkImageRepository.findByArtWorkId(artWorkId);
List<ArtWorkKeyword> findArtWorkKeywords = artWorkKeywordRepository.findByArtWorkId(artWorkId);

// 기존 작품과 동일한 작품 객체 생성(현재 예정된 경매 정보만 새로 반영)
ArtWork newArtWork = reBuildNewArtWork(findArtWork, member, latestScheduledAuction);

artWorkRepository.save(newArtWork);
reRegisterArtWorkImages(findArtWorkImages, newArtWork);
reRegisterArtWorkKeywords(findArtWorkKeywords, newArtWork);
}

private void reRegisterArtWorkImages(List<ArtWorkImage> findArtWorkImages, ArtWork artWork) {

for (ArtWorkImage artWorkImage : findArtWorkImages) {
artWorkImageRepository.save(ArtWorkImage.builder().image(artWorkImage.getImage()).artWork(artWork).build());
}
}

private void reRegisterArtWorkKeywords(List<ArtWorkKeyword> 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<Auction> 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();
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,14 @@ public ResponseEntity<Void> deleteArtWork(@AuthenticationPrincipal CustomUserDet

return ResponseEntity.ok().build();
}

// 작품 재등록
@PostMapping("/{artWorkId}")
public ResponseEntity<Void> reRegisterArtWork(@AuthenticationPrincipal CustomUserDetails userDetails,
@PathVariable("artWorkId") Long artWorkId) {

artWorkService.reRegisterArtWork(userDetails.getMember(), artWorkId);

return ResponseEntity.ok().build();
}
}