Skip to content
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

✨ [Feature] admin 댓글,방,노쇼 신고조회 api #719

Merged
merged 14 commits into from
Mar 13, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
package gg.pingpong.api.party.admin.report.controller;
package gg.party.api.admin.report.controller;

import java.util.List;

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.CommentReportPageResDto;
import gg.party.api.admin.report.controller.response.RoomReportPageResDto;
import gg.party.api.admin.report.controller.response.UserReportPageResDto;
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<CommentReportPageResDto> getCommentReports(
@ModelAttribute @Valid ReportPageReqDto reportPageReqDto) {
CommentReportPageResDto commentReportPageResDto = reportAdminService.getCommentReports(reportPageReqDto);
return ResponseEntity.ok(commentReportPageResDto);
}

/**
* 방 신고 전체 리스트 조회
* return 200 status code(성공 status)
*/
@GetMapping("/rooms")
public ResponseEntity<RoomReportPageResDto> getRoomReports(
@ModelAttribute @Valid ReportPageReqDto reportPageReqDto) {
RoomReportPageResDto roomReportPageResDto = reportAdminService.getRoomReports(reportPageReqDto);
return ResponseEntity.ok(roomReportPageResDto);
}

/**
* 노쇼 신고 전체 리스트 조회
* return 200 status code(성공 status)
*/
@GetMapping("/users")
public ResponseEntity<UserReportPageResDto> getUserReports(
@ModelAttribute @Valid ReportPageReqDto reportPageReqDto) {
UserReportPageResDto userReportPageResDto = reportAdminService.getUserReports(reportPageReqDto);
return ResponseEntity.ok(userReportPageResDto);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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 CommentReportListAdminResDto {
private Long id;
private String reporterIntraId;
private Long commentId;
private Long roomId;
private String message;
private LocalDateTime createdAt;

public CommentReportListAdminResDto(CommentReport commentReport) {
this.id = commentReport.getId();
this.reporterIntraId = commentReport.getReporter().getIntraId();
JaBeast marked this conversation as resolved.
Show resolved Hide resolved
this.commentId = commentReport.getComment().getId();
this.roomId = commentReport.getRoom().getId();
this.message = commentReport.getMessage();
this.createdAt = commentReport.getCreatedAt();
}
}
Original file line number Diff line number Diff line change
@@ -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 CommentReportPageResDto {
private List<CommentReportListAdminResDto> commentReportPageList;
private int totalPages;

public CommentReportPageResDto(List<CommentReportListAdminResDto> commentReportPageList, int totalPages) {
this.commentReportPageList = commentReportPageList;
this.totalPages = totalPages;
}
}
Original file line number Diff line number Diff line change
@@ -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 RoomReportListAdminResDto {
private Long id;
private String reporterIntraId;
private String reporteeIntraId;
private Long roomId;
private String message;
private LocalDateTime createdAt;

public RoomReportListAdminResDto(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();
}
}
Original file line number Diff line number Diff line change
@@ -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 RoomReportPageResDto {
private List<RoomReportListAdminResDto> roomReportPageList;
private int totalPages;

public RoomReportPageResDto(List<RoomReportListAdminResDto> roomReportPageList, int totalPages) {
this.roomReportPageList = roomReportPageList;
this.totalPages = totalPages;
}
}
Original file line number Diff line number Diff line change
@@ -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 UserReportListAdminResDto {
private Long id;
private String reporterIntraId;
private String reporteeIntraId;
private Long roomId;
private String message;
private LocalDateTime createdAt;

public UserReportListAdminResDto(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();
}
}
Original file line number Diff line number Diff line change
@@ -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 UserReportPageResDto {
private List<UserReportListAdminResDto> userReportPageList;
private int totalPages;

public UserReportPageResDto(List<UserReportListAdminResDto> userReportPageList, int totalPages) {
this.userReportPageList = userReportPageList;
this.totalPages = totalPages;
}
}
Original file line number Diff line number Diff line change
@@ -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.CommentReportListAdminResDto;
import gg.party.api.admin.report.controller.response.CommentReportPageResDto;
import gg.party.api.admin.report.controller.response.RoomReportListAdminResDto;
import gg.party.api.admin.report.controller.response.RoomReportPageResDto;
import gg.party.api.admin.report.controller.response.UserReportListAdminResDto;
import gg.party.api.admin.report.controller.response.UserReportPageResDto;
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 CommentReportPageResDto getCommentReports(ReportPageReqDto reportPageReqDto) {
int page = reportPageReqDto.getPage();
int size = reportPageReqDto.getSize();

Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.ASC, "createdAt"));
Page<CommentReport> commentReportPage = commentReportRepository.findAllWithFetchJoin(pageable);

