diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/ReportAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/ReportAdminController.java index f7c613f1d..b42b80730 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/ReportAdminController.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/ReportAdminController.java @@ -1,7 +1,56 @@ -package gg.pingpong.api.party.admin.report.controller; +package gg.party.api.admin.report.controller; +import javax.validation.Valid; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import gg.party.api.admin.report.controller.request.ReportPageReqDto; +import gg.party.api.admin.report.controller.response.CommentReportListResDto; +import gg.party.api.admin.report.controller.response.RoomReportListResDto; +import gg.party.api.admin.report.controller.response.UserReportListResDto; +import gg.party.api.admin.report.service.ReportAdminService; +import lombok.RequiredArgsConstructor; + @RestController +@RequiredArgsConstructor +@RequestMapping("/party/admin/reports") public class ReportAdminController { + private final ReportAdminService reportAdminService; + + /** + * 댓글 신고 전체 리스트 조회 + * return 200 status code(성공 status) + */ + @GetMapping("/comments") + public ResponseEntity getCommentReports( + @ModelAttribute @Valid ReportPageReqDto reportPageReqDto) { + CommentReportListResDto commentReportListResDto = reportAdminService.getCommentReports(reportPageReqDto); + return ResponseEntity.ok(commentReportListResDto); + } + + /** + * 방 신고 전체 리스트 조회 + * return 200 status code(성공 status) + */ + @GetMapping("/rooms") + public ResponseEntity getRoomReports( + @ModelAttribute @Valid ReportPageReqDto reportPageReqDto) { + RoomReportListResDto roomReportListResDto = reportAdminService.getRoomReports(reportPageReqDto); + return ResponseEntity.ok(roomReportListResDto); + } + + /** + * 노쇼 신고 전체 리스트 조회 + * return 200 status code(성공 status) + */ + @GetMapping("/users") + public ResponseEntity getUserReports( + @ModelAttribute @Valid ReportPageReqDto reportPageReqDto) { + UserReportListResDto userReportListResDto = reportAdminService.getUserReports(reportPageReqDto); + return ResponseEntity.ok(userReportListResDto); + } } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/request/ReportPageReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/request/ReportPageReqDto.java new file mode 100644 index 000000000..08bf49601 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/request/ReportPageReqDto.java @@ -0,0 +1,29 @@ +package gg.party.api.admin.report.controller.request; + +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ReportPageReqDto { + @Min(value = 1) + @NotNull + private Integer page; + + @Min(value = 1) + @Max(value = 30) + private Integer size = 10; + + public ReportPageReqDto(Integer page, Integer size) { + this.page = page; + if (size == null) { + this.size = 10; + } else { + this.size = size; + } + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportAdminResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportAdminResDto.java new file mode 100644 index 000000000..24d342bf5 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportAdminResDto.java @@ -0,0 +1,28 @@ +package gg.party.api.admin.report.controller.response; + +import java.time.LocalDateTime; + +import gg.data.party.CommentReport; +import lombok.Getter; + +/** + * 댓글 신고 dto + */ +@Getter +public class CommentReportAdminResDto { + private Long id; + private String reporterIntraId; + private Long commentId; + private Long roomId; + private String message; + private LocalDateTime createdAt; + + public CommentReportAdminResDto(CommentReport commentReport) { + this.id = commentReport.getId(); + this.reporterIntraId = commentReport.getReporter().getIntraId(); + this.commentId = commentReport.getComment().getId(); + this.roomId = commentReport.getRoom().getId(); + this.message = commentReport.getMessage(); + this.createdAt = commentReport.getCreatedAt(); + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportListResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportListResDto.java new file mode 100644 index 000000000..106d4ca9f --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/CommentReportListResDto.java @@ -0,0 +1,18 @@ +package gg.party.api.admin.report.controller.response; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +@Getter +public class CommentReportListResDto { + private List commentReportPageList; + private int totalPages; + + public CommentReportListResDto(List commentReportPageList, int totalPages) { + this.commentReportPageList = commentReportPageList; + this.totalPages = totalPages; + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportAdminResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportAdminResDto.java new file mode 100644 index 000000000..5fd4bd196 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportAdminResDto.java @@ -0,0 +1,28 @@ +package gg.party.api.admin.report.controller.response; + +import java.time.LocalDateTime; + +import gg.data.party.RoomReport; +import lombok.Getter; + +/** + * 방 신고 dto + */ +@Getter +public class RoomReportAdminResDto { + private Long id; + private String reporterIntraId; + private String reporteeIntraId; + private Long roomId; + private String message; + private LocalDateTime createdAt; + + public RoomReportAdminResDto(RoomReport roomReport) { + this.id = roomReport.getId(); + this.reporterIntraId = roomReport.getReporter().getIntraId(); + this.reporteeIntraId = roomReport.getReportee().getIntraId(); + this.roomId = roomReport.getRoom().getId(); + this.message = roomReport.getMessage(); + this.createdAt = roomReport.getCreatedAt(); + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportListResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportListResDto.java new file mode 100644 index 000000000..b3800aa9b --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/RoomReportListResDto.java @@ -0,0 +1,18 @@ +package gg.party.api.admin.report.controller.response; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +@Getter +public class RoomReportListResDto { + private List roomReportPageList; + private int totalPages; + + public RoomReportListResDto(List roomReportPageList, int totalPages) { + this.roomReportPageList = roomReportPageList; + this.totalPages = totalPages; + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportAdminResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportAdminResDto.java new file mode 100644 index 000000000..7a8ade362 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportAdminResDto.java @@ -0,0 +1,28 @@ +package gg.party.api.admin.report.controller.response; + +import java.time.LocalDateTime; + +import gg.data.party.UserReport; +import lombok.Getter; + +/** + * 노쇼 신고 dto + */ +@Getter +public class UserReportAdminResDto { + private Long id; + private String reporterIntraId; + private String reporteeIntraId; + private Long roomId; + private String message; + private LocalDateTime createdAt; + + public UserReportAdminResDto(UserReport userReport) { + this.id = userReport.getId(); + this.reporterIntraId = userReport.getReporter().getIntraId(); + this.reporteeIntraId = userReport.getReportee().getIntraId(); + this.roomId = userReport.getRoom().getId(); + this.message = userReport.getMessage(); + this.createdAt = userReport.getCreatedAt(); + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportListResDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportListResDto.java new file mode 100644 index 000000000..5d55e0553 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/controller/response/UserReportListResDto.java @@ -0,0 +1,18 @@ +package gg.party.api.admin.report.controller.response; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +@Getter +public class UserReportListResDto { + private List userReportPageList; + private int totalPages; + + public UserReportListResDto(List userReportPageList, int totalPages) { + this.userReportPageList = userReportPageList; + this.totalPages = totalPages; + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/report/service/ReportAdminService.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/service/ReportAdminService.java new file mode 100644 index 000000000..300c51ee1 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/report/service/ReportAdminService.java @@ -0,0 +1,92 @@ +package gg.party.api.admin.report.service; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import gg.data.party.CommentReport; +import gg.data.party.RoomReport; +import gg.data.party.UserReport; +import gg.party.api.admin.report.controller.request.ReportPageReqDto; +import gg.party.api.admin.report.controller.response.CommentReportAdminResDto; +import gg.party.api.admin.report.controller.response.CommentReportListResDto; +import gg.party.api.admin.report.controller.response.RoomReportAdminResDto; +import gg.party.api.admin.report.controller.response.RoomReportListResDto; +import gg.party.api.admin.report.controller.response.UserReportAdminResDto; +import gg.party.api.admin.report.controller.response.UserReportListResDto; +import gg.repo.party.CommentReportRepository; +import gg.repo.party.RoomReportRepository; +import gg.repo.party.UserReportRepository; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class ReportAdminService { + private final CommentReportRepository commentReportRepository; + private final RoomReportRepository roomReportRepository; + private final UserReportRepository userReportRepository; + + /** + * 댓글 신고 전체 리스트를 조회한다 + * + * @return 전체 댓글 신고 리스트 (시간순 정렬) + */ + @Transactional(readOnly = true) + public CommentReportListResDto getCommentReports(ReportPageReqDto reportPageReqDto) { + int page = reportPageReqDto.getPage(); + int size = reportPageReqDto.getSize(); + + Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt")); + Page commentReportPage = commentReportRepository.findAllWithFetchJoin(pageable); + + List commentReportPageResDto = commentReportPage.getContent().stream() + .map(CommentReportAdminResDto::new) + .collect(Collectors.toList()); + + return new CommentReportListResDto(commentReportPageResDto, commentReportPage.getTotalPages()); + } + + /** + * 방 신고 전체 리스트를 조회한다 + * @return 전체 방 신고 리스트 (시간순 정렬) + */ + @Transactional(readOnly = true) + public RoomReportListResDto getRoomReports(ReportPageReqDto reportPageReqDto) { + int page = reportPageReqDto.getPage(); + int size = reportPageReqDto.getSize(); + + Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt")); + Page roomReportPage = roomReportRepository.findAllWithFetchJoin(pageable); + + List roomReportPageResDto = roomReportPage.getContent().stream() + .map(RoomReportAdminResDto::new) + .collect(Collectors.toList()); + + return new RoomReportListResDto(roomReportPageResDto, roomReportPage.getTotalPages()); + } + + /** + * 노쇼 신고 전체 리스트를 조회한다 + * @return 전체 노쇼 신고 리스트 (시간순 정렬) + */ + @Transactional(readOnly = true) + public UserReportListResDto getUserReports(ReportPageReqDto reportPageReqDto) { + int page = reportPageReqDto.getPage(); + int size = reportPageReqDto.getSize(); + + Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createdAt")); + Page userReportPage = userReportRepository.findAllWithFetchJoin(pageable); + + List userReportPageResDto = userReportPage.getContent().stream() + .map(UserReportAdminResDto::new) + .collect(Collectors.toList()); + + return new UserReportListResDto(userReportPageResDto, userReportPage.getTotalPages()); + } +} diff --git a/gg-repo/src/main/java/gg/repo/party/CommentReportRepository.java b/gg-repo/src/main/java/gg/repo/party/CommentReportRepository.java index 70dc9f715..3f821f2d7 100644 --- a/gg-repo/src/main/java/gg/repo/party/CommentReportRepository.java +++ b/gg-repo/src/main/java/gg/repo/party/CommentReportRepository.java @@ -3,7 +3,10 @@ import java.util.List; import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import gg.data.party.CommentReport; import gg.data.user.User; @@ -12,4 +15,11 @@ public interface CommentReportRepository extends JpaRepository findByCommentId(Long commentId); public Optional findByReporterAndCommentId(User reporter, Long commentId); + + @Query(value = "SELECT cr FROM CommentReport cr " + + "JOIN FETCH cr.reporter " + + "JOIN FETCH cr.comment " + + "JOIN FETCH cr.room", + countQuery = "SELECT count(cr) FROM CommentReport cr") + Page findAllWithFetchJoin(Pageable pageable); } diff --git a/gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java b/gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java index 88d9fcb93..c74c15421 100644 --- a/gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java +++ b/gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java @@ -3,8 +3,13 @@ import java.util.List; import java.util.Optional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import gg.data.party.CommentReport; import gg.data.party.RoomReport; import gg.data.user.User; @@ -12,4 +17,11 @@ public interface RoomReportRepository extends JpaRepository { public List findByRoomId(Long roomId); public Optional findByReporterAndRoomId(User reporter, Long roomId); + + @Query(value = "SELECT rr FROM RoomReport rr " + + "JOIN FETCH rr.reporter " + + "JOIN FETCH rr.reportee " + + "JOIN FETCH rr.room", + countQuery = "SELECT count(rr) FROM RoomReport rr") + Page findAllWithFetchJoin(Pageable pageable); } diff --git a/gg-repo/src/main/java/gg/repo/party/UserReportRepository.java b/gg-repo/src/main/java/gg/repo/party/UserReportRepository.java new file mode 100644 index 000000000..0dcdab4e7 --- /dev/null +++ b/gg-repo/src/main/java/gg/repo/party/UserReportRepository.java @@ -0,0 +1,18 @@ +package gg.repo.party; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import gg.data.party.UserReport; + +public interface UserReportRepository extends JpaRepository { + + @Query(value = "SELECT ur FROM UserReport ur " + + "JOIN FETCH ur.reporter " + + "JOIN FETCH ur.reportee " + + "JOIN FETCH ur.room", + countQuery = "SELECT count(ur) FROM UserReport ur") + Page findAllWithFetchJoin(Pageable pageable); +}