Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.ject.recreation.core.api.controller.request.BlockUserRequestDto;
import org.ject.recreation.core.api.controller.request.GameDeleteRequestDto;
import org.ject.recreation.core.api.controller.response.GameListResponseDto;
import org.ject.recreation.core.api.controller.response.GetAllUserResponseDto;
import org.ject.recreation.core.api.controller.response.ReportGameDetailResponseDto;
import org.ject.recreation.core.api.controller.response.ReportGameResponseDto;
Expand All @@ -28,6 +29,7 @@ public ApiResponse<PageResponseDto<ReportGameResponseDto>> getReportGames(
return ApiResponse.success(adminService.getReportedGames(page));
}

// report 상세 내역 조회
@GetMapping("games/{reportId}")
public ApiResponse<ReportGameDetailResponseDto> getReportGame(
@PathVariable Long reportId
Expand All @@ -40,6 +42,14 @@ public ApiResponse<Void> deleteReportGame(@RequestBody GameDeleteRequestDto game
return ApiResponse.success(adminService.deleteReportedDetailGames(gameDeleteRequestDto));
}


@GetMapping("games/admin")
public ApiResponse<PageResponseDto<GameListResponseDto.GameDto>> getAdminGames(
@RequestParam(defaultValue = "0") int page
) {
return ApiResponse.success(adminService.getAdminGames(page));
}

@GetMapping("/users")
public ApiResponse<PageResponseDto<GetAllUserResponseDto>> getUsers(
@RequestParam(defaultValue = "0") int page
Expand All @@ -53,7 +63,7 @@ public ApiResponse<Void> blockUser(@RequestBody BlockUserRequestDto blockUserReq
}

@PostMapping("/users/unblock")
public ApiResponse<Void> unBlockUser(@RequestBody BlockUserRequestDto blockUserRequestDto){
public ApiResponse<Void> unBlockUser(@RequestBody BlockUserRequestDto blockUserRequestDto) {
return ApiResponse.success(adminService.unBlockUser(blockUserRequestDto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ public class ReportGameDetailResponseDto {
private String gameTitle;
private String makerNickname;
private String makerEmail;
private boolean isMakerBlock;
private ReportStatus status;
private int questionCount;
private long version;
private List<GameDetailResponseDto.QuestionDto> qustions;
private String reporterEmail;
private String reporterNickname;
private boolean isReporterBlock;
private GameReportReason reasonCode;

public static ReportGameDetailResponseDto from(ReportEntity reportEntity) {
GameEntity game = reportEntity.getGame();
UserEntity gameCreator = game.getGameCreator();
UserEntity reporter = reportEntity.getReporter();

List<QuestionEntity> questions = game.getQuestions();

ReportReason reason = reportEntity.getReason();
Expand All @@ -43,15 +47,21 @@ public static ReportGameDetailResponseDto from(ReportEntity reportEntity) {
question.getVersion()))
.toList();

boolean isMakerBlock = gameCreator.getBlockReason() != null;
boolean isReporterBlock = reporter != null && reporter.getBlockReason() != null;

return ReportGameDetailResponseDto.builder()
.gameTitle(game.getGameTitle())
.makerNickname(gameCreator.getNickname())
.makerEmail(gameCreator.getEmail())
.isMakerBlock(isMakerBlock)
.status(reportEntity.getStatus())
.questionCount(game.getQuestionCount())
.version(game.getVersion())
.qustions(list)
.reporterEmail(reporter != null ? reporter.getEmail() : null)
.reporterNickname(reporter != null ? reporter.getNickname() : null)
.isReporterBlock(isReporterBlock)
.reasonCode(gameReportReason)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import lombok.RequiredArgsConstructor;
import org.ject.recreation.core.api.controller.request.BlockUserRequestDto;
import org.ject.recreation.core.api.controller.request.GameDeleteRequestDto;
import org.ject.recreation.core.api.controller.response.GameListResponseDto;
import org.ject.recreation.core.api.controller.response.GetAllUserResponseDto;
import org.ject.recreation.core.api.controller.response.ReportGameDetailResponseDto;
import org.ject.recreation.core.api.controller.response.ReportGameResponseDto;
import org.ject.recreation.core.support.error.CoreException;
import org.ject.recreation.core.support.error.ErrorType;
import org.ject.recreation.core.support.response.PageResponseDto;
import org.ject.recreation.storage.db.core.*;
import org.springframework.context.support.BeanDefinitionDsl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -27,9 +29,11 @@ public class AdminService {

private final ReportRepository reportRepository;
private final UserRepository userRepository;
private final GameRepository gameRepository;

public PageResponseDto<ReportGameResponseDto> getReportedGames(int page) {
Pageable pageable = PageRequest.of(page, 7);
// BeanDefinitionDsl.Role
// return reportRepository.findAllForAdmin(pageable)
// .map(ReportGameResponseDto::from);
Page<ReportGameResponseDto> result =
Expand Down Expand Up @@ -67,6 +71,24 @@ public PageResponseDto<GetAllUserResponseDto> getAllUsers(int page) {
return PageResponseDto.of(result);
}

public PageResponseDto<GameListResponseDto.GameDto> getAdminGames(int page) {
Pageable pageable = PageRequest.of(page, 7);
// return reportRepository.findAllForAdmin(pageable)
// .map(ReportGameResponseDto::from);
Page<GameEntity> allByAdmin = gameRepository.findAllByAdmin(pageable);
Page<GameListResponseDto.GameDto> list = allByAdmin.map(game ->
GameListResponseDto.GameDto.builder()
.gameId(game.getGameId())
.gameThumbnailUrl(game.getGameThumbnailUrl())
.gameTitle(game.getGameTitle())
.questionCount(game.getQuestionCount())
.playCount(game.getPlayCount())
.updatedAt(game.getUpdatedAt())
.build()
);
return PageResponseDto.of(list);
}

public Void blockUser(BlockUserRequestDto blockUserRequestDto) {
List<String> emailList = blockUserRequestDto.getBanList().stream()
.map(BlockUserRequestDto.UserBanItem::getEmail)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ject.recreation.storage.db.core;

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;
Expand Down Expand Up @@ -50,4 +51,8 @@ List<GameEntity> findGamesWithEmailAndCursor(

// 기본 게임들을 조회하는 메서드
List<GameEntity> findAllByGameCreatorEmailAndIsDeletedFalse(String gameCreatorEmail);

@Query(value = "SELECT g FROM GameEntity g JOIN g.gameCreator u WHERE u.role = 'ADMIN'",
countQuery = "SELECT count(g) FROM GameEntity g JOIN g.gameCreator u WHERE u.role = 'ADMIN'")
Page<GameEntity> findAllByAdmin( Pageable pageable);
}