List<CommentReportListAdminResDto> commentReportPageResDto = commentReportPage.getContent().stream()
.map(CommentReportListAdminResDto::new)
.collect(Collectors.toList());

return new CommentReportPageResDto(commentReportPageResDto, commentReportPage.getTotalPages());
}

/**
* 방 신고 전체 리스트를 조회한다
* @return 전체 방 신고 리스트 (시간순 정렬)
*/
@Transactional(readOnly = true)
public RoomReportPageResDto getRoomReports(ReportPageReqDto reportPageReqDto) {
int page = reportPageReqDto.getPage();
int size = reportPageReqDto.getSize();

Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.ASC, "createdAt"));
Page<RoomReport> roomReportPage = roomReportRepository.findAllWithFetchJoin(pageable);

List<RoomReportListAdminResDto> roomReportPageResDto = roomReportPage.getContent().stream()
.map(RoomReportListAdminResDto::new)
.collect(Collectors.toList());

return new RoomReportPageResDto(roomReportPageResDto, roomReportPage.getTotalPages());
}

/**
* 노쇼 신고 전체 리스트를 조회한다
* @return 전체 노쇼 신고 리스트 (시간순 정렬)
*/
@Transactional(readOnly = true)
public UserReportPageResDto getUserReports(ReportPageReqDto reportPageReqDto) {
int page = reportPageReqDto.getPage();
int size = reportPageReqDto.getSize();

Pageable pageable = PageRequest.of(page - 1, size, Sort.by(Sort.Direction.ASC, "createdAt"));
Page<UserReport> userReportPage = userReportRepository.findAllWithFetchJoin(pageable);

List<UserReportListAdminResDto> userReportPageResDto = userReportPage.getContent().stream()
.map(UserReportListAdminResDto::new)
.collect(Collectors.toList());

return new UserReportPageResDto(userReportPageResDto, userReportPage.getTotalPages());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,4 +15,10 @@ public interface CommentReportRepository extends JpaRepository<CommentReport, Lo
public List<CommentReport> findByCommentId(Long commentId);

public Optional<CommentReport> findByReporterAndCommentId(User reporter, Long commentId);

@Query("SELECT cr FROM CommentReport cr "
+ "JOIN FETCH cr.reporter "
+ "JOIN FETCH cr.comment "
+ "JOIN FETCH cr.room")
Page<CommentReport> findAllWithFetchJoin(Pageable pageable);
}
9 changes: 9 additions & 0 deletions gg-repo/src/main/java/gg/repo/party/RoomReportRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.RoomReport;
import gg.data.user.User;
Expand All @@ -12,4 +15,10 @@ public interface RoomReportRepository extends JpaRepository<RoomReport, Long> {
public List<RoomReport> findByRoomId(Long roomId);

public Optional<RoomReport> findByReporterAndRoomId(User reporter, Long roomId);

@Query("SELECT rr FROM RoomReport rr "
+ "JOIN FETCH rr.reporter "
+ "JOIN FETCH rr.reportee "
+ "JOIN FETCH rr.room")
Page<RoomReport> findAllWithFetchJoin(Pageable pageable);
}
16 changes: 16 additions & 0 deletions gg-repo/src/main/java/gg/repo/party/UserReportRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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<UserReport, Long> {
@Query("SELECT ur FROM UserReport ur "
+ "JOIN FETCH ur.reporter "
+ "JOIN FETCH ur.reportee "
+ "JOIN FETCH ur.room")
Page<UserReport> findAllWithFetchJoin(Pageable pageable);
}
Loading