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..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}") @@ -198,4 +199,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/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/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); } 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(); 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(),