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 0b2fee7..d4e84da 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 @@ -181,21 +181,21 @@ public BaseResponseDto successFarmClub( return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.successFarmClub(farmClubId, user.getUserId())); } - @PostMapping("/report/mission/{missionPostId}") + @PostMapping("/report/mission") public BaseResponseDto reportMissionPost( @AuthenticationPrincipal CustomUser user, - @PathVariable Long missionPostId + @RequestBody CreateMissionPostReportRequestDto requestDto ) { - missionPostService.reportMissionPost(user.getUserId(), missionPostId); + missionPostService.reportMissionPost(user.getUserId(), requestDto); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } @PostMapping("/report/comment/{commentId}") public BaseResponseDto reportMissionPostComment( @AuthenticationPrincipal CustomUser user, - @PathVariable Long commentId + @RequestBody CreateMissionPostCommentReportRequestDto requestDto ) { - missionPostService.reportMissionPostComment(user.getUserId(), commentId); + missionPostService.reportMissionPostComment(user.getUserId(), requestDto); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentReportRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentReportRequestDto.java new file mode 100644 index 0000000..c610ee2 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentReportRequestDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +public record CreateMissionPostCommentReportRequestDto( + Long missionPostCommentId, + String reason +) { +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostReportRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostReportRequestDto.java new file mode 100644 index 0000000..4ed8c61 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostReportRequestDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +public record CreateMissionPostReportRequestDto( + Long missionPostId, + String reason +) { +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java index 1423d1c..49cdf33 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostCommentReport.java @@ -22,6 +22,9 @@ public class MissionPostCommentReport { @Column(name = "mission_post_comment_report_id") private Long id; + @Column(name = "reason") + private String reason; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "mission_post_comment_id") @@ -31,10 +34,11 @@ public class MissionPostCommentReport { @JoinColumn(name = "user_id") private User user; - public static MissionPostCommentReport createMissionPostCommentReport(MissionPostComment missionPostComment, User user){ + public static MissionPostCommentReport createMissionPostCommentReport(MissionPostComment missionPostComment, User user, String reason){ MissionPostCommentReport report = MissionPostCommentReport.builder() .missionPostComment(missionPostComment) .user(user) + .reason(reason) .build(); missionPostComment.addReport(report); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java index 3558ac1..e2a630b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPostReport.java @@ -22,6 +22,9 @@ public class MissionPostReport { @Column(name = "mission_post_report_id") private Long id; + @Column(name = "reason") + private String reason; + @OnDelete(action = OnDeleteAction.CASCADE) @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "mission_post_id") @@ -31,10 +34,11 @@ public class MissionPostReport { @JoinColumn(name = "user_id") private User user; - public static MissionPostReport createMissionPostReport(MissionPost missionPost, User user){ + public static MissionPostReport createMissionPostReport(MissionPost missionPost, User user, String reason){ MissionPostReport report = MissionPostReport.builder() .missionPost(missionPost) .user(user) + .reason(reason) .build(); missionPost.addReport(report); 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 1146935..1f55265 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 @@ -1,6 +1,8 @@ package com.modernfarmer.farmusspring.domain.farmclub.service; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostCommentReportRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostCommentRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostReportRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.*; @@ -77,9 +79,9 @@ public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId } @Transactional - public void reportMissionPost(Long userId, Long missionPostId) { - MissionPost missionPost = missionPostHelper.getMissionPost(missionPostId); - MissionPostReport.createMissionPostReport(missionPost, userHelper.getUserEntity(userId)); + public void reportMissionPost(Long userId, CreateMissionPostReportRequestDto requestDto) { + MissionPost missionPost = missionPostHelper.getMissionPost(requestDto.missionPostId()); + MissionPostReport.createMissionPostReport(missionPost, userHelper.getUserEntity(userId), requestDto.reason()); int userCount = missionPost.getUserFarmClub().getFarmClub().getUserFarmClubs().size(); int reportCount = missionPost.getMissionPostReports().size(); if (userCount < 4 && reportCount >= 2) { @@ -90,9 +92,9 @@ public void reportMissionPost(Long userId, Long missionPostId) { } @Transactional - public void reportMissionPostComment(Long userId, Long missionPostCommentId) { - MissionPostComment missionPostComment = missionPostHelper.getMissionPostComment(missionPostCommentId); - MissionPostCommentReport.createMissionPostCommentReport(missionPostComment, userHelper.getUserEntity(userId)); + public void reportMissionPostComment(Long userId, CreateMissionPostCommentReportRequestDto requestDto) { + MissionPostComment missionPostComment = missionPostHelper.getMissionPostComment(requestDto.missionPostCommentId()); + MissionPostCommentReport.createMissionPostCommentReport(missionPostComment, userHelper.getUserEntity(userId), requestDto.reason()); int userCount = missionPostComment.getMissionPost().getUserFarmClub().getFarmClub().getUserFarmClubs().size(); int reportCount = missionPostComment.getMissionPostCommentReports().size(); if (userCount < 4 && reportCount >= 2) {