-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Feat/48] 회원 신고 API 구현 #60
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b5d32ea
:sparkles: 회원 신고 api 구현.
hzee97 822d5e9
:sparkles: [Feat]: ReportTypeMapping 엔티티 및 매핑 추가
Eunjin3395 46a0ae4
:sparkles: [Feat] 디렉터리 변경.
hzee97 654ffbe
:recycle: [Refactor]: DTO 클래스 구조 변경
Eunjin3395 25dd0b2
:sparkles: [Feat] 회원 신고 API 구현.
hzee97 22f6dd0
:sparkles: [Feat] 회원 신고 API 구현.
hzee97 ace4d11
Merge branch 'develop' of https://github.com/Gamegoo-repo/Gamegoo-ser…
hzee97 630aede
Merge branch 'develop' into feature/48
hzee97 c4fbbeb
:bug: [Fix] 어노테이션 수정.
hzee97 eb62a2b
:sparkles: [Feat] member 와 targetMember 일치 여부 검증 추가
hzee97 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 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 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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/gamegoo/apiPayload/exception/handler/ReportHandler.java
This file contains 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.gamegoo.apiPayload.exception.handler; | ||
|
||
import com.gamegoo.apiPayload.code.BaseErrorCode; | ||
import com.gamegoo.apiPayload.exception.GeneralException; | ||
|
||
public class ReportHandler extends GeneralException { | ||
public ReportHandler(BaseErrorCode code) { | ||
super(code); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/gamegoo/controller/report/ReportController.java
This file contains 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,51 @@ | ||
package com.gamegoo.controller.report; | ||
|
||
|
||
import com.gamegoo.apiPayload.ApiResponse; | ||
import com.gamegoo.domain.report.Report; | ||
import com.gamegoo.dto.report.ReportRequest; | ||
import com.gamegoo.dto.report.ReportResponse; | ||
import com.gamegoo.service.report.ReportService; | ||
import com.gamegoo.util.JWTUtil; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
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; | ||
|
||
import javax.validation.Valid; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
@RequestMapping("/api/reports") | ||
@Tag(name = "Reports", description = "신고 관련 API") | ||
public class ReportController { | ||
private final ReportService reportService; | ||
|
||
@PostMapping("") | ||
public ApiResponse<ReportResponse.reportInsertResultDTO> reportInsert( | ||
@RequestBody @Valid ReportRequest.reportInsertDTO request | ||
){ | ||
Long memberId = JWTUtil.getCurrentUserId(); | ||
|
||
Report report = reportService.insertReport(request,memberId); | ||
|
||
List<Long> reportTypeIdList = report.getReportTypeMappingList().stream() | ||
.map(reportTypeMapping -> reportTypeMapping.getReportType().getId()) | ||
.collect(Collectors.toList()); | ||
|
||
ReportResponse.reportInsertResultDTO result = ReportResponse.reportInsertResultDTO.builder() | ||
.targetId(report.getTarget().getId()) | ||
.reportId(report.getId()) | ||
.contents(report.getReportContent()) | ||
.reportTypeIdList(reportTypeIdList) | ||
.build(); | ||
|
||
return ApiResponse.onSuccess(result); | ||
} | ||
} |
This file contains 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 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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/gamegoo/domain/report/ReportTypeMapping.java
This file contains 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,37 @@ | ||
package com.gamegoo.domain.report; | ||
|
||
import com.gamegoo.domain.common.BaseDateTimeEntity; | ||
import lombok.*; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "ReportTypeMapping") | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class ReportTypeMapping extends BaseDateTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "report_type_mapping_id") | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "report_type_id", nullable = false) | ||
private ReportType reportType; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "report_id", nullable = false) | ||
private Report report; | ||
|
||
// 연관관계 메소드 | ||
public void setReport(Report report) { | ||
if (this.report != null) { | ||
this.report.getReportTypeMappingList().remove(this); | ||
} | ||
this.report = report; | ||
this.report.getReportTypeMappingList().add(this); | ||
} | ||
|
||
} |
This file contains 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,22 @@ | ||
package com.gamegoo.dto.report; | ||
|
||
import lombok.Getter; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
public class ReportRequest { | ||
|
||
@Getter | ||
public static class reportInsertDTO { | ||
@NotNull | ||
Long targetMemberId; | ||
|
||
@NotEmpty | ||
List<Long> reportTypeIdList; | ||
|
||
String contents; | ||
} | ||
} |
This file contains 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.gamegoo.dto.report; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
public class ReportResponse { | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class reportInsertResultDTO{ | ||
Long reportId; | ||
Long targetId; | ||
List<Long> reportTypeIdList; | ||
String contents; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gamegoo/repository/report/ReportRepository.java
This file contains 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,8 @@ | ||
package com.gamegoo.repository.report; | ||
|
||
import com.gamegoo.domain.report.Report; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/gamegoo/repository/report/ReportTypeMappingRepository.java
This file contains 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.gamegoo.repository.report; | ||
|
||
import com.gamegoo.domain.report.ReportTypeMapping; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportTypeMappingRepository extends JpaRepository<ReportTypeMapping, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gamegoo/repository/report/ReportTypeRepository.java
This file contains 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,8 @@ | ||
package com.gamegoo.repository.report; | ||
|
||
import com.gamegoo.domain.report.ReportType; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportTypeRepository extends JpaRepository<ReportType, Long> { | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/gamegoo/service/report/ReportService.java
This file contains 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,80 @@ | ||
package com.gamegoo.service.report; | ||
|
||
import com.gamegoo.apiPayload.code.status.ErrorStatus; | ||
import com.gamegoo.apiPayload.exception.handler.MemberHandler; | ||
import com.gamegoo.apiPayload.exception.handler.ReportHandler; | ||
import com.gamegoo.apiPayload.exception.handler.TempHandler; | ||
import com.gamegoo.domain.Member; | ||
import com.gamegoo.domain.report.Report; | ||
import com.gamegoo.domain.report.ReportType; | ||
import com.gamegoo.domain.report.ReportTypeMapping; | ||
import com.gamegoo.dto.report.ReportRequest; | ||
import com.gamegoo.repository.member.MemberRepository; | ||
import com.gamegoo.repository.report.ReportRepository; | ||
import com.gamegoo.repository.report.ReportTypeMappingRepository; | ||
import com.gamegoo.repository.report.ReportTypeRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ReportService{ | ||
private final MemberRepository memberRepository; | ||
private final ReportRepository reportRepository; | ||
private final ReportTypeRepository reportTypeRepository; | ||
private final ReportTypeMappingRepository reportTypeMappingRepository; | ||
|
||
public Report insertReport(ReportRequest.reportInsertDTO request, Long memberId){ | ||
Member member = memberRepository.findById(memberId).orElseThrow(()->new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
|
||
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. member와 targetMember가 같은 회원인 경우 에러 처리 추가가 필요할 것 같아요 |
||
// target 회원 존재 여부 검증. | ||
Member targetMember = memberRepository.findById(request.getTargetMemberId()).orElseThrow(()->new MemberHandler(ErrorStatus.REPORT_TARGET_MEMBER_NOT_FOUND)); | ||
|
||
// target 회원 탈퇴 여부 검증. | ||
if (targetMember.getBlind()){ | ||
throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); | ||
} | ||
|
||
// reportType이 실제 존재 여부 검증. | ||
List<ReportType> reportTypeList = new ArrayList<>(); | ||
request.getReportTypeIdList() | ||
.forEach(reportTypeId -> { | ||
ReportType reportType = reportTypeRepository.findById(reportTypeId).orElseThrow(() -> new TempHandler(ErrorStatus._BAD_REQUEST)); | ||
reportTypeList.add(reportType); | ||
}); | ||
|
||
// member 와 targetMember가 같은 회원인 경우. | ||
if (member.getId().equals(targetMember.getId())){ | ||
throw new MemberHandler(ErrorStatus.MEMBER_AND_TARGET_MEMBER_SAME); | ||
} | ||
|
||
// report 엔티티 생성 및 연관관계 매핑. | ||
Report report = Report.builder() | ||
.target(targetMember) | ||
.reportContent(request.getContents()) | ||
.reportTypeMappingList(new ArrayList<>()) | ||
.build(); | ||
|
||
report.setReporter(member); | ||
Report saveReport = reportRepository.save(report); | ||
|
||
// reportTypeMapping 엔티티 생성 및 연관관계 매핑. | ||
reportTypeList.forEach(reportType -> { | ||
ReportTypeMapping reportTypeMapping = ReportTypeMapping.builder() | ||
.reportType(reportType) | ||
.build(); | ||
|
||
reportTypeMapping.setReport(saveReport); | ||
reportTypeMappingRepository.save(reportTypeMapping); | ||
}); | ||
|
||
return saveReport; | ||
} | ||
} |
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.
reportInsertResponseDTO