-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from YAPP-Github/feature/PC-272-api-report
[PC-272] 유저 신고 기능 구현
- Loading branch information
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
api/src/main/java/org/yapp/domain/report/application/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,32 @@ | ||
package org.yapp.domain.report.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.yapp.domain.report.Report; | ||
import org.yapp.domain.report.dao.ReportRepository; | ||
import org.yapp.domain.report.dto.request.UserReportRequest; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.domain.user.application.UserService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportService { | ||
|
||
private final ReportRepository reportRepository; | ||
private final UserService userService; | ||
|
||
/** | ||
* 유저 신고 기능 | ||
* | ||
* @param reporterId 신고하는 유저의 아이디 | ||
* @param userReportRequest 신고 요청 | ||
* @return 신고 객체 | ||
*/ | ||
public Report reportUser(Long reporterId, UserReportRequest userReportRequest) { | ||
User reporter = userService.getUserById(reporterId); | ||
User reportedUser = userService.getUserById(userReportRequest.getReportedUserId()); | ||
Report report = Report.builder().reporter(reporter).reportedUser(reportedUser) | ||
.reason(userReportRequest.getReason()).build(); | ||
return reportRepository.save(report); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
api/src/main/java/org/yapp/domain/report/controller/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,33 @@ | ||
package org.yapp.domain.report.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
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 org.yapp.domain.report.application.ReportService; | ||
import org.yapp.domain.report.dto.request.UserReportRequest; | ||
import org.yapp.util.CommonResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/reports") | ||
public class ReportController { | ||
|
||
public final ReportService reportService; | ||
|
||
@PostMapping() | ||
@Operation(summary = "유저 신고", description = "유저를 신고합니다.", tags = { | ||
"신고"}) | ||
@ApiResponse(responseCode = "200", description = "유저를 성공적으로 신고하였습니다.") | ||
public ResponseEntity<CommonResponse<Void>> reportUser(@AuthenticationPrincipal Long userId, | ||
@RequestBody @Valid UserReportRequest request) { | ||
reportService.reportUser(userId, request); | ||
return ResponseEntity.ok(CommonResponse.createSuccessWithNoContent()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
api/src/main/java/org/yapp/domain/report/dao/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,10 @@ | ||
package org.yapp.domain.report.dao; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.yapp.domain.report.Report; | ||
import org.yapp.domain.user.User; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
||
boolean existsReportByReporterAndReportedUser(User reporter, User reportedUser); | ||
} |
17 changes: 17 additions & 0 deletions
17
api/src/main/java/org/yapp/domain/report/dto/request/UserReportRequest.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,17 @@ | ||
package org.yapp.domain.report.dto.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.validator.constraints.Length; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class UserReportRequest { | ||
|
||
@NotNull | ||
private Long reportedUserId; | ||
@NotNull | ||
@Length(min = 1, max = 100) | ||
private String reason; | ||
} |
15 changes: 15 additions & 0 deletions
15
common/src/main/java/org/yapp/error/dto/ReportErrorCode.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,15 @@ | ||
package org.yapp.error.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum ReportErrorCode implements ErrorCode { | ||
ALREADY_REPORTED(HttpStatus.BAD_REQUEST, "이미 신고한 유저입니다."), | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String message; | ||
} |