From d2c252aee42563d8e0123cdfc992999b2a80f223 Mon Sep 17 00:00:00 2001 From: Min Yeong Park Date: Sun, 2 Jun 2024 16:32:12 +0900 Subject: [PATCH 1/5] =?UTF-8?q?#195=20Feat:=20=EA=B8=80=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/status/ErrorStatus.java | 4 ++- .../spring/converter/PostConverter.java | 17 +++++++++++ .../java/friend/spring/domain/Report.java | 12 +++----- .../friend/spring/domain/ReportCategory.java | 29 ++++++++++++++++++ .../spring/domain/enums/ReportCategory.java | 5 ---- .../repository/ReportCategoryRepository.java | 10 +++++++ .../spring/repository/ReportRepository.java | 11 +++++++ .../friend/spring/service/PostService.java | 3 ++ .../spring/service/PostServiceImpl.java | 30 +++++++++++++++++++ .../web/controller/PostRestController.java | 26 ++++++++++++++++ .../friend/spring/web/dto/PostRequestDTO.java | 7 +++++ .../spring/web/dto/PostResponseDTO.java | 8 +++++ 12 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 src/main/java/friend/spring/domain/ReportCategory.java delete mode 100644 src/main/java/friend/spring/domain/enums/ReportCategory.java create mode 100644 src/main/java/friend/spring/repository/ReportCategoryRepository.java create mode 100644 src/main/java/friend/spring/repository/ReportRepository.java diff --git a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java index a9bd165..495c02d 100644 --- a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java @@ -61,7 +61,9 @@ POST_SCRAP_DUPLICATE(HttpStatus.BAD_REQUEST, "POST4015", "글에 대한 스크랩 데이터가 이미 존재합니다."), DEADLINE_OVER(HttpStatus.BAD_REQUEST, "POST4016", "투표 마감 시간이 지났습니다"), ALREADY_VOTE(HttpStatus.BAD_REQUEST, "POST4017", "이미 투표 하셨습니다."), -// USER_VOTE(HttpStatus.BAD_REQUEST,"POST4017","작성자는 투표가 불가능 합니다 하셨습니다."), +// USER_VOTE(HttpStatus.BAD_REQUEST,"POST4017","작성자는 투표가 불가능 합니다 하셨습니다."), // 이거 필요없으면 지워야 할 것 같습니다! + + POST_REPORT_DUPLICATE(HttpStatus.BAD_REQUEST, "POST4018", "이 유저가 해당 글을 신고한 신고 내역 데이터가 이미 존재합니다."), // 댓글 관련 응답 COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "COMMENT4001", "댓글을 찾을 수 없습니다."), diff --git a/src/main/java/friend/spring/converter/PostConverter.java b/src/main/java/friend/spring/converter/PostConverter.java index 5ef2d5b..f6c45fc 100644 --- a/src/main/java/friend/spring/converter/PostConverter.java +++ b/src/main/java/friend/spring/converter/PostConverter.java @@ -4,6 +4,7 @@ import friend.spring.domain.enums.PostState; import friend.spring.domain.enums.PostType; import friend.spring.domain.enums.PostVoteType; +import friend.spring.domain.enums.ReportType; import friend.spring.service.PostQueryService; import friend.spring.web.dto.*; import org.springframework.data.domain.Page; @@ -995,6 +996,22 @@ public static PostResponseDTO.ScrapCreateRes toScrapCreateRes(Post_scrap post_sc .post_scrap_id(post_scrap.getId()) .build(); } + + public static Report toReportPost(Post post, User user, ReportCategory reportCategory) { + return Report.builder() + .targetType(ReportType.POST) + .targetId(post.getId()) + .reportCategory(reportCategory) + .user(user) + .build(); + } + + public static PostResponseDTO.PostReportRes toPostReportRes(Report report) { + return PostResponseDTO.PostReportRes.builder() + .reportId(report.getId()) + .build(); + } + } diff --git a/src/main/java/friend/spring/domain/Report.java b/src/main/java/friend/spring/domain/Report.java index cf87d47..396f4fd 100644 --- a/src/main/java/friend/spring/domain/Report.java +++ b/src/main/java/friend/spring/domain/Report.java @@ -1,7 +1,6 @@ package friend.spring.domain; import friend.spring.domain.common.BaseEntity; -import friend.spring.domain.enums.ReportCategory; import friend.spring.domain.enums.ReportType; import lombok.*; @@ -22,14 +21,11 @@ public class Report extends BaseEntity { private ReportType targetType; @Column(nullable = false) - private Integer targetId; + private Long targetId; - @Column(nullable = false, length = 500) - private String content; - - @Enumerated(EnumType.STRING) - @Column - private ReportCategory category; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "report_category_id") + private ReportCategory reportCategory; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") diff --git a/src/main/java/friend/spring/domain/ReportCategory.java b/src/main/java/friend/spring/domain/ReportCategory.java new file mode 100644 index 0000000..b382fd1 --- /dev/null +++ b/src/main/java/friend/spring/domain/ReportCategory.java @@ -0,0 +1,29 @@ +package friend.spring.domain; + +import friend.spring.domain.common.BaseEntity; +import lombok.*; + +import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class ReportCategory { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Builder.Default + @OneToMany(mappedBy = "reportCategory") + private List reportList = new ArrayList<>(); + +} + diff --git a/src/main/java/friend/spring/domain/enums/ReportCategory.java b/src/main/java/friend/spring/domain/enums/ReportCategory.java deleted file mode 100644 index 1c79bbf..0000000 --- a/src/main/java/friend/spring/domain/enums/ReportCategory.java +++ /dev/null @@ -1,5 +0,0 @@ -package friend.spring.domain.enums; - -public enum ReportCategory { - SPAM, PRONO, NOT_FIT_POST, ABUSE, AD -} diff --git a/src/main/java/friend/spring/repository/ReportCategoryRepository.java b/src/main/java/friend/spring/repository/ReportCategoryRepository.java new file mode 100644 index 0000000..1487661 --- /dev/null +++ b/src/main/java/friend/spring/repository/ReportCategoryRepository.java @@ -0,0 +1,10 @@ +package friend.spring.repository; + +import friend.spring.domain.Category; +import friend.spring.domain.Report; +import friend.spring.domain.ReportCategory; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ReportCategoryRepository extends JpaRepository { + ReportCategory findByName(String category); +} diff --git a/src/main/java/friend/spring/repository/ReportRepository.java b/src/main/java/friend/spring/repository/ReportRepository.java new file mode 100644 index 0000000..7991e22 --- /dev/null +++ b/src/main/java/friend/spring/repository/ReportRepository.java @@ -0,0 +1,11 @@ +package friend.spring.repository; + +import friend.spring.domain.Report; +import friend.spring.domain.enums.ReportType; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ReportRepository extends JpaRepository { + Optional findByTargetTypeAndTargetIdAndUserId(ReportType post, Long postId, Long userId); +} diff --git a/src/main/java/friend/spring/service/PostService.java b/src/main/java/friend/spring/service/PostService.java index fc4034d..e242862 100644 --- a/src/main/java/friend/spring/service/PostService.java +++ b/src/main/java/friend/spring/service/PostService.java @@ -3,6 +3,7 @@ import friend.spring.domain.Candidate; import friend.spring.domain.Post; +import friend.spring.domain.Report; import friend.spring.domain.User; import friend.spring.domain.mapping.Post_like; import friend.spring.domain.mapping.Post_scrap; @@ -48,5 +49,7 @@ public interface PostService { Post_scrap createScrapPost(Long postId, HttpServletRequest request); void deleteScrapPost(Long postId, HttpServletRequest request); + + Report createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2); } diff --git a/src/main/java/friend/spring/service/PostServiceImpl.java b/src/main/java/friend/spring/service/PostServiceImpl.java index d29f477..4dd8b2a 100644 --- a/src/main/java/friend/spring/service/PostServiceImpl.java +++ b/src/main/java/friend/spring/service/PostServiceImpl.java @@ -8,6 +8,7 @@ import friend.spring.domain.*; import friend.spring.domain.enums.PostState; import friend.spring.domain.enums.PostType; +import friend.spring.domain.enums.ReportType; import friend.spring.domain.enums.S3ImageType; import friend.spring.domain.mapping.Post_like; import friend.spring.domain.mapping.Post_scrap; @@ -42,6 +43,8 @@ public class PostServiceImpl implements PostService { private final Card_PollRepository cardPollRepository; private final PointRepository pointRepository; private final CategoryRepository categoryRepository; + private final ReportCategoryRepository reportCategoryRepository; + private final ReportRepository reportRepository; private final PostLikeRepository postLikeRepository; private final CommentRepository commentRepository; @@ -470,4 +473,31 @@ public void deleteScrapPost(Long postId, HttpServletRequest request) { postScrapRepository.delete(post_scrap); } + @Override + public Report createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2) { + Long userId = jwtTokenProvider.getCurrentUser(request2); + + Optional optionalPost = postRepository.findById(postId); + if (optionalPost.isEmpty()) { + this.checkPost(false); + } + + Optional optionalUser = userRepository.findById(userId); + if (optionalUser.isEmpty()) { + userService.checkUser(false); + } + + Post post = optionalPost.get(); + User user = optionalUser.get(); + + // 이미 신고된 건인지 확인 + Optional optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.POST, postId, userId); + if (!optionalReport.isEmpty()) { + throw new PostHandler(POST_REPORT_DUPLICATE); + } + + ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory()); + Report report = PostConverter.toReportPost(post, user, reportCategory); + return reportRepository.save(report); + } } diff --git a/src/main/java/friend/spring/web/controller/PostRestController.java b/src/main/java/friend/spring/web/controller/PostRestController.java index c8ce789..746c972 100644 --- a/src/main/java/friend/spring/web/controller/PostRestController.java +++ b/src/main/java/friend/spring/web/controller/PostRestController.java @@ -5,6 +5,7 @@ import friend.spring.converter.PostConverter; import friend.spring.domain.Candidate; import friend.spring.domain.Post; +import friend.spring.domain.Report; import friend.spring.repository.PostRepository; import friend.spring.service.JwtTokenService; import friend.spring.service.PostQueryService; @@ -26,6 +27,8 @@ import javax.validation.Valid; import java.io.IOException; +import static friend.spring.apiPayload.code.status.ErrorStatus.POST_REPORT_DUPLICATE; + @RestController @RequiredArgsConstructor @Validated @@ -303,4 +306,27 @@ public ApiResponse deleteScrapPost( postService.deleteScrapPost(postId, request); return ApiResponse.onSuccess(null); } + + // 글 신고 + @PostMapping("/posts/{post-id}/report") + @Operation(summary = "글 신고 API", description = "글 신고하는 API입니다. ex) /posts/1/report") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 요청에 성공했습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER4001", description = "NOT_FOUND, 사용자를 찾을 수 없습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4001", description = "NOT_FOUND, 글을 찾을 수 없습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4018", description = "BAD_REQUEST, 이 유저가 해당 글을 신고한 신고 내역 데이터가 이미 존재합니다."), + }) + @Parameters({ + @Parameter(name = "post-id", description = "path variable - 글 아이디"), + @Parameter(name = "atk", description = "RequestHeader - 로그인한 사용자의 accessToken"), + }) + public ApiResponse createReportPost( + @PathVariable("post-id") Long postId, + @RequestBody PostRequestDTO.PostReportReq request, + @RequestHeader("atk") String atk, + HttpServletRequest request2 + ) { + Report postReport = postService.createReportPost(postId, request, request2); + return ApiResponse.onSuccess(PostConverter.toPostReportRes(postReport)); + } } diff --git a/src/main/java/friend/spring/web/dto/PostRequestDTO.java b/src/main/java/friend/spring/web/dto/PostRequestDTO.java index 6619638..d80a409 100644 --- a/src/main/java/friend/spring/web/dto/PostRequestDTO.java +++ b/src/main/java/friend/spring/web/dto/PostRequestDTO.java @@ -50,4 +50,11 @@ public static class PostEditReq { Boolean voteOnGoing; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PostReportReq { + String reportCategory; + } } diff --git a/src/main/java/friend/spring/web/dto/PostResponseDTO.java b/src/main/java/friend/spring/web/dto/PostResponseDTO.java index 4b2e351..acdf06d 100644 --- a/src/main/java/friend/spring/web/dto/PostResponseDTO.java +++ b/src/main/java/friend/spring/web/dto/PostResponseDTO.java @@ -158,4 +158,12 @@ public static class PostLikeRes { public static class ScrapCreateRes { Long post_scrap_id; } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PostReportRes { + Long reportId; + } } \ No newline at end of file From 35d5135e3f01982533299bbfcdd71ba21fda1845 Mon Sep 17 00:00:00 2001 From: Min Yeong Park Date: Sun, 2 Jun 2024 17:04:44 +0900 Subject: [PATCH 2/5] =?UTF-8?q?#195=20Feat:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=8B=A0=EA=B3=A0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/status/ErrorStatus.java | 1 + .../spring/converter/CommentConverter.java | 20 +++++++++-- .../friend/spring/service/CommentService.java | 3 ++ .../spring/service/CommentServiceImpl.java | 33 +++++++++++++++++++ .../web/controller/CommentRestController.java | 25 ++++++++++++++ .../spring/web/dto/CommentRequestDTO.java | 8 +++++ .../spring/web/dto/CommentResponseDTO.java | 8 +++++ 7 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java index 495c02d..698c9a5 100644 --- a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java @@ -73,6 +73,7 @@ COMMENT_NOT_CORRECT_USER(HttpStatus.BAD_REQUEST, "COMMENT4005", "올바른 사용자(댓글 작성자)가 아닙니다."), COMMENT_POST_NOT_MATCH(HttpStatus.BAD_REQUEST, "COMMENT4006", "해당 글에 작성된 댓글이 아닙니다."), COMMENT_LIKE_DUPLICATE(HttpStatus.BAD_REQUEST, "COMMENT4007", "댓글에 대한 좋아요 데이터가 이미 존재합니다."), + COMMENT_REPORT_DUPLICATE(HttpStatus.BAD_REQUEST, "COMMENT4008", "이 유저가 해당 댓글을 신고한 신고 내역 데이터가 이미 존재합니다."), // 알림 관련 응답 ALARM_NOT_FOUND(HttpStatus.NOT_FOUND, "ALARM4001", "알림이 없습니다"), diff --git a/src/main/java/friend/spring/converter/CommentConverter.java b/src/main/java/friend/spring/converter/CommentConverter.java index 97b6051..0478464 100644 --- a/src/main/java/friend/spring/converter/CommentConverter.java +++ b/src/main/java/friend/spring/converter/CommentConverter.java @@ -1,13 +1,13 @@ package friend.spring.converter; -import friend.spring.domain.Comment; -import friend.spring.domain.Post; -import friend.spring.domain.User; +import friend.spring.domain.*; import friend.spring.domain.enums.CommentState; +import friend.spring.domain.enums.ReportType; import friend.spring.domain.mapping.Comment_choice; import friend.spring.domain.mapping.Comment_like; import friend.spring.web.dto.CommentRequestDTO; import friend.spring.web.dto.CommentResponseDTO; +import friend.spring.web.dto.PostResponseDTO; import java.util.ArrayList; import java.util.List; @@ -116,4 +116,18 @@ public static CommentResponseDTO.myCommentRes toMyCommentResDTO(Comment comment) .build(); } + public static CommentResponseDTO.CommentReportRes toCommentReportRes(Report report) { + return CommentResponseDTO.CommentReportRes.builder() + .reportId(report.getId()) + .build(); + } + + public static Report toReportComment(Comment comment, User user, ReportCategory reportCategory) { + return Report.builder() + .targetType(ReportType.COMMENT) + .targetId(comment.getId()) + .reportCategory(reportCategory) + .user(user) + .build(); + } } diff --git a/src/main/java/friend/spring/service/CommentService.java b/src/main/java/friend/spring/service/CommentService.java index 3199432..2d9e309 100644 --- a/src/main/java/friend/spring/service/CommentService.java +++ b/src/main/java/friend/spring/service/CommentService.java @@ -1,6 +1,7 @@ package friend.spring.service; import friend.spring.domain.Comment; +import friend.spring.domain.Report; import friend.spring.domain.mapping.Comment_choice; import friend.spring.domain.mapping.Comment_like; import friend.spring.web.dto.CommentRequestDTO; @@ -36,4 +37,6 @@ public interface CommentService { Page getMyCommentList(Long userId, Integer page); void deleteComment(Long postId, Long commentId, HttpServletRequest request); + + Report createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2); } diff --git a/src/main/java/friend/spring/service/CommentServiceImpl.java b/src/main/java/friend/spring/service/CommentServiceImpl.java index 6863c52..5bacee6 100644 --- a/src/main/java/friend/spring/service/CommentServiceImpl.java +++ b/src/main/java/friend/spring/service/CommentServiceImpl.java @@ -3,11 +3,14 @@ import friend.spring.apiPayload.GeneralException; import friend.spring.apiPayload.code.status.ErrorStatus; import friend.spring.apiPayload.handler.CommentHandler; +import friend.spring.apiPayload.handler.PostHandler; import friend.spring.converter.AlarmConverter; import friend.spring.converter.CommentConverter; +import friend.spring.converter.PostConverter; import friend.spring.converter.SseConverter; import friend.spring.domain.*; import friend.spring.domain.enums.AlarmType; +import friend.spring.domain.enums.ReportType; import friend.spring.domain.mapping.Comment_choice; import friend.spring.domain.mapping.Comment_like; import friend.spring.repository.*; @@ -38,6 +41,8 @@ public class CommentServiceImpl implements CommentService { private final CommentChoiceRepository commentChoiceRepository; private final PointRepository pointRepository; private final AlarmRepository alarmRepository; + private final ReportRepository reportRepository; + private final ReportCategoryRepository reportCategoryRepository; private final UserService userService; private final PostService postService; private final JwtTokenProvider jwtTokenProvider; @@ -400,5 +405,33 @@ public void deleteComment(Long postId, Long commentId, HttpServletRequest reques } comment.updateStateToDeleted(); } + + @Override + public Report createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2) { + Long userId = jwtTokenProvider.getCurrentUser(request2); + + Optional optionalComment = commentRepository.findById(commentId); + if (optionalComment.isEmpty()) { + this.checkComment(false); + } + + Optional optionalUser = userRepository.findById(userId); + if (optionalUser.isEmpty()) { + userService.checkUser(false); + } + + Comment comment = optionalComment.get(); + User user = optionalUser.get(); + + // 이미 신고된 건인지 확인 + Optional optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.COMMENT, commentId, userId); + if (!optionalReport.isEmpty()) { + throw new CommentHandler(COMMENT_REPORT_DUPLICATE); + } + + ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory()); + Report report = CommentConverter.toReportComment(comment, user, reportCategory); + return reportRepository.save(report); + } } diff --git a/src/main/java/friend/spring/web/controller/CommentRestController.java b/src/main/java/friend/spring/web/controller/CommentRestController.java index 583516c..534abc0 100644 --- a/src/main/java/friend/spring/web/controller/CommentRestController.java +++ b/src/main/java/friend/spring/web/controller/CommentRestController.java @@ -2,7 +2,9 @@ import friend.spring.apiPayload.ApiResponse; import friend.spring.converter.CommentConverter; +import friend.spring.converter.PostConverter; import friend.spring.domain.Comment; +import friend.spring.domain.Report; import friend.spring.domain.mapping.Comment_choice; import friend.spring.domain.mapping.Comment_like; import friend.spring.service.CommentService; @@ -197,4 +199,27 @@ public ApiResponse deleteComment( commentService.deleteComment(postId, commentId, request); return ApiResponse.onSuccess(null); } + + // 댓글 신고 + @PostMapping("/posts/{post-id}/comment/{comment-id}/report") + @Operation(summary = "댓글 신고 API", description = "댓글 신고하는 API입니다. ex) /posts/1/report") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 요청에 성공했습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER4001", description = "NOT_FOUND, 사용자를 찾을 수 없습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4001", description = "NOT_FOUND, 글을 찾을 수 없습니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4018", description = "BAD_REQUEST, 이 유저가 해당 글을 신고한 신고 내역 데이터가 이미 존재합니다."), + }) + @Parameters({ + @Parameter(name = "post-id", description = "path variable - 글 아이디"), + @Parameter(name = "atk", description = "RequestHeader - 로그인한 사용자의 accessToken"), + }) + public ApiResponse createReportComment( + @PathVariable("comment-id") Long commentId, + @RequestBody CommentRequestDTO.CommentReportReq request, + @RequestHeader("atk") String atk, + HttpServletRequest request2 + ) { + Report commentReport = commentService.createReportComment(commentId, request, request2); + return ApiResponse.onSuccess(CommentConverter.toCommentReportRes(commentReport)); + } } diff --git a/src/main/java/friend/spring/web/dto/CommentRequestDTO.java b/src/main/java/friend/spring/web/dto/CommentRequestDTO.java index 96e1ee7..82e9559 100644 --- a/src/main/java/friend/spring/web/dto/CommentRequestDTO.java +++ b/src/main/java/friend/spring/web/dto/CommentRequestDTO.java @@ -27,4 +27,12 @@ public static class commentEditReq { @NotBlank String content; } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class CommentReportReq { + String reportCategory; + } } diff --git a/src/main/java/friend/spring/web/dto/CommentResponseDTO.java b/src/main/java/friend/spring/web/dto/CommentResponseDTO.java index 790d956..2726538 100644 --- a/src/main/java/friend/spring/web/dto/CommentResponseDTO.java +++ b/src/main/java/friend/spring/web/dto/CommentResponseDTO.java @@ -70,4 +70,12 @@ public static class myCommentRes { Integer commentLike; Integer reComment; } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class CommentReportRes { + Long reportId; + } } From 94c0f47b8b84f800a9a93b6952eafd7205da084a Mon Sep 17 00:00:00 2001 From: Min Yeong Park Date: Sun, 2 Jun 2024 18:52:20 +0900 Subject: [PATCH 3/5] =?UTF-8?q?#195=20Refactor:=20=EB=8C=93=EA=B8=80=20?= =?UTF-8?q?=EC=8B=A0=EA=B3=A0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../friend/spring/apiPayload/code/status/ErrorStatus.java | 4 +--- .../friend/spring/web/controller/CommentRestController.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java index 698c9a5..2daa04f 100644 --- a/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/friend/spring/apiPayload/code/status/ErrorStatus.java @@ -8,9 +8,7 @@ @Getter @AllArgsConstructor -public enum -ErrorStatus implements BaseErrorCode { - +public enum ErrorStatus implements BaseErrorCode { // 가장 일반적인 응답 _INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON5000", "서버 에러, 관리자에게 문의 바랍니다."), diff --git a/src/main/java/friend/spring/web/controller/CommentRestController.java b/src/main/java/friend/spring/web/controller/CommentRestController.java index 534abc0..9c46d91 100644 --- a/src/main/java/friend/spring/web/controller/CommentRestController.java +++ b/src/main/java/friend/spring/web/controller/CommentRestController.java @@ -207,7 +207,7 @@ public ApiResponse deleteComment( @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 요청에 성공했습니다."), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER4001", description = "NOT_FOUND, 사용자를 찾을 수 없습니다."), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4001", description = "NOT_FOUND, 글을 찾을 수 없습니다."), - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST4018", description = "BAD_REQUEST, 이 유저가 해당 글을 신고한 신고 내역 데이터가 이미 존재합니다."), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMENT4008", description = "BAD_REQUEST, 이 유저가 해당 댓글을 신고한 신고 내역 데이터가 이미 존재합니다."), }) @Parameters({ @Parameter(name = "post-id", description = "path variable - 글 아이디"), From 72bb5831b80f0fb369b005de3c36611b75616ed4 Mon Sep 17 00:00:00 2001 From: Min Yeong Park Date: Sun, 2 Jun 2024 19:39:32 +0900 Subject: [PATCH 4/5] =?UTF-8?q?#195=20Refactor:=20ResponseDTO=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=A4=91=EB=B3=B5=EB=90=9C=20=EC=8B=A0=EA=B3=A0?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=EC=97=90=20=EB=8C=80=ED=95=B4=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 --- .../friend/spring/converter/CommentConverter.java | 6 ++++-- .../java/friend/spring/converter/PostConverter.java | 8 ++++---- .../java/friend/spring/service/CommentService.java | 3 ++- .../friend/spring/service/CommentServiceImpl.java | 13 ++++++++++--- .../java/friend/spring/service/PostService.java | 3 +-- .../java/friend/spring/service/PostServiceImpl.java | 12 +++++++++--- .../web/controller/CommentRestController.java | 3 ++- .../spring/web/controller/PostRestController.java | 5 +---- .../friend/spring/web/dto/CommentResponseDTO.java | 3 +++ .../java/friend/spring/web/dto/PostResponseDTO.java | 13 ++++++++++++- 10 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/main/java/friend/spring/converter/CommentConverter.java b/src/main/java/friend/spring/converter/CommentConverter.java index 0478464..40e5efe 100644 --- a/src/main/java/friend/spring/converter/CommentConverter.java +++ b/src/main/java/friend/spring/converter/CommentConverter.java @@ -116,9 +116,11 @@ public static CommentResponseDTO.myCommentRes toMyCommentResDTO(Comment comment) .build(); } - public static CommentResponseDTO.CommentReportRes toCommentReportRes(Report report) { + public static CommentResponseDTO.CommentReportRes toCommentReportRes(PostResponseDTO.ReportResult reportResult) { return CommentResponseDTO.CommentReportRes.builder() - .reportId(report.getId()) + .reportId(reportResult.getReport().getId()) + .createdAt(reportResult.getReport().getCreatedAt()) + .duplicatedReport(reportResult.getDuplicatedReport()) .build(); } diff --git a/src/main/java/friend/spring/converter/PostConverter.java b/src/main/java/friend/spring/converter/PostConverter.java index f6c45fc..5ed5b47 100644 --- a/src/main/java/friend/spring/converter/PostConverter.java +++ b/src/main/java/friend/spring/converter/PostConverter.java @@ -20,10 +20,8 @@ import friend.spring.domain.mapping.Post_like; import friend.spring.domain.mapping.Post_scrap; -import friend.spring.web.dto.CandidateResponseDTO; import friend.spring.web.dto.PostRequestDTO; import friend.spring.web.dto.PostResponseDTO; -import software.amazon.awssdk.services.s3.endpoints.internal.Value; import java.util.List; @@ -1006,9 +1004,11 @@ public static Report toReportPost(Post post, User user, ReportCategory reportCat .build(); } - public static PostResponseDTO.PostReportRes toPostReportRes(Report report) { + public static PostResponseDTO.PostReportRes toPostReportRes(PostResponseDTO.ReportResult reportResult) { return PostResponseDTO.PostReportRes.builder() - .reportId(report.getId()) + .reportId(reportResult.getReport().getId()) + .createdAt(reportResult.getReport().getCreatedAt()) + .duplicatedReport(reportResult.getDuplicatedReport()) .build(); } diff --git a/src/main/java/friend/spring/service/CommentService.java b/src/main/java/friend/spring/service/CommentService.java index 2d9e309..f0699e9 100644 --- a/src/main/java/friend/spring/service/CommentService.java +++ b/src/main/java/friend/spring/service/CommentService.java @@ -6,6 +6,7 @@ import friend.spring.domain.mapping.Comment_like; import friend.spring.web.dto.CommentRequestDTO; import friend.spring.web.dto.CommentResponseDTO; +import friend.spring.web.dto.PostResponseDTO; import org.springframework.data.domain.Page; import javax.servlet.http.HttpServletRequest; @@ -38,5 +39,5 @@ public interface CommentService { void deleteComment(Long postId, Long commentId, HttpServletRequest request); - Report createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2); + PostResponseDTO.ReportResult createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2); } diff --git a/src/main/java/friend/spring/service/CommentServiceImpl.java b/src/main/java/friend/spring/service/CommentServiceImpl.java index 5bacee6..7633b87 100644 --- a/src/main/java/friend/spring/service/CommentServiceImpl.java +++ b/src/main/java/friend/spring/service/CommentServiceImpl.java @@ -17,6 +17,7 @@ import friend.spring.security.JwtTokenProvider; import friend.spring.web.dto.CommentRequestDTO; import friend.spring.web.dto.CommentResponseDTO; +import friend.spring.web.dto.PostResponseDTO; import friend.spring.web.dto.SseResponseDTO; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -407,7 +408,7 @@ public void deleteComment(Long postId, Long commentId, HttpServletRequest reques } @Override - public Report createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2) { + public PostResponseDTO.ReportResult createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2) { Long userId = jwtTokenProvider.getCurrentUser(request2); Optional optionalComment = commentRepository.findById(commentId); @@ -426,12 +427,18 @@ public Report createReportComment(Long commentId, CommentRequestDTO.CommentRepor // 이미 신고된 건인지 확인 Optional optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.COMMENT, commentId, userId); if (!optionalReport.isEmpty()) { - throw new CommentHandler(COMMENT_REPORT_DUPLICATE); + return PostResponseDTO.ReportResult.builder() + .report(optionalReport.get()) + .duplicatedReport(true) + .build(); } ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory()); Report report = CommentConverter.toReportComment(comment, user, reportCategory); - return reportRepository.save(report); + return PostResponseDTO.ReportResult.builder() + .report(reportRepository.save(report)) + .duplicatedReport(false) + .build(); } } diff --git a/src/main/java/friend/spring/service/PostService.java b/src/main/java/friend/spring/service/PostService.java index e242862..cd4f709 100644 --- a/src/main/java/friend/spring/service/PostService.java +++ b/src/main/java/friend/spring/service/PostService.java @@ -3,7 +3,6 @@ import friend.spring.domain.Candidate; import friend.spring.domain.Post; -import friend.spring.domain.Report; import friend.spring.domain.User; import friend.spring.domain.mapping.Post_like; import friend.spring.domain.mapping.Post_scrap; @@ -50,6 +49,6 @@ public interface PostService { void deleteScrapPost(Long postId, HttpServletRequest request); - Report createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2); + PostResponseDTO.ReportResult createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2); } diff --git a/src/main/java/friend/spring/service/PostServiceImpl.java b/src/main/java/friend/spring/service/PostServiceImpl.java index 4dd8b2a..7250e12 100644 --- a/src/main/java/friend/spring/service/PostServiceImpl.java +++ b/src/main/java/friend/spring/service/PostServiceImpl.java @@ -474,7 +474,7 @@ public void deleteScrapPost(Long postId, HttpServletRequest request) { } @Override - public Report createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2) { + public PostResponseDTO.ReportResult createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2) { Long userId = jwtTokenProvider.getCurrentUser(request2); Optional optionalPost = postRepository.findById(postId); @@ -493,11 +493,17 @@ public Report createReportPost(Long postId, PostRequestDTO.PostReportReq request // 이미 신고된 건인지 확인 Optional optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.POST, postId, userId); if (!optionalReport.isEmpty()) { - throw new PostHandler(POST_REPORT_DUPLICATE); + return PostResponseDTO.ReportResult.builder() + .report(optionalReport.get()) + .duplicatedReport(true) + .build(); } ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory()); Report report = PostConverter.toReportPost(post, user, reportCategory); - return reportRepository.save(report); + return PostResponseDTO.ReportResult.builder() + .report(reportRepository.save(report)) + .duplicatedReport(false) + .build(); } } diff --git a/src/main/java/friend/spring/web/controller/CommentRestController.java b/src/main/java/friend/spring/web/controller/CommentRestController.java index 9c46d91..ea05999 100644 --- a/src/main/java/friend/spring/web/controller/CommentRestController.java +++ b/src/main/java/friend/spring/web/controller/CommentRestController.java @@ -10,6 +10,7 @@ import friend.spring.service.CommentService; import friend.spring.web.dto.CommentRequestDTO; import friend.spring.web.dto.CommentResponseDTO; +import friend.spring.web.dto.PostResponseDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -219,7 +220,7 @@ public ApiResponse createReportComment( @RequestHeader("atk") String atk, HttpServletRequest request2 ) { - Report commentReport = commentService.createReportComment(commentId, request, request2); + PostResponseDTO.ReportResult commentReport = commentService.createReportComment(commentId, request, request2); return ApiResponse.onSuccess(CommentConverter.toCommentReportRes(commentReport)); } } diff --git a/src/main/java/friend/spring/web/controller/PostRestController.java b/src/main/java/friend/spring/web/controller/PostRestController.java index 746c972..d018213 100644 --- a/src/main/java/friend/spring/web/controller/PostRestController.java +++ b/src/main/java/friend/spring/web/controller/PostRestController.java @@ -5,7 +5,6 @@ import friend.spring.converter.PostConverter; import friend.spring.domain.Candidate; import friend.spring.domain.Post; -import friend.spring.domain.Report; import friend.spring.repository.PostRepository; import friend.spring.service.JwtTokenService; import friend.spring.service.PostQueryService; @@ -27,8 +26,6 @@ import javax.validation.Valid; import java.io.IOException; -import static friend.spring.apiPayload.code.status.ErrorStatus.POST_REPORT_DUPLICATE; - @RestController @RequiredArgsConstructor @Validated @@ -326,7 +323,7 @@ public ApiResponse createReportPost( @RequestHeader("atk") String atk, HttpServletRequest request2 ) { - Report postReport = postService.createReportPost(postId, request, request2); + PostResponseDTO.ReportResult postReport = postService.createReportPost(postId, request, request2); return ApiResponse.onSuccess(PostConverter.toPostReportRes(postReport)); } } diff --git a/src/main/java/friend/spring/web/dto/CommentResponseDTO.java b/src/main/java/friend/spring/web/dto/CommentResponseDTO.java index 2726538..b97f840 100644 --- a/src/main/java/friend/spring/web/dto/CommentResponseDTO.java +++ b/src/main/java/friend/spring/web/dto/CommentResponseDTO.java @@ -1,5 +1,6 @@ package friend.spring.web.dto; +import friend.spring.domain.Report; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -77,5 +78,7 @@ public static class myCommentRes { @AllArgsConstructor public static class CommentReportRes { Long reportId; + LocalDateTime createdAt; + Boolean duplicatedReport; } } diff --git a/src/main/java/friend/spring/web/dto/PostResponseDTO.java b/src/main/java/friend/spring/web/dto/PostResponseDTO.java index acdf06d..c74b4de 100644 --- a/src/main/java/friend/spring/web/dto/PostResponseDTO.java +++ b/src/main/java/friend/spring/web/dto/PostResponseDTO.java @@ -1,8 +1,8 @@ package friend.spring.web.dto; +import friend.spring.domain.Report; import friend.spring.domain.enums.PostType; import friend.spring.domain.enums.PostVoteType; -import io.swagger.models.auth.In; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -165,5 +165,16 @@ public static class ScrapCreateRes { @AllArgsConstructor public static class PostReportRes { Long reportId; + LocalDateTime createdAt; + Boolean duplicatedReport; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class ReportResult { + Report report; + Boolean duplicatedReport; } } \ No newline at end of file From 9e8633c93e8a9bea24a13aa843a5ca72c0c69953 Mon Sep 17 00:00:00 2001 From: Min Yeong Park Date: Sun, 14 Jul 2024 10:28:23 +0900 Subject: [PATCH 5/5] =?UTF-8?q?#195=20Refactor:=20EB=20environment=20name?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev_deploy.yml b/.github/workflows/dev_deploy.yml index 37c9c9d..94f1e4a 100644 --- a/.github/workflows/dev_deploy.yml +++ b/.github/workflows/dev_deploy.yml @@ -54,7 +54,7 @@ jobs: aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }} aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }} application_name: solution-friend-dev - environment_name: Solution-friend-dev-env + environment_name: Solution-friend-dev-env-1 version_label: github-action-${{ steps.current-time.outputs.formattedTime }} region: ap-northeast-2 deployment_package: deploy/deploy.zip