Skip to content

게시물 신고 기능 구현#36

Open
itzjb wants to merge 4 commits intodevelopfrom
feat/post-report
Open

게시물 신고 기능 구현#36
itzjb wants to merge 4 commits intodevelopfrom
feat/post-report

Conversation

@itzjb
Copy link
Copy Markdown
Contributor

@itzjb itzjb commented Mar 29, 2026

💡 배경 및 개요

게시물 별 신고 기능 구현했습니다.

📃 작업내용

신고 사유 ENUM과 상세, 그에 따른 신고 기능 등을 구현했습니다.

🔀 변경사항

게시물 별 신고 기능이 구현되었습니다.

🙋‍♂️ 리뷰노트

✅ PR 체크리스트

템플릿 체크리스트 말고도 추가적으로 필요한 체크리스트는 추가해주세요!

  • 이 작업으로 인해 변경이 필요한 문서가 변경되었나요? (e.g. .env, 노션, README)
  • 이 작업을 하고나서 공유해야할 팀원들에게 공유되었나요? (e.g. "API 개발 완료됐어요", "환경값 추가되었어요")
  • 작업한 코드가 정상적으로 동작하나요?
  • Merge 대상 브랜치가 올바른가요?
  • PR과 관련 없는 작업이 있지는 않나요?

🎸 기타

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements a post reporting feature, introducing the Report entity, a ReportReason enum, and the necessary service and controller logic to handle report submissions. The reviewer suggested enhancing the CreateReportService with validation logic to prevent users from reporting their own posts and to block duplicate reports. Additionally, it was recommended to replace the static factory method in the Report entity with the Builder pattern to improve object creation and maintainability.

User reporter = userRepository.findByUserId(userDetails.getUserId())
.orElseThrow(() -> UserNotFoundException.EXCEPTION);

Report report = Report.create(post, reporter, request.getReason(), request.getDetail());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

신고 기능에 대한 몇 가지 중요한 검증 로직이 누락된 것으로 보입니다. 아래 두 가지 검증을 추가하는 것을 강력히 권장합니다.

  1. 자신이 작성한 게시물 신고 방지: 사용자가 자신의 게시물을 신고하는 것은 일반적인 시나리오가 아니므로, 게시물 작성자와 신고자가 동일 인물인지 확인하여 이를 방지해야 합니다.
  2. 중복 신고 방지: 한 사용자가 동일한 게시물에 대해 여러 번 신고하는 것을 막아 시스템 악용을 방지해야 합니다.

아래와 같이 reporter를 조회한 후, Report 객체를 생성하기 전에 검증 로직을 추가할 수 있습니다.

// 자신의 게시물 신고 방지
if (post.getWriter().getId().equals(reporter.getId())) {
    // 적절한 예외(e.g., 400 Bad Request)를 발생시켜야 합니다.
    throw new SelfReportNotAllowedException("자신의 게시물은 신고할 수 없습니다.");
}

// 중복 신고 방지 (ReportRepository에 existsByPostAndReporter 메서드 추가 필요)
if (reportRepository.existsByPostAndReporter(post, reporter)) {
    // 적절한 예외(e.g., 409 Conflict)를 발생시켜야 합니다.
    throw new DuplicateReportException("이미 신고한 게시물입니다.");
}

위의 중복 신고 방지 로직을 위해 ReportRepository에 다음 메서드를 추가해야 합니다.

// ReportRepository.java
boolean existsByPostAndReporter(Post post, User reporter);

Comment on lines +41 to +48
public static Report create(Post post, User reporter, ReportReason reason, String detail) {
Report report = new Report();
report.post = post;
report.reporter = reporter;
report.reason = reason;
report.detail = detail;
return report;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

현재의 정적 팩토리 메서드는 new Report()로 빈 객체를 생성한 후 필드를 수동으로 할당하고 있습니다. 이 방식보다는 빌더 패턴을 사용하여 객체의 불변성을 보장하고 생성 로직을 더 명확하게 만드는 것이 좋습니다.

@Builder 어노테이션을 클래스에 추가하고, 이 create 메서드를 제거하는 것을 고려해보세요. 서비스 레이어에서는 빌더를 사용하여 Report 객체를 생성하게 됩니다.

Report.java 수정 제안:

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Report extends BaseIdEntity {
    // ... 필드들 ...
    // create() 메서드는 제거합니다.
}

CreateReportService.java에서의 사용 예시:

Report report = Report.builder()
        .post(post)
        .reporter(reporter)
        .reason(request.getReason())
        .detail(request.getDetail())
        .build();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant