-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 신고 기능 구현 #402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nayonsoso
merged 8 commits into
solid-connection:develop
from
nayonsoso:feat/401-create-report
Jul 25, 2025
Merged
feat: 신고 기능 구현 #402
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5613230
feat: 신고 도메인 생성
nayonsoso 8a9c196
feat: 신고 요청 dto 생성
nayonsoso 8f82192
feat: 신고 레포지토리 생성
nayonsoso 08716d1
feat: 신고 기능 서비스 구현
nayonsoso 26667ea
test: 신고 테스트 작성
nayonsoso bdc675c
feat: 신고 컨트롤러 생성
nayonsoso 0328fa4
refactor: '신고 유형' 컬럼 이름 변경
nayonsoso ad803d9
refactor: findBy 보다 성능이 좋은 existsBy 로 존재 여부 검증
nayonsoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/com/example/solidconnection/report/controller/ReportController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.example.solidconnection.report.controller; | ||
|
|
||
| import com.example.solidconnection.common.resolver.AuthorizedUser; | ||
| import com.example.solidconnection.report.dto.ReportRequest; | ||
| import com.example.solidconnection.report.service.ReportService; | ||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/reports") | ||
| public class ReportController { | ||
|
|
||
| private final ReportService reportService; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<Void> createReport( | ||
| @AuthorizedUser SiteUser siteUser, | ||
| @Valid @RequestBody ReportRequest reportRequest | ||
| ) { | ||
| reportService.createReport(siteUser.getId(), reportRequest); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/example/solidconnection/report/domain/Report.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.example.solidconnection.report.domain; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import jakarta.persistence.UniqueConstraint; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Entity | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Table(uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "uk_report_reporter_id_target_type_target_id", | ||
| columnNames = {"reporter_id", "target_type", "target_id"} | ||
| ) | ||
| }) | ||
| public class Report { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "reporter_id") | ||
| private long reporterId; | ||
|
|
||
| @Column(name = "report_type") | ||
| @Enumerated(value = EnumType.STRING) | ||
| private ReportType reportType; | ||
|
|
||
| @Column(name = "target_type") | ||
| @Enumerated(value = EnumType.STRING) | ||
| private TargetType targetType; | ||
|
|
||
| @Column(name = "target_id") | ||
| private long targetId; | ||
|
|
||
| public Report(long reporterId, ReportType reportType, TargetType targetType, long targetId) { | ||
| this.reportType = reportType; | ||
| this.reporterId = reporterId; | ||
| this.targetType = targetType; | ||
| this.targetId = targetId; | ||
| } | ||
| } | ||
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/solidconnection/report/domain/ReportType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.solidconnection.report.domain; | ||
|
|
||
| public enum ReportType { | ||
|
|
||
| ADVERTISEMENT, // 광고 | ||
| SPAM, // 낚시/도배 | ||
| PERSONAL_INFO_EXPOSURE, // 개인정보 노출 | ||
| PORNOGRAPHY, // 선정성 | ||
| COPYRIGHT_INFRINGEMENT, // 저작권 침해 | ||
| ILLEGAL_ACTIVITY, // 불법 행위 | ||
| IMPERSONATION, // 사칭/도용 | ||
| INSULT, // 욕설/비하 | ||
| ; | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/solidconnection/report/domain/TargetType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.solidconnection.report.domain; | ||
|
|
||
| public enum TargetType { | ||
|
|
||
| POST, | ||
| ; | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/solidconnection/report/dto/ReportRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.example.solidconnection.report.dto; | ||
|
|
||
| import com.example.solidconnection.report.domain.ReportType; | ||
| import com.example.solidconnection.report.domain.TargetType; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record ReportRequest( | ||
| @NotNull(message = "신고 유형을 선택해주세요.") | ||
| ReportType reportType, | ||
|
|
||
| @NotNull(message = "신고 대상을 포함해주세요.") | ||
| TargetType targetType, | ||
|
|
||
| long targetId | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion targetId 필드에 검증 로직 추가를 고려해보세요. 현재 + @Positive(message = "유효한 대상 ID를 입력해주세요.")
long targetId필요한 import도 추가해주세요: +import jakarta.validation.constraints.Positive;🤖 Prompt for AI Agents |
||
| ) { | ||
|
|
||
| } | ||
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/solidconnection/report/repository/ReportRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.example.solidconnection.report.repository; | ||
|
|
||
| import com.example.solidconnection.report.domain.Report; | ||
| import com.example.solidconnection.report.domain.TargetType; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
|
||
| boolean existsByReporterIdAndTargetTypeAndTargetId(long reporterId, TargetType targetType, long targetId); | ||
| } |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/example/solidconnection/report/service/ReportService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package com.example.solidconnection.report.service; | ||
|
|
||
| import com.example.solidconnection.common.exception.CustomException; | ||
| import com.example.solidconnection.common.exception.ErrorCode; | ||
| import com.example.solidconnection.community.post.repository.PostRepository; | ||
| import com.example.solidconnection.report.domain.Report; | ||
| import com.example.solidconnection.report.domain.TargetType; | ||
| import com.example.solidconnection.report.dto.ReportRequest; | ||
| import com.example.solidconnection.report.repository.ReportRepository; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import jakarta.transaction.Transactional; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class ReportService { | ||
|
|
||
| private final ReportRepository reportRepository; | ||
| private final SiteUserRepository siteUserRepository; | ||
| private final PostRepository postRepository; | ||
|
|
||
| @Transactional | ||
| public void createReport(long reporterId, ReportRequest request) { | ||
| validateReporterExists(reporterId); | ||
| validateTargetExists(request.targetType(), request.targetId()); | ||
| validateFirstReportByUser(reporterId, request.targetType(), request.targetId()); | ||
|
|
||
| Report report = new Report(reporterId, request.reportType(), request.targetType(), request.targetId()); | ||
| reportRepository.save(report); | ||
| } | ||
|
|
||
| private void validateReporterExists(long reporterId) { | ||
| if (!siteUserRepository.existsById(reporterId)) { | ||
| throw new CustomException(ErrorCode.USER_NOT_FOUND); | ||
| } | ||
| } | ||
|
|
||
| private void validateTargetExists(TargetType targetType, long targetId) { | ||
| if (targetType == TargetType.POST && !postRepository.existsById(targetId)) { | ||
| throw new CustomException(ErrorCode.REPORT_TARGET_NOT_FOUND); | ||
| } | ||
| } | ||
nayonsoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private void validateFirstReportByUser(long reporterId, TargetType targetType, long targetId) { | ||
| if (reportRepository.existsByReporterIdAndTargetTypeAndTargetId(reporterId, targetType, targetId)) { | ||
| throw new CustomException(ErrorCode.ALREADY_REPORTED_BY_CURRENT_USER); | ||
| } | ||
| } | ||
nayonsoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/main/resources/db/migration/V24__create_report_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| CREATE TABLE report | ||
| ( | ||
| id BIGINT NOT NULL AUTO_INCREMENT, | ||
| reporter_id BIGINT NOT NULL, | ||
| target_type ENUM ('POST') NOT NULL, | ||
| target_id BIGINT NOT NULL, | ||
| report_type ENUM ('ADVERTISEMENT', 'SPAM', 'PERSONAL_INFO_EXPOSURE', 'PORNOGRAPHY', 'COPYRIGHT_INFRINGEMENT', 'ILLEGAL_ACTIVITY', 'IMPERSONATION', 'INSULT') NOT NULL, | ||
| primary key (id), | ||
| constraint fk_report_reporter_id foreign key (reporter_id) references site_user (id), | ||
| unique uk_report_reporter_id_target_type_target_id (reporter_id, target_type, target_id) | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/test/java/com/example/solidconnection/report/fixture/ReportFixture.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.example.solidconnection.report.fixture; | ||
|
|
||
| import com.example.solidconnection.report.domain.Report; | ||
| import com.example.solidconnection.report.domain.TargetType; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class ReportFixture { | ||
|
|
||
| private final ReportFixtureBuilder reportFixtureBuilder; | ||
|
|
||
| public Report 신고(long reporterId, TargetType targetType, long targetId) { | ||
| return reportFixtureBuilder.report() | ||
| .reporterId(reporterId) | ||
| .targetType(targetType) | ||
| .targetId(targetId) | ||
| .create(); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/example/solidconnection/report/fixture/ReportFixtureBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.example.solidconnection.report.fixture; | ||
|
|
||
| import com.example.solidconnection.report.domain.Report; | ||
| import com.example.solidconnection.report.domain.ReportType; | ||
| import com.example.solidconnection.report.domain.TargetType; | ||
| import com.example.solidconnection.report.repository.ReportRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.test.context.TestComponent; | ||
|
|
||
| @TestComponent | ||
| @RequiredArgsConstructor | ||
| public class ReportFixtureBuilder { | ||
|
|
||
| private final ReportRepository reportRepository; | ||
|
|
||
| private long reporterId; | ||
| private TargetType targetType; | ||
| private long targetId; | ||
| private ReportType reportType = ReportType.ADVERTISEMENT; | ||
|
|
||
| public ReportFixtureBuilder report() { | ||
| return new ReportFixtureBuilder(reportRepository); | ||
| } | ||
|
|
||
| public ReportFixtureBuilder reporterId(long reporterId) { | ||
| this.reporterId = reporterId; | ||
| return this; | ||
| } | ||
|
|
||
| public ReportFixtureBuilder targetType(TargetType targetType) { | ||
| this.targetType = targetType; | ||
| return this; | ||
| } | ||
|
|
||
| public ReportFixtureBuilder targetId(long targetId) { | ||
| this.targetId = targetId; | ||
| return this; | ||
| } | ||
|
|
||
| public ReportFixtureBuilder reasonType(ReportType reportType) { | ||
| this.reportType = reportType; | ||
| return this; | ||
| } | ||
|
|
||
| public Report create() { | ||
| Report report = new Report( | ||
| reporterId, | ||
| reportType, | ||
| targetType, | ||
| targetId | ||
| ); | ||
| return reportRepository.save(report); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.