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,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<CommentReportListResDto> getCommentReports(
@ModelAttribute @Valid ReportPageReqDto reportPageReqDto) {
CommentReportListResDto commentReportListResDto = reportAdminService.getCommentReports(reportPageReqDto);
return ResponseEntity.ok(commentReportListResDto);
}

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

/**
* 노쇼 신고 전체 리스트 조회
* return 200 status code(성공 status)
*/
@GetMapping("/users")
public ResponseEntity<UserReportListResDto> getUserReports(
@ModelAttribute @Valid ReportPageReqDto reportPageReqDto) {
UserReportListResDto userReportListResDto = reportAdminService.getUserReports(reportPageReqDto);
return ResponseEntity.ok(userReportListResDto);
}
}
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 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();
}
}
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 CommentReportListResDto {
private List<CommentReportAdminResDto> commentReportPageList;
private int totalPages;

public CommentReportListResDto(List<CommentReportAdminResDto> 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 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();
}
}
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 RoomReportListResDto {
private List<RoomReportAdminResDto> roomReportPageList;
private int totalPages;

public RoomReportListResDto(List<RoomReportAdminResDto> 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 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();
}
}
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 UserReportListResDto {
private List<UserReportAdminResDto> userReportPageList;
private int totalPages;

public UserReportListResDto(List<UserReportAdminResDto> 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.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<CommentReport> commentReportPage = commentReportRepository.findAllWithFetchJoin(pageable);

List<CommentReportAdminResDto> 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<RoomReport> roomReportPage = roomReportRepository.findAllWithFetchJoin(pageable);

List<RoomReportAdminResDto> 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<UserReport> userReportPage = userReportRepository.findAllWithFetchJoin(pageable);

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

return new UserReportListResDto(userReportPageResDto, userReportPage.getTotalPages());
}
}
10 changes: 10 additions & 0 deletions gg-repo/src/main/java/gg/repo/party/CommentReportRepository.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.CommentReport;
import gg.data.user.User;
Expand All @@ -12,4 +15,11 @@ public interface CommentReportRepository extends JpaRepository<CommentReport, Lo
public List<CommentReport> findByCommentId(Long commentId);

public Optional<CommentReport> 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count query 는 필요 없을것 같은데 추가하신 이유가 있나요?

Copy link
Contributor Author

@JaBeast JaBeast Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pageable과 fetch join같이 쓰면 에러 뜹니다(같이 사용 불가). 그래서 query를 fetch join하는데 유효하게 만들기 위해서 사용했습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이때 join 이 내부적으로 inner join 으로 실행되는 것으로 아는데, join 후와 join 전 쿼리 수가 달라지는 경우는 없나요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch 하는것 중에서 입력값이 없으면(예를 들어서 comment) 안가져올 것 같은데 이런거는 안가져오는게 맞을것 같습니다.

Page<CommentReport> findAllWithFetchJoin(Pageable pageable);
}
12 changes: 12 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,13 +3,25 @@
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;

public interface RoomReportRepository extends JpaRepository<RoomReport, Long> {
public List<RoomReport> findByRoomId(Long roomId);

public Optional<RoomReport> 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<RoomReport> findAllWithFetchJoin(Pageable pageable);
}
18 changes: 18 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,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<UserReport, Long> {

@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<UserReport> findAllWithFetchJoin(Pageable pageable);
}
Loading