Skip to content

Commit

Permalink
Merge pull request #119 from Mojacknong/feat_101/신고-로직-개발
Browse files Browse the repository at this point in the history
Feat 101/신고 로직 개발
  • Loading branch information
Ryeolee authored Sep 8, 2024
2 parents 62cf213 + 876d80e commit 129d3f3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.req;

public record CreateMissionPostCommentReportRequestDto(
Long missionPostCommentId,
String reason
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.req;

public record CreateMissionPostReportRequestDto(
Long missionPostId,
String reason
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.*;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 129d3f3

Please sign in to comment.