diff --git a/src/main/java/org/rf/rfserver/party/controller/PartyController.java b/src/main/java/org/rf/rfserver/party/controller/PartyController.java index f8e1eb5..d38fbfc 100644 --- a/src/main/java/org/rf/rfserver/party/controller/PartyController.java +++ b/src/main/java/org/rf/rfserver/party/controller/PartyController.java @@ -52,9 +52,9 @@ public BaseResponse getParty(@PathVariable("partyId") Long partyId } @PatchMapping("/{partyId}") - public BaseResponse getParty(@PathVariable("partyId") Long partyId, @RequestBody PatchPartyReq patchPartyReq) { + public BaseResponse getParty(@PathVariable("partyId") Long partyId, @RequestPart("patchPartyReq") PatchPartyReq patchPartyReq, @RequestPart(value = "file", required = false) MultipartFile file) { try { - return new BaseResponse<>(partyService.updateParty(partyId, patchPartyReq)); + return new BaseResponse<>(partyService.updateParty(partyId, patchPartyReq, file)); } catch (BaseException e) { return new BaseResponse<>(e.getStatus()); } diff --git a/src/main/java/org/rf/rfserver/party/service/PartyService.java b/src/main/java/org/rf/rfserver/party/service/PartyService.java index 7ee135c..255eb98 100644 --- a/src/main/java/org/rf/rfserver/party/service/PartyService.java +++ b/src/main/java/org/rf/rfserver/party/service/PartyService.java @@ -34,6 +34,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Random; import java.util.stream.Collectors; import static org.rf.rfserver.config.BaseResponseStatus.*; @@ -120,15 +121,36 @@ public GetPartyRes getParty(Long partyId) throws BaseException { .build(); } - public PatchPartyRes updateParty(Long partyId, PatchPartyReq patchPartyReq) throws BaseException { - Party party = findPartyById(partyId); - party.updateParty(patchPartyReq); - return new PatchPartyRes(true); + public PatchPartyRes updateParty(Long partyId, PatchPartyReq patchPartyReq, MultipartFile file) throws BaseException { + try{ + Party party = findPartyById(partyId); + if(file != null){ + String preImageFilePath = party.getImageFilePath(); + //기본 배너 이미지일때 + if(preImageFilePath.contains("partyBanner/")){ + String imageFilePath = s3Uploader.fileUpload(file,"partyImage"); + } else { + //이전 이미지 버킷에서 삭제 + String fileKey = s3Uploader.changeFileKeyPath(preImageFilePath); + s3Uploader.deleteFile(fileKey); + //새 이미지 업데이트 + String imageFilePath = s3Uploader.fileUpload(file,"partyImage"); + party.updateImageUrl(imageFilePath); + } + } + party.updateParty(patchPartyReq); + return new PatchPartyRes(true); + } catch (Exception e){ + throw new BaseException(DATABASE_ERROR); + } } public DeletePartyRes deleteParty(Long partyId) throws BaseException { Party party = partyRepository.findById(partyId) .orElseThrow(() -> new BaseException(INVALID_PARTY)); + String imageFilePath = party.getImageFilePath(); + String fileKey = s3Uploader.changeFileKeyPath(imageFilePath); + s3Uploader.deleteFile(fileKey); deleteUserParty(party.getUsers()); partyRepository.delete(party); return new DeletePartyRes(partyId); @@ -171,7 +193,7 @@ public void joinValidation(Party party, User user) throws BaseException { } - public Boolean isFullParty(Party party) { + public boolean isFullParty(Party party) { if (party.getUsers().size() >= party.getMemberCount()) { return true; } diff --git a/src/main/java/org/rf/rfserver/redisDomain/partyidUserid/service/PartyidUseridService.java b/src/main/java/org/rf/rfserver/redisDomain/partyidUserid/service/PartyidUseridService.java index ca59dbe..3cb84ab 100644 --- a/src/main/java/org/rf/rfserver/redisDomain/partyidUserid/service/PartyidUseridService.java +++ b/src/main/java/org/rf/rfserver/redisDomain/partyidUserid/service/PartyidUseridService.java @@ -20,14 +20,13 @@ public Boolean setPartyidUserid(Long partyId, Long userId) { partyidUserid.getUserIds().add(userId); partyidUseridRepository.save(partyidUserid); return true; - } catch (Exception e) { PartyidUserid partyidUserid = new PartyidUserid(partyId, new HashSet<>()); partyidUserid.getUserIds().add(userId); partyidUseridRepository.save(partyidUserid); return true; - } + } public Set getUserids(Long partyId){ PartyidUserid partyidUserid = partyidUseridRepository.findById(partyId)