-
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.
✨ [FEATURE] 리뷰 신고 & 관리자 신고 조회 (#99)
- Loading branch information
Showing
11 changed files
with
263 additions
and
8 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/umc/unimade/domain/review/controller/AdminReviewController.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,43 @@ | ||
package umc.unimade.domain.review.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.data.domain.Pageable; | ||
import umc.unimade.domain.review.dto.ReviewReportResponse; | ||
import umc.unimade.domain.review.dto.ReviewReportsResponse; | ||
import umc.unimade.domain.review.service.ReviewReportQueryService; | ||
import umc.unimade.global.common.ApiResponse; | ||
|
||
@RestController | ||
@RequestMapping("/admin/report") | ||
@Tag(name = "Admin_report", description = "관리자-리뷰 신고 관련 API") | ||
@RequiredArgsConstructor | ||
public class AdminReviewController { | ||
|
||
private final ReviewReportQueryService reviewReportQueryService; | ||
|
||
// TODO: 신고 처리 여부에 따라 조회 | ||
@Operation(summary = "리뷰 신고 목록 조회", description = "유저 role이 관리자인 사람만 가능") | ||
@GetMapping() | ||
public ApiResponse<Page<ReviewReportsResponse>> getReports( | ||
@RequestParam(name = "page", defaultValue = "0") int page, | ||
@RequestParam(name = "size", defaultValue = "10") int size) { | ||
Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdAt")); | ||
Page<ReviewReportsResponse> responses = reviewReportQueryService.getReports(pageable); | ||
return ApiResponse.onSuccess(responses); | ||
} | ||
|
||
@Operation(summary = "리뷰 신고 개별 조회", description = "유저 role이 관리자인 사람만 가능") | ||
@GetMapping("/{reviewReportId}") | ||
public ApiResponse<ReviewReportResponse> getReport(@PathVariable Long reviewReportId) { | ||
ReviewReportResponse response = reviewReportQueryService.getReport(reviewReportId); | ||
return ApiResponse.onSuccess(response); | ||
} | ||
|
||
// TODO: 관리자의 신고 처리 추가 | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/umc/unimade/domain/review/dto/ReviewReportRequest.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,31 @@ | ||
package umc.unimade.domain.review.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import umc.unimade.domain.accounts.entity.Seller; | ||
import umc.unimade.domain.review.entity.ReportType; | ||
import umc.unimade.domain.review.entity.Review; | ||
import umc.unimade.domain.review.entity.ReviewReport; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ReviewReportRequest { | ||
|
||
@NotNull | ||
private ReportType type; | ||
private String description; | ||
|
||
public ReviewReport toEntity(Review review, Seller seller) { | ||
return ReviewReport.builder() | ||
.review(review) | ||
.seller(seller) | ||
.type(type) | ||
.description(description) | ||
.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/umc/unimade/domain/review/dto/ReviewReportResponse.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,40 @@ | ||
package umc.unimade.domain.review.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import umc.unimade.domain.review.entity.ReportType; | ||
import umc.unimade.domain.review.entity.Review; | ||
import umc.unimade.domain.review.entity.ReviewReport; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ReviewReportResponse { | ||
|
||
private Long reportId; | ||
private Long reviewId; | ||
private Long buyerId; | ||
private Long sellerId; | ||
private ReportType type; | ||
private String reviewTitle; | ||
private String reviewContent; | ||
private String description; | ||
|
||
public static ReviewReportResponse from(ReviewReport report) { | ||
Review review = report.getReview(); | ||
return ReviewReportResponse.builder() | ||
.reportId(report.getId()) | ||
.reviewId(review.getId()) | ||
.buyerId(review.getBuyer().getId()) | ||
.sellerId(report.getSeller().getId()) | ||
.type(report.getType()) | ||
.reviewTitle(review.getTitle()) | ||
.reviewContent(review.getContent()) | ||
.description(report.getDescription()) | ||
.build(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/umc/unimade/domain/review/dto/ReviewReportsResponse.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,28 @@ | ||
package umc.unimade.domain.review.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import umc.unimade.domain.review.entity.Review; | ||
import umc.unimade.domain.review.entity.ReviewReport; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ReviewReportsResponse { | ||
|
||
private Long reportId; | ||
private Long reviewId; | ||
private String reviewTitle; | ||
|
||
public static ReviewReportsResponse from(ReviewReport report) { | ||
Review review = report.getReview(); | ||
return ReviewReportsResponse.builder() | ||
.reportId(report.getId()) | ||
.reviewId(review.getId()) | ||
.reviewTitle(review.getTitle()) | ||
.build(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/umc/unimade/domain/review/entity/ReportType.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 umc.unimade.domain.review.entity; | ||
|
||
public enum ReportType { | ||
OPTION_1, | ||
OPTION_2, | ||
OPTION_3, | ||
ECT | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/umc/unimade/domain/review/entity/ReviewReport.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,34 @@ | ||
package umc.unimade.domain.review.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import umc.unimade.domain.accounts.entity.Seller; | ||
import umc.unimade.global.common.BaseEntity; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
@Table(name = "review_report") | ||
public class ReviewReport extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "review_report_id", nullable = false) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "review_id", nullable = false) | ||
private Review review; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "seller_id", nullable = false) | ||
private Seller seller; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "type", nullable = false) | ||
private ReportType type; | ||
|
||
@Column(name = "description") | ||
private String description; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/umc/unimade/domain/review/repository/ReviewReportRepository.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 umc.unimade.domain.review.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.unimade.domain.review.entity.ReviewReport; | ||
|
||
public interface ReviewReportRepository extends JpaRepository<ReviewReport, Long> { | ||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/umc/unimade/domain/review/service/ReviewReportQueryService.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 umc.unimade.domain.review.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import umc.unimade.domain.review.dto.ReviewReportResponse; | ||
import umc.unimade.domain.review.dto.ReviewReportsResponse; | ||
import umc.unimade.domain.review.entity.ReviewReport; | ||
import umc.unimade.domain.review.exception.ReviewExceptionHandler; | ||
import umc.unimade.domain.review.repository.ReviewReportRepository; | ||
import umc.unimade.global.common.ErrorCode; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ReviewReportQueryService { | ||
|
||
private final ReviewReportRepository reviewReportRepository; | ||
|
||
public Page<ReviewReportsResponse> getReports(Pageable pageable) { | ||
Page<ReviewReport> reports = reviewReportRepository.findAll(pageable); | ||
return reports.map(ReviewReportsResponse::from); | ||
} | ||
|
||
public ReviewReportResponse getReport(Long reviewReportId) { | ||
ReviewReport report = reviewReportRepository.findById(reviewReportId) | ||
.orElseThrow(() -> new ReviewExceptionHandler(ErrorCode.REPORT_NOT_FOUND)); | ||
return ReviewReportResponse.from(report); | ||
} | ||
} |
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