-
Notifications
You must be signed in to change notification settings - Fork 20
[4주차] 최유찬 /[feat] 추가 API 구현 #159
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
ruchan04
wants to merge
1
commit into
Leets-Official:최유찬/main
Choose a base branch
from
ruchan04:최유찬/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: "\uCD5C\uC720\uCC2C/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
Empty file.
Empty file.
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/demo1/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,13 @@ | ||
| package com.example.demo1.domain.post.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum PostStatus { | ||
| ACTIVE("활성화"), | ||
| HIDDEN("숨김"); | ||
|
|
||
| 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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/example/demo1/domain/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,23 @@ | ||
| package com.example.demo1.domain.report.controller; | ||
|
|
||
| import com.example.demo1.domain.global.response.BaseResponse; | ||
| import com.example.demo1.domain.report.dto.ReportRequestDto; | ||
| import com.example.demo1.domain.report.service.ReportService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/reports") | ||
| @RequiredArgsConstructor | ||
| public class ReportController { | ||
|
|
||
| private final ReportService reportService; | ||
|
|
||
| @PostMapping | ||
| public BaseResponse<String> report(@RequestBody ReportRequestDto dto) { | ||
| String result = reportService.createReport(dto.getReporterId(), dto.getTargetId()); | ||
| return BaseResponse.onSuccess("REP200", result, null); | ||
| } | ||
|
|
||
|
|
||
| } |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/demo1/domain/report/dto/ReportRequestDto.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.demo1.domain.report.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class ReportRequestDto { | ||
| private Long reporterId; | ||
| private Long targetId; | ||
| } |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/demo1/domain/report/entity/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,28 @@ | ||
| package com.example.demo1.domain.report.entity; | ||
|
|
||
| import com.example.demo1.domain.global.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) // JPA를 위한 기본 생성자 | ||
| @AllArgsConstructor | ||
| public class Report extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private Long reporterId; // 신고자 ID | ||
| private Long targetId; // 게시물 또는 댓글 ID | ||
|
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. 나중에 게시글(targetId = 1)이나 댓글(targetId=1)로 신고가 들어왔을 경우에 중복되는 문제가 생길 수도 있을 것 같습니다..! 따로 targetType을 지정해서 Post에 대한 신고인지, Comment에 대한 신고인지 구분해 놓으면 위 문제를 방지할 수 있을 것 같습니다. 고생하셨습니다! 💊 |
||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private ReportStatus status = ReportStatus.PENDING; // 기본값: 대기중 | ||
|
|
||
| public void resolve() { | ||
| this.status = ReportStatus.RESOLVED; | ||
| } | ||
|
|
||
|
|
||
| } | ||
13 changes: 13 additions & 0 deletions
13
src/main/java/com/example/demo1/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.example.demo1.domain.report.entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum ReportStatus { | ||
| PENDING("대기 중"), | ||
| RESOLVED("처리 완료"); | ||
|
|
||
| private final String description; | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/example/demo1/domain/report/entity/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,4 @@ | ||
| package com.example.demo1.domain.report.entity; | ||
|
|
||
| public class ReportType { | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/demo1/domain/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,9 @@ | ||
| package com.example.demo1.domain.report.repository; | ||
|
|
||
| import com.example.demo1.domain.report.entity.Report; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ReportRepository extends JpaRepository<Report, Long> { | ||
| // [중복 방지] 신고자와 타겟 ID로 이미 데이터가 있는지 확인하는 메서드 | ||
| boolean existsByReporterIdAndTargetId(Long reporterId, Long targetId); | ||
| } |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/example/demo1/domain/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,35 @@ | ||
| package com.example.demo1.domain.report.service; | ||
|
|
||
| import com.example.demo1.domain.report.entity.Report; | ||
| import com.example.demo1.domain.report.entity.ReportStatus; | ||
| import com.example.demo1.domain.report.repository.ReportRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class ReportService { | ||
|
|
||
| private final ReportRepository reportRepository; | ||
|
|
||
| @Transactional | ||
| public String createReport(Long reporterId, Long targetId) { | ||
| // [오류 해결 포인트 1] 리포지토리에 existsByReporterIdAndTargetId 메서드가 선언되어 있어야 합니다. | ||
| if (reportRepository.existsByReporterIdAndTargetId(reporterId, targetId)) { | ||
| throw new IllegalStateException("이미 신고한 대상입니다."); | ||
| } | ||
|
|
||
| Report report = Report.builder() | ||
| .reporterId(reporterId) | ||
| .targetId(targetId) | ||
| .status(ReportStatus.PENDING) | ||
| .build(); | ||
|
|
||
| reportRepository.save(report); | ||
| return "신고가 정상적으로 접수되었습니다."; | ||
| } | ||
|
|
||
|
|
||
| } |
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| spring.application.name=demo | ||
| spring.jpa.open-in-view=false |
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.
과제에서 요구한 내용 명확하게 잘 구현하신 것 같습니다. 고생 많으셨습니다!