From c5203dffade9985485ae7fb66ff2de6f24053f7a Mon Sep 17 00:00:00 2001 From: Yerin Lee <91695537+lxxyxin@users.noreply.github.com> Date: Tue, 22 Aug 2023 16:00:46 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20[#107]=20isFullofKorean=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/rf/rfserver/party/service/PartyService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 03486b1..046cc88 100644 --- a/src/main/java/org/rf/rfserver/party/service/PartyService.java +++ b/src/main/java/org/rf/rfserver/party/service/PartyService.java @@ -147,6 +147,7 @@ public void joinValidation(Party party, User user) throws BaseException { isFullParty(party); if (userService.isKorean(user)) { isFullOfKorean(party); + } if(userService.isKorean(user)) { if (isFullOfKorean(party)) { throw new BaseException(FULL_OF_KOREAN); @@ -156,6 +157,7 @@ public void joinValidation(Party party, User user) throws BaseException { isJoinedUser(user, party); } + public boolean isFullParty(Party party) { if (party.getUsers().size() >= party.getMemberCount()) { return true; @@ -163,12 +165,14 @@ public boolean isFullParty(Party party) { return false; } - public void isFullOfKorean(Party party) throws BaseException { + public Boolean isFullOfKorean(Party party) throws BaseException { if(party.getNativeCount() <= party.getCurrentNativeCount()) { - throw new BaseException(FULL_OF_KOREAN); + return true; } + throw new BaseException(FULL_OF_KOREAN); } + public void isJoinedUser(User user, Party party) throws BaseException { for (UserParty userParty : party.getUsers()) { if (userParty.getUser() == user) { From 071883e0ea27cd636a044cf7ca1a0169128f3bc6 Mon Sep 17 00:00:00 2001 From: Yerin Lee <91695537+lxxyxin@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:18:16 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20[#112]=20=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=88=98=EC=A0=95=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B0=8F=20=EB=AA=A8=EC=9E=84=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../party/controller/PartyController.java | 4 ++-- .../rfserver/party/service/PartyService.java | 21 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) 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 83f4f1f..9fb84e9 100644 --- a/src/main/java/org/rf/rfserver/party/service/PartyService.java +++ b/src/main/java/org/rf/rfserver/party/service/PartyService.java @@ -120,16 +120,35 @@ public GetPartyRes getParty(Long partyId) throws BaseException { .build(); } - public PatchPartyRes updateParty(Long partyId, PatchPartyReq patchPartyReq) throws BaseException { + public PatchPartyRes updateParty(Long partyId, PatchPartyReq patchPartyReq, MultipartFile file) throws BaseException { + try{ Party party = findPartyById(partyId); party.updateParty(patchPartyReq); + if(file != null){ + String preImageFilePath = party.getImageFilePath(); + String fileKey = s3Uploader.changeFileKeyPath(preImageFilePath); + if(fileKey.contains("partyBanner/")){ + String imageFilePath = s3Uploader.fileUpload(file, "partyImage"); + party.updateImageUrl(imageFilePath); + } else { + s3Uploader.deleteFile(fileKey); + String imageFilePath = s3Uploader.fileUpload(file, "partyImage"); + party.updateImageUrl(imageFilePath); + } + } 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)); deleteUserParty(party.getUsers()); + String imageFilePath = party.getImageFilePath(); + String fileKey = s3Uploader.changeFileKeyPath(imageFilePath); + s3Uploader.deleteFile(fileKey); partyRepository.delete(party); return new DeletePartyRes(partyId); } From 9b2197572895a141fe560aacfb982a7f82d8509e Mon Sep 17 00:00:00 2001 From: Yerin Lee <91695537+lxxyxin@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:45:21 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20[#97]=20=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=88=98=EC=A0=95=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rfserver/party/service/PartyService.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) 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 d6eb7b7..e7e6e00 100644 --- a/src/main/java/org/rf/rfserver/party/service/PartyService.java +++ b/src/main/java/org/rf/rfserver/party/service/PartyService.java @@ -121,10 +121,28 @@ 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 { From c5c73ab7afa8162513a42d22690835b7a89df8fa Mon Sep 17 00:00:00 2001 From: Yerin Lee <91695537+lxxyxin@users.noreply.github.com> Date: Tue, 22 Aug 2023 23:43:42 +0900 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20[#97]=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/PartyidUseridService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 c8e8308..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 @@ -14,11 +14,19 @@ public class PartyidUseridService { private final PartyidUseridRepository partyidUseridRepository; public Boolean setPartyidUserid(Long partyId, Long userId) { - PartyidUserid partyidUserid = partyidUseridRepository.findById(partyId) - .orElse(new PartyidUserid(partyId, new HashSet<>())); - partyidUserid.getUserIds().add(userId); - partyidUseridRepository.save(partyidUserid); - return true; + try { + PartyidUserid partyidUserid = partyidUseridRepository.findById(partyId) + .orElse(new PartyidUserid(partyId, new HashSet<>())); + 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) From 4453a14fbd30167c0713847500ab614f976c1361 Mon Sep 17 00:00:00 2001 From: Yerin Lee <91695537+lxxyxin@users.noreply.github.com> Date: Tue, 22 Aug 2023 23:58:21 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20[#97]=20=EB=AA=A8=EC=9E=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=B2=84=ED=82=B7=EC=97=90=EC=84=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/rf/rfserver/party/service/PartyService.java | 3 +++ 1 file changed, 3 insertions(+) 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 e7e6e00..664d448 100644 --- a/src/main/java/org/rf/rfserver/party/service/PartyService.java +++ b/src/main/java/org/rf/rfserver/party/service/PartyService.java @@ -148,6 +148,9 @@ public PatchPartyRes updateParty(Long partyId, PatchPartyReq patchPartyReq, Mult 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);