From c2bfa6247d863d2035f86a3a66336e2cd681ba62 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Tue, 10 Sep 2024 15:12:46 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[fix]=20=EB=AF=B8=EC=85=98=EA=B8=80=20?= =?UTF-8?q?=EB=B0=8F=20=EB=8C=93=EA=B8=80=20=EC=82=AD=EC=A0=9C=20API=20?= =?UTF-8?q?=EC=84=A4=EA=B3=84=20=EB=B0=8F=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/controller/FarmClubController.java | 16 ++++++++++++++++ .../farmclub/service/MissionPostService.java | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 0923a10..8579428 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -198,4 +198,20 @@ public BaseResponseDto reportMissionPostComment( missionPostService.reportMissionPostComment(user.getUserId(), requestDto); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } + + @DeleteMapping("/mission/{missionPostId}") + public BaseResponseDto deleteMissionPost( + @PathVariable Long missionPostId + ) { + missionPostService.deleteMissionPost(missionPostId); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); + } + + @DeleteMapping("/mission/comment/{missionPostCommentId}") + public BaseResponseDto deleteMissionPostComment( + @PathVariable Long missionPostCommentId + ) { + missionPostService.deleteMissionPostComment(missionPostCommentId); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java index 1f55265..47d8811 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java @@ -104,6 +104,16 @@ public void reportMissionPostComment(Long userId, CreateMissionPostCommentReport } } + public void deleteMissionPost(Long missionPostId) { + MissionPost missionPost = missionPostHelper.getMissionPost(missionPostId); + missionPostHelper.deleteMissionPost(missionPost); + } + + public void deleteMissionPostComment(Long missionPostCommentId) { + MissionPostComment missionPostComment = missionPostHelper.getMissionPostComment(missionPostCommentId); + missionPostHelper.deleteMissionPostComment(missionPostComment); + } + private MissionPost saveMissionPost(MissionPost missionPost) { return missionPostRepository.save(missionPost); } From 9680f73b15564f730946751e6aaf9b9869f9c9ee Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Tue, 10 Sep 2024 15:40:23 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=AA=A9=EB=A1=9D=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EA=B0=92=EC=97=90=20=EC=9C=A0=EC=A0=80=20id=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=9E=90=EC=8B=A0=EC=9D=B4=20?= =?UTF-8?q?=EA=B0=80=EC=9E=A5=20=EB=A8=BC=EC=A0=80=20=EC=98=A4=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FarmClubController.java | 3 +- .../farmclub/helper/FarmClubHelper.java | 4 +-- .../repository/FarmClubRepositoryCustom.java | 2 +- .../repository/FarmClubRepositoryImpl.java | 35 ++++++++++++++----- .../farmclub/service/FarmClubService.java | 4 +-- .../domain/farmclub/vo/GetFarmClubUserVo.java | 4 ++- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 8579428..a212c21 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -122,9 +122,10 @@ public BaseResponseDto getMissionPostList( @GetMapping("/{farmClubId}/user") public BaseResponseDto getFarmClubUserList( + @AuthenticationPrincipal CustomUser user, @PathVariable Long farmClubId ) { - return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getFarmClubUserList(farmClubId)); + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getFarmClubUserList(user.getUserId(), farmClubId)); } @GetMapping("/mission/{missionPostId}") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java index 66adb46..e28edcd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java @@ -38,8 +38,8 @@ public List getUserFarmClubList(Long userId) { return farmClubRepository.findMyFarmClubList(userId); } - public GetFarmClubUserListResponseDto getFarmClubUserList(Long farmClubId) { - return GetFarmClubUserListResponseDto.of(farmClubRepository.findFarmClubUserList(farmClubId)); + public GetFarmClubUserListResponseDto getFarmClubUserList(Long userId, Long farmClubId) { + return GetFarmClubUserListResponseDto.of(farmClubRepository.findFarmClubUserList(userId, farmClubId)); } public List getRecommendedFarmClubList(String level) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java index abd6411..9d7aece 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java @@ -15,6 +15,6 @@ public interface FarmClubRepositoryCustom { List findMyFarmClubList(Long userId); GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId); HistoryDetailVo getFarmClubDetail(Long userFarmClubId); - List findFarmClubUserList(Long farmClubId); + List findFarmClubUserList(Long userId, Long farmClubId); List getRecommendedFarmClubList(String level); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index 180d27f..9dd79e3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -110,23 +110,40 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) { } @Override - public List findFarmClubUserList(Long farmClubId) { + public List findFarmClubUserList(Long userId, Long farmClubId) { JPAQueryFactory queryFactory = new JPAQueryFactory(em); - return queryFactory + // 내 유저 정보 + List userList = queryFactory .select(Projections.constructor( GetFarmClubUserVo.class, + user.id, user.nickname, user.profileImage)) .from(user) - .where(user.id.in( - JPAExpressions - .select(userFarmClub.userId) - .from(userFarmClub) - .join(userFarmClub.farmClub, farmClub) - .where(farmClub.id.eq(farmClubId)) - )) + .where(user.id.eq(userId)) // 내 유저 id를 먼저 조회 .fetch(); + + // 나머지 유저 정보 + userList.addAll( + queryFactory + .select(Projections.constructor( + GetFarmClubUserVo.class, + user.id, + user.nickname, + user.profileImage)) + .from(user) + .where(user.id.in( + JPAExpressions + .select(userFarmClub.userId) + .from(userFarmClub) + .join(userFarmClub.farmClub, farmClub) + .where(farmClub.id.eq(farmClubId)) + ).and(user.id.ne(userId))) // 내 유저 id를 제외하고 조회 + .fetch() + ); + + return userList; } public HistoryDetailVo getFarmClubDetail(Long userFarmClubId) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 5db4cd3..84dcbf7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -143,8 +143,8 @@ public List getMyFarmClubList(Long userId) { return farmClubHelper.getUserFarmClubList(userId); } - public GetFarmClubUserListResponseDto getFarmClubUserList(Long farmClubId) { - return farmClubHelper.getFarmClubUserList(farmClubId); + public GetFarmClubUserListResponseDto getFarmClubUserList(Long userId, Long farmClubId) { + return farmClubHelper.getFarmClubUserList(userId, farmClubId); } public GetMyVeggieResponseDto getMyVeggieForRegister(Long userId, String veggieInfoId) { diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetFarmClubUserVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetFarmClubUserVo.java index 4f4eabd..bc6cbdc 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetFarmClubUserVo.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetFarmClubUserVo.java @@ -5,11 +5,13 @@ @Builder(access = AccessLevel.PRIVATE) public record GetFarmClubUserVo( + Long userId, String nickname, String profileImage ) { - public static GetFarmClubUserVo of(String nickname, String profileImage) { + public static GetFarmClubUserVo of(Long userId, String nickname, String profileImage) { return GetFarmClubUserVo.builder() + .userId(userId) .nickname(nickname) .profileImage(profileImage) .build(); From 1963a886a5660f1bcec24ae0435393c4d906d4aa Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Tue, 10 Sep 2024 16:08:55 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=EA=B8=80=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EC=9D=91=EB=8B=B5=EA=B0=92=EC=97=90=20=EA=B0=81=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EA=B8=80=20=EC=9E=91=EC=84=B1=EC=9E=90?= =?UTF-8?q?=EC=9D=98=20=EC=9C=A0=EC=A0=80id=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/vo/MissionPostVo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java index 9047ebf..169f9c8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java @@ -8,6 +8,7 @@ public record MissionPostVo( Long missionPostId, + Long userId, int stepNum, String nickname, String profileImage, @@ -23,6 +24,7 @@ public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long co { this( missionPost.getId(), + user.getId(), missionPost.getStepNum(), user.getNickname(), user.getProfileImage(),