Skip to content

Commit

Permalink
Merge branch 'develop' into feat#201
Browse files Browse the repository at this point in the history
  • Loading branch information
ls-rain authored Aug 18, 2024
2 parents 618c1ad + 630643a commit 3e6ae8d
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

@Getter
@AllArgsConstructor
public enum
ErrorStatus implements BaseErrorCode {

public enum ErrorStatus implements BaseErrorCode {

// 가장 일반적인 응답
_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON5000", "서버 에러, 관리자에게 문의 바랍니다."),
Expand Down Expand Up @@ -61,7 +59,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", "댓글을 찾을 수 없습니다."),
Expand All @@ -71,6 +71,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", "알림이 없습니다"),
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/friend/spring/converter/CommentConverter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -116,4 +116,20 @@ public static CommentResponseDTO.myCommentRes toMyCommentResDTO(Comment comment)
.build();
}

public static CommentResponseDTO.CommentReportRes toCommentReportRes(PostResponseDTO.ReportResult reportResult) {
return CommentResponseDTO.CommentReportRes.builder()
.reportId(reportResult.getReport().getId())
.createdAt(reportResult.getReport().getCreatedAt())
.duplicatedReport(reportResult.getDuplicatedReport())
.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();
}
}
20 changes: 18 additions & 2 deletions src/main/java/friend/spring/converter/PostConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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;
Expand All @@ -20,10 +21,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;

Expand Down Expand Up @@ -997,6 +996,23 @@ public static PostResponseDTO.ScrapCreateRes toScrapCreateRes(Post_scrap post_sc
.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(PostResponseDTO.ReportResult reportResult) {
return PostResponseDTO.PostReportRes.builder()
.reportId(reportResult.getReport().getId())
.createdAt(reportResult.getReport().getCreatedAt())
.duplicatedReport(reportResult.getDuplicatedReport())
.build();
}

public static PostResponseDTO.PostSearchRes PostSearchResDTO(Post post,Long userId) {
Integer likeCount = post.getPostLikeList().size();
Integer commentCount = post.getCommentList().size();
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/friend/spring/domain/Report.java
Original file line number Diff line number Diff line change
@@ -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.*;

Expand All @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/friend/spring/domain/ReportCategory.java
Original file line number Diff line number Diff line change
@@ -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<Report> reportList = new ArrayList<>();

}

5 changes: 0 additions & 5 deletions src/main/java/friend/spring/domain/enums/ReportCategory.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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, Long> {
ReportCategory findByName(String category);
}
11 changes: 11 additions & 0 deletions src/main/java/friend/spring/repository/ReportRepository.java
Original file line number Diff line number Diff line change
@@ -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<Report, Long> {
Optional<Report> findByTargetTypeAndTargetIdAndUserId(ReportType post, Long postId, Long userId);
}
4 changes: 4 additions & 0 deletions src/main/java/friend/spring/service/CommentService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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;
import friend.spring.web.dto.CommentResponseDTO;
import friend.spring.web.dto.PostResponseDTO;
import org.springframework.data.domain.Page;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -36,4 +38,6 @@ public interface CommentService {
Page<Comment> getMyCommentList(Long userId, Integer page);

void deleteComment(Long postId, Long commentId, HttpServletRequest request);

PostResponseDTO.ReportResult createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2);
}
40 changes: 40 additions & 0 deletions src/main/java/friend/spring/service/CommentServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
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.*;
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;
Expand All @@ -38,6 +42,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;
Expand Down Expand Up @@ -400,5 +406,39 @@ public void deleteComment(Long postId, Long commentId, HttpServletRequest reques
}
comment.updateStateToDeleted();
}

@Override
public PostResponseDTO.ReportResult createReportComment(Long commentId, CommentRequestDTO.CommentReportReq request, HttpServletRequest request2) {
Long userId = jwtTokenProvider.getCurrentUser(request2);

Optional<Comment> optionalComment = commentRepository.findById(commentId);
if (optionalComment.isEmpty()) {
this.checkComment(false);
}

Optional<User> optionalUser = userRepository.findById(userId);
if (optionalUser.isEmpty()) {
userService.checkUser(false);
}

Comment comment = optionalComment.get();
User user = optionalUser.get();

// 이미 신고된 건인지 확인
Optional<Report> optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.COMMENT, commentId, userId);
if (!optionalReport.isEmpty()) {
return PostResponseDTO.ReportResult.builder()
.report(optionalReport.get())
.duplicatedReport(true)
.build();
}

ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory());
Report report = CommentConverter.toReportComment(comment, user, reportCategory);
return PostResponseDTO.ReportResult.builder()
.report(reportRepository.save(report))
.duplicatedReport(false)
.build();
}
}

4 changes: 4 additions & 0 deletions src/main/java/friend/spring/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public interface PostService {
Post_scrap createScrapPost(Long postId, HttpServletRequest request);

void deleteScrapPost(Long postId, HttpServletRequest request);


PostResponseDTO.ReportResult createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2);

}
37 changes: 37 additions & 0 deletions src/main/java/friend/spring/service/PostServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import friend.spring.domain.Redis.SearchLog;
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;
Expand Down Expand Up @@ -44,6 +45,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;
Expand Down Expand Up @@ -476,4 +479,38 @@ public void deleteScrapPost(Long postId, HttpServletRequest request) {
Post_scrap post_scrap = optionalPost_scrap.get();
postScrapRepository.delete(post_scrap);
}

@Override
public PostResponseDTO.ReportResult createReportPost(Long postId, PostRequestDTO.PostReportReq request, HttpServletRequest request2) {
Long userId = jwtTokenProvider.getCurrentUser(request2);

Optional<Post> optionalPost = postRepository.findById(postId);
if (optionalPost.isEmpty()) {
this.checkPost(false);
}

Optional<User> optionalUser = userRepository.findById(userId);
if (optionalUser.isEmpty()) {
userService.checkUser(false);
}

Post post = optionalPost.get();
User user = optionalUser.get();

// 이미 신고된 건인지 확인
Optional<Report> optionalReport = reportRepository.findByTargetTypeAndTargetIdAndUserId(ReportType.POST, postId, userId);
if (!optionalReport.isEmpty()) {
return PostResponseDTO.ReportResult.builder()
.report(optionalReport.get())
.duplicatedReport(true)
.build();
}

ReportCategory reportCategory = reportCategoryRepository.findByName(request.getReportCategory());
Report report = PostConverter.toReportPost(post, user, reportCategory);
return PostResponseDTO.ReportResult.builder()
.report(reportRepository.save(report))
.duplicatedReport(false)
.build();
}
}
Loading

0 comments on commit 3e6ae8d

Please sign in to comment.