-
Notifications
You must be signed in to change notification settings - Fork 20
[4주차] 이건희/[feat] 추가 API 구현 #147
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
Open
KunHeeLee7
wants to merge
4
commits into
Leets-Official:이건희/main
Choose a base branch
from
KunHeeLee7:이건희/4주차
base: 이건희/main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "\uC774\uAC74\uD76C/4\uC8FC\uCC28"
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
14 changes: 14 additions & 0 deletions
14
LeeKunHee/src/main/java/com/leets/assignment/domain/post/entity/PostStatus.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.leets.assignment.domain.post.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum PostStatus { | ||
| ACTIVE("Active"), | ||
| HIDDEN_BY_USER("Hidden by user"), | ||
| HIDDEN_BY_ADMIN("Hidden by admin"); | ||
|
|
||
| private final String description; | ||
| } |
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
34 changes: 34 additions & 0 deletions
34
...Hee/src/main/java/com/leets/assignment/domain/report/controller/PostReportController.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,34 @@ | ||
| package com.leets.assignment.domain.report.controller; | ||
|
|
||
| import com.leets.assignment.domain.report.dto.req.PostReportRequestDTO; | ||
| import com.leets.assignment.domain.report.dto.res.PostReportResponseDTO; | ||
| import com.leets.assignment.domain.report.service.PostReportService; | ||
| import com.leets.assignment.global.common.ApiResponse; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/posts") | ||
| @RequiredArgsConstructor | ||
| public class PostReportController { | ||
|
|
||
| private final PostReportService postReportService; | ||
|
|
||
| @PostMapping("/{postId}/reports") | ||
| public ApiResponse<PostReportResponseDTO> createReport( | ||
| @PathVariable Long postId, | ||
| @Valid @RequestBody PostReportRequestDTO request) { | ||
|
|
||
| PostReportResponseDTO response = postReportService.reportPost(postId, request.reporterId(), request.reason()); | ||
| return ApiResponse.onSuccess("REPORT201", "신고가 정상적으로 접수되었습니다.", response); | ||
| } | ||
|
|
||
| @PatchMapping("/reports/{reportId}/resolve") | ||
| public ApiResponse<PostReportResponseDTO> resolveReport( | ||
| @PathVariable Long reportId | ||
| ) { | ||
| PostReportResponseDTO response = postReportService.resolveReport(reportId); | ||
| return ApiResponse.onSuccess("REPORT200_1", "신고 처리가 완료되어 해당 게시글이 숨겨졌습니다.", response); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
LeeKunHee/src/main/java/com/leets/assignment/domain/report/dto/req/PostReportRequestDTO.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,13 @@ | ||
| package com.leets.assignment.domain.report.dto.req; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record PostReportRequestDTO( | ||
| @NotNull(message = "신고자 ID는 필수입니다.") | ||
| Long reporterId, | ||
|
|
||
| @NotBlank(message = "신고 사유를 입력해주세요.") | ||
| String reason | ||
| ) { | ||
| } |
16 changes: 16 additions & 0 deletions
16
...unHee/src/main/java/com/leets/assignment/domain/report/dto/res/PostReportResponseDTO.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,16 @@ | ||
| package com.leets.assignment.domain.report.dto.res; | ||
|
|
||
| import com.leets.assignment.domain.report.entity.ReportStatus; | ||
| import lombok.Builder; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Builder | ||
| public record PostReportResponseDTO( | ||
| Long reportId, | ||
| Long postId, | ||
| Long reporterId, | ||
| String reason, | ||
| ReportStatus status, | ||
| LocalDateTime createdAt | ||
| ) { | ||
| } |
39 changes: 39 additions & 0 deletions
39
LeeKunHee/src/main/java/com/leets/assignment/domain/report/entity/BaseReport.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,39 @@ | ||
| package com.leets.assignment.domain.report.entity; | ||
|
|
||
| import com.leets.assignment.domain.user.entity.User; | ||
| import com.leets.assignment.global.baseEntity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @MappedSuperclass | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public abstract class BaseReport extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long reportId; // 신고 아이디 | ||
|
|
||
| @Column(nullable = false) | ||
| private String reason; // 신고 사유 | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| private ReportStatus status = ReportStatus.PENDING; // 신고 상태 (기본값: 대기중) | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "reporter_id", nullable = false) | ||
| private User reporter; // 신고자 | ||
|
|
||
| protected BaseReport(User reporter, String reason) { | ||
| this.reporter = reporter; | ||
| this.reason = reason; | ||
| this.status = ReportStatus.PENDING; | ||
| } | ||
|
|
||
| public void resolve() { | ||
| this.status = ReportStatus.RESOLVED; | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
LeeKunHee/src/main/java/com/leets/assignment/domain/report/entity/PostReport.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,26 @@ | ||
| package com.leets.assignment.domain.report.entity; | ||
|
|
||
| import com.leets.assignment.domain.post.entity.Post; | ||
| import com.leets.assignment.domain.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "post_reports") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class PostReport extends BaseReport { | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id", nullable = false) | ||
| private Post post; // 신고 대상 게시글 | ||
|
|
||
| @Builder | ||
| public PostReport(User reporter, Post post, String reason) { | ||
| super(reporter, reason); | ||
| this.post = post; | ||
| } | ||
| } | ||
13 changes: 13 additions & 0 deletions
13
LeeKunHee/src/main/java/com/leets/assignment/domain/report/entity/ReportStatus.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,13 @@ | ||
| package com.leets.assignment.domain.report.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum ReportStatus { | ||
| PENDING("Pending"), // 대기 중 | ||
| RESOLVED("Resolved"); // 처리 완료 | ||
|
|
||
| private final String description; | ||
| } |
14 changes: 14 additions & 0 deletions
14
LeeKunHee/src/main/java/com/leets/assignment/domain/report/exception/ReportException.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.leets.assignment.domain.report.exception; | ||
|
|
||
| import com.leets.assignment.domain.report.exception.code.ReportErrorCode; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ReportException extends RuntimeException { | ||
| private final ReportErrorCode errorCode; | ||
|
|
||
| public ReportException(ReportErrorCode errorCode) { | ||
| super(errorCode.getMessage()); | ||
| this.errorCode = errorCode; | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
...nHee/src/main/java/com/leets/assignment/domain/report/exception/code/ReportErrorCode.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,19 @@ | ||
| package com.leets.assignment.domain.report.exception.code; | ||
|
|
||
| import com.leets.assignment.global.exception.code.BaseErrorCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum ReportErrorCode implements BaseErrorCode { | ||
| REPORT_DUPLICATED("REPORT409_1", "이미 신고한 게시글입니다.", HttpStatus.CONFLICT), | ||
| REPORT_SELF_FORBIDDEN("REPORT403_1", "자신의 게시글은 신고할 수 없습니다.", HttpStatus.FORBIDDEN), | ||
| REPORT_NOT_FOUND("REPORT404_1", "해당 신고 내역을 찾을 수 없습니다.", HttpStatus.NOT_FOUND), | ||
| REPORT_ALREADY_RESOLVED("REPORT400_1", "이미 처리가 완료된 신고입니다.", HttpStatus.BAD_REQUEST); | ||
|
|
||
| private final String code; | ||
| private final String message; | ||
| private final HttpStatus httpStatus; | ||
| } |
14 changes: 14 additions & 0 deletions
14
...Hee/src/main/java/com/leets/assignment/domain/report/repository/PostReportRepository.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.leets.assignment.domain.report.repository; | ||
|
|
||
| import com.leets.assignment.domain.post.entity.Post; | ||
| import com.leets.assignment.domain.report.entity.PostReport; | ||
| import com.leets.assignment.domain.user.entity.User; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface PostReportRepository extends JpaRepository<PostReport, Long> { | ||
| // 특정 게시글의 전체 신고 횟수를 카운트하는 메서드 | ||
| // Post 엔티티 필드명(post) + Post 엔티티 내부의 PK 필드명(PostId) | ||
| long countByPost_PostId(Long postId); | ||
| // 중복 신고 확인: 동일 신고자가 동일 게시글을 이미 신고했는지 체크 | ||
| boolean existsByReporter_UserIdAndPost_PostId(Long userId, Long postId); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 설계에서는 report 타입 별로 데이터베이스 테이블을 따로 가지기 때문에 관리가 힘들고 새로운 도메인에 대한 신고 기능을 구현할 때 기존 코드를 재사용하기 힘들어 확장성이 떨어지는 단점이 있을 것 같습니다. 똑같은 기능을 구현할 때 다양한 설계와 장단점들을 고려해보는 것도 좋을 것 같습니다.