-
Notifications
You must be signed in to change notification settings - Fork 20
[4주차] 시재욱/[feat] 추가 API 구현 #144
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
seejaewook456-maker
wants to merge
1
commit into
Leets-Official:시재욱/main
Choose a base branch
from
seejaewook456-maker:시재욱/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: "\uC2DC\uC7AC\uC6B1/4\uC8FC\uCC28"
Open
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/example/demo/comment/entity/CommentStatus.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,6 @@ | ||
| package com.example.demo.comment.entity; | ||
|
|
||
| public enum CommentStatus { | ||
| ACTIVE, | ||
| HIDDEN | ||
| } |
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
src/main/java/com/example/demo/global/exception/CustomException.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.demo.global.exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class CustomException extends RuntimeException { | ||
|
|
||
| private final BaseCode baseCode; | ||
|
|
||
| public CustomException(BaseCode baseCode) { | ||
| super(baseCode.getMessage()); | ||
| this.baseCode = baseCode; | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.example.demo.post.entity; | ||
|
|
||
| public enum PostStatus { | ||
| ACTIVE, | ||
| HIDDEN | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/example/demo/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,56 @@ | ||
| package com.example.demo.report.controller; | ||
|
|
||
| import com.example.demo.global.exception.ApiResponse; | ||
| import com.example.demo.global.exception.BaseCode; | ||
| import com.example.demo.global.exception.ResponseUtil; | ||
| import com.example.demo.report.dto.ReportCreateRequest; | ||
| import com.example.demo.report.dto.ReportResponse; | ||
| import com.example.demo.report.service.ReportService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class ReportController { | ||
|
|
||
| private final ReportService reportService; | ||
|
|
||
| // 게시글 신고 | ||
| @PostMapping("/posts/{postId}/reports") | ||
| public ResponseEntity<ApiResponse<ReportResponse>> reportPost( | ||
| @PathVariable Long postId, | ||
| @RequestBody ReportCreateRequest request | ||
| ) { | ||
| ReportResponse response = reportService.reportPost(postId, request); | ||
|
|
||
| return ResponseEntity.ok( | ||
| ResponseUtil.success(BaseCode.REPORT_POST_SUCCESS, response) | ||
| ); | ||
| } | ||
|
|
||
| // 댓글 신고 | ||
| @PostMapping("/comments/{commentId}/reports") | ||
| public ResponseEntity<ApiResponse<ReportResponse>> reportComment( | ||
| @PathVariable Long commentId, | ||
| @RequestBody ReportCreateRequest request | ||
| ) { | ||
| ReportResponse response = reportService.reportComment(commentId, request); | ||
|
|
||
| return ResponseEntity.ok( | ||
| ResponseUtil.success(BaseCode.REPORT_COMMENT_SUCCESS, response) | ||
| ); | ||
| } | ||
|
|
||
| // 신고 처리 완료 | ||
| @PatchMapping("/reports/{reportId}/resolve") | ||
| public ResponseEntity<ApiResponse<ReportResponse>> resolveReport( | ||
| @PathVariable Long reportId | ||
| ) { | ||
| ReportResponse response = reportService.resolveReport(reportId); | ||
|
|
||
| return ResponseEntity.ok( | ||
| ResponseUtil.success(BaseCode.REPORT_RESOLVE_SUCCESS, response) | ||
| ); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/demo/report/dto/ReportCreateRequest.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,11 @@ | ||
| package com.example.demo.report.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ReportCreateRequest { | ||
|
|
||
| private Long reporterId; | ||
|
|
||
| private String reason; | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/example/demo/report/dto/ReportResponse.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,46 @@ | ||
| package com.example.demo.report.dto; | ||
|
|
||
| import com.example.demo.report.entity.Report; | ||
| import com.example.demo.report.entity.ReportStatus; | ||
| import com.example.demo.report.entity.ReportTargetType; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class ReportResponse { | ||
|
|
||
| private Long reportId; | ||
| private Long reporterId; | ||
| private ReportTargetType targetType; | ||
| private Long targetId; | ||
| private String reason; | ||
| private ReportStatus status; | ||
| private LocalDateTime createdAt; | ||
| private LocalDateTime resolvedAt; | ||
|
|
||
| public static ReportResponse from(Report report) { | ||
| Long targetId = null; | ||
|
|
||
| if (report.getTargetType() == ReportTargetType.POST) { | ||
| targetId = report.getPost().getId(); | ||
| } | ||
|
|
||
| if (report.getTargetType() == ReportTargetType.COMMENT) { | ||
| targetId = report.getComment().getId(); | ||
| } | ||
|
|
||
| return ReportResponse.builder() | ||
| .reportId(report.getId()) | ||
| .reporterId(report.getReporter().getId()) | ||
| .targetType(report.getTargetType()) | ||
| .targetId(targetId) | ||
| .reason(report.getReason()) | ||
|
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. 💬 신고 사유 필드를 통해 관리자가 신고 내용을 쉽게 파악할 수 있겠네요. 📝 이전에 작성하신 서비스 로직의 title 필드와 이 DTO의 reason 필드 네이밍이 일치하는지 한 번 더 확인해 보시면 완벽할 것 같습니다. |
||
| .status(report.getStatus()) | ||
| .createdAt(report.getCreatedAt()) | ||
| .resolvedAt(report.getResolvedAt()) | ||
| .build(); | ||
| } | ||
| } | ||
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,57 @@ | ||
| package com.example.demo.report.entity; | ||
|
|
||
| import com.example.demo.comment.entity.Comment; | ||
| import com.example.demo.post.entity.Post; | ||
| import com.example.demo.user.entity.User; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class Report { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| // 신고한 사용자 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "reporter_id", nullable = false) | ||
| private User reporter; | ||
|
|
||
| // 신고 대상 게시글 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "post_id") | ||
| private Post post; | ||
|
|
||
| // 신고 대상 댓글 | ||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "comment_id") | ||
| private Comment comment; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| private ReportTargetType targetType; | ||
|
|
||
| @Column(nullable = false) | ||
| private String reason; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false) | ||
| private ReportStatus status; | ||
|
|
||
| @Column(nullable = false) | ||
| private LocalDateTime createdAt; | ||
|
|
||
| private LocalDateTime resolvedAt; | ||
|
|
||
| public void resolve() { | ||
| this.status = ReportStatus.RESOLVED; | ||
| this.resolvedAt = LocalDateTime.now(); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/example/demo/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,6 @@ | ||
| package com.example.demo.report.entity; | ||
|
|
||
| public enum ReportStatus { | ||
| PENDING, | ||
| RESOLVED | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/example/demo/report/entity/ReportTargetType.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,6 @@ | ||
| package com.example.demo.report.entity; | ||
|
|
||
| public enum ReportTargetType { | ||
| POST, | ||
| COMMENT | ||
| } |
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.
과제 요구 사항 중 하나인 상태 변화 (ACTIVE->HIDDEN)를 잘 설계하신 것 같아요 👍