Skip to content

Commit

Permalink
refactor : Admin 도메인을 AdminFindingGame, AdminRacingGame 도메인으로 분리 (CC-…
Browse files Browse the repository at this point in the history
…132) (#26)

* refactor : Admin 도메인을 AdminFindingGame, AdminRacingGame 도메인으로 분리
(CC-132)

* feat : S3 이미지 업로드 에러코드 추가
(CC-132)

* rename : HealthTestController 의 패키지명을 api로 변경
(CC-132)

* feat : S3 이미지 업로드 응답/요청 객체 생성
(CC-132)

* feat : S3 이미지 api에 ResponseEntity 추가
(CC-132)

* teat : S3 이미지 업로드 실패 테스트코드
(CC-132)

* teat : S3 이미지 업로드 성공 테스트코드 작성
(CC-132)

* teat : 테스트코드 실행을 위한 환경 구성
(CC-132)

* teat : 테스트코드 실행을 위한 환경 구성 삭제
(CC-132)

* test : S3 이미지 업로드 성공 테스트 코드 작성
(CC-132)

* refactor : admin 디렉터리 내부로 통합 (CC-132)
  • Loading branch information
j2noo authored Aug 12, 2024
1 parent b0641f1 commit de1ef93
Show file tree
Hide file tree
Showing 19 changed files with 368 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package ai.softeer.caecae.admin.api;

import ai.softeer.caecae.admin.domain.dto.request.FindingGameDailyAnswerRequestDto;
import ai.softeer.caecae.admin.domain.dto.response.FindingGameDailyAnswerResponseDto;
import ai.softeer.caecae.admin.service.AdminFindingGameService;
import ai.softeer.caecae.findinggame.service.FindingGameService;
import ai.softeer.caecae.global.dto.response.SuccessResponse;
import ai.softeer.caecae.global.enums.SuccessCode;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterFindingGamePeriodRequestDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RegisterFindingGamePeriodResponseDto;
import ai.softeer.caecae.racinggame.service.RacingGameInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/admin/finding")
@RequiredArgsConstructor
public class AdminFindingGameController {
private final RacingGameInfoService racingGameService;
private final FindingGameService findingGameService;
private final AdminFindingGameService adminFindingGameService;

/**
* 어드민이 숨은캐스퍼찾기 게임 기간을 등록하는 api
*
* @param req 게임 시작 날짜
* @return 등록된 게임 시작 날짜, 종료 날짜(+6일)
*/
@PostMapping("/period")
public ResponseEntity<SuccessResponse<RegisterFindingGamePeriodResponseDto>>
registerFindingGamePeriod(@RequestBody RegisterFindingGamePeriodRequestDto req) {
RegisterFindingGamePeriodResponseDto res = adminFindingGameService.registerFindingGamePeriod(req);
return SuccessResponse.of(SuccessCode.CREATED, res);
}

/**
* 어드민이 숨은캐스퍼찾기 날짜별 정답을 등록하는 api
*
* @param req
* @return
*/
@PostMapping("/answer")
public ResponseEntity<SuccessResponse<FindingGameDailyAnswerResponseDto>>
saveFindingGameDailyInfo(@RequestBody FindingGameDailyAnswerRequestDto req) {
FindingGameDailyAnswerResponseDto res = adminFindingGameService.saveFindingGameDailyAnswer(req);
return SuccessResponse.of(SuccessCode.OK, res);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package ai.softeer.caecae.admin.api;

import ai.softeer.caecae.admin.domain.dto.response.RacingGameWinnerResponseDto;
import ai.softeer.caecae.admin.domain.dto.request.FindingGameDailyAnswerRequestDto;
import ai.softeer.caecae.admin.domain.dto.response.FindingGameDailyAnswerResponseDto;
import ai.softeer.caecae.admin.service.AdminService;
import ai.softeer.caecae.admin.service.AdminRacingGameService;
import ai.softeer.caecae.findinggame.service.FindingGameService;
import ai.softeer.caecae.global.dto.response.SuccessResponse;
import ai.softeer.caecae.global.enums.SuccessCode;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterFindingGamePeriodRequestDto;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterRacingGameInfoRequestDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RegisterFindingGamePeriodResponseDto;
import ai.softeer.caecae.racinggame.domain.dto.response.RegisterRacingGameInfoResponseDto;
import ai.softeer.caecae.racinggame.service.RacingGameInfoService;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,19 +16,19 @@
import java.util.List;

@RestController
@RequestMapping("/api/admin")
@RequestMapping("/api/admin/racing")
@RequiredArgsConstructor
public class AdminController {
public class AdminRacingGameController {
private final RacingGameInfoService racingGameService;
private final FindingGameService findingGameService;
private final AdminService adminService;
private final AdminRacingGameService adminRacingGameService;

/**
* 관리자가 등록된 레이싱게임의 정보를 조회하는 로직
*
* @return 레이싱게임 정보
*/
@GetMapping("/racing/period")
@GetMapping("/period")
public ResponseEntity<SuccessResponse<RacingGameInfoResponseDto>> getRacingGameInfo() {
RacingGameInfoResponseDto racingGameInfoDto = racingGameService.getRacingGameInfo();
return SuccessResponse.of(SuccessCode.OK, racingGameInfoDto);
Expand All @@ -43,7 +39,7 @@ public ResponseEntity<SuccessResponse<RacingGameInfoResponseDto>> getRacingGameI
*
* @param req 레이싱게임 정보
*/
@PostMapping("/racing/period")
@PostMapping("/period")
public ResponseEntity<SuccessResponse<RegisterRacingGameInfoResponseDto>> registerRacingGame(
@RequestBody RegisterRacingGameInfoRequestDto req
) {
Expand All @@ -56,44 +52,18 @@ public ResponseEntity<SuccessResponse<RegisterRacingGameInfoResponseDto>> regist
*
* @return 당첨자 리스트
*/
@PostMapping("/racing/winners")
@PostMapping("/winners")
public ResponseEntity<SuccessResponse<List<RacingGameWinnerResponseDto>>> drawRacingGameWinner() {
return SuccessResponse.of(SuccessCode.CREATED, adminService.drawRacingGameWinner());
return SuccessResponse.of(SuccessCode.CREATED, adminRacingGameService.drawRacingGameWinner());
}

/**
* 당첨자를 반환하는 API
*
* @return 당첨자 리스트
*/
@GetMapping("/racing/winners")
@GetMapping("/winners")
public ResponseEntity<SuccessResponse<List<RacingGameWinnerResponseDto>>> getRacingGameWinner() {
return SuccessResponse.of(SuccessCode.OK, adminService.getRacingGameWinner());
return SuccessResponse.of(SuccessCode.OK, adminRacingGameService.getRacingGameWinner());
}

/**
* 어드민이 숨은캐스퍼찾기 게임 기간을 등록하는 api
*
* @param req 게임 시작 날짜
* @return 등록된 게임 시작 날짜, 종료 날짜(+6일)
*/
@PostMapping("/finding/period")
public ResponseEntity<SuccessResponse<RegisterFindingGamePeriodResponseDto>>
registerFindingGamePeriod(@RequestBody RegisterFindingGamePeriodRequestDto req) {
RegisterFindingGamePeriodResponseDto res = adminService.registerFindingGamePeriod(req);
return SuccessResponse.of(SuccessCode.CREATED, res);
}

/**
* 어드민이 숨은캐스퍼찾기 날짜별 정답을 등록하는 api
*
* @param req
* @return
*/
@PostMapping("/finding/answer")
public ResponseEntity<SuccessResponse<FindingGameDailyAnswerResponseDto>>
saveFindingGameDailyInfo(@RequestBody FindingGameDailyAnswerRequestDto req) {
FindingGameDailyAnswerResponseDto res = adminService.saveFindingGameDailyAnswer(req);
return SuccessResponse.of(SuccessCode.OK, res);
}
}
}
21 changes: 15 additions & 6 deletions src/main/java/ai/softeer/caecae/admin/api/S3Controller.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package ai.softeer.caecae.admin.api;

import ai.softeer.caecae.global.utils.S3Service;
import ai.softeer.caecae.admin.domain.dto.response.S3ResponseDto;
import ai.softeer.caecae.admin.service.S3Service;
import ai.softeer.caecae.global.dto.response.SuccessResponse;
import ai.softeer.caecae.global.enums.SuccessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin/s3")
public class S3Controller {
// TBD : Admin의 컨트롤러들, 이미지 업로드 등의 기능을 일반 사용자가 이용 못하게 막아야 하지 않는가?
private final S3Service s3Service;

@PostMapping("/api/s3")
public String upload(@RequestParam("file") MultipartFile file) {
String filePath = s3Service.uploadFile(file);
return filePath + "created!";
//TODO : ResponseEntity 생성하기
@PostMapping("")
public ResponseEntity<SuccessResponse<S3ResponseDto>> upload(
@RequestParam("file") MultipartFile file,
String directory
) {
S3ResponseDto res = s3Service.uploadFile(file, directory);
return SuccessResponse.of(SuccessCode.CREATED, res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ai.softeer.caecae.admin.domain.dto.request;

import lombok.Builder;
import org.springframework.web.multipart.MultipartFile;

// S3에 이미지를 업로드 할 때 사용하는 요청 객체
@Builder
public record S3RequestDto(
MultipartFile file
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

@Builder
public record RacingGameWinnerResponseDto(
int ranking,
String phone,
double distance,
Integer selection
int ranking,
String phone,
double distance,
Integer selection
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ai.softeer.caecae.admin.domain.dto.response;

import lombok.Builder;

// S3에 이미지를 업로드 한 후 받는 응답 객체
@Builder
public record S3ResponseDto(
String imageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ai.softeer.caecae.admin.domain.exception;

import ai.softeer.caecae.global.enums.ErrorCode;
import lombok.Getter;

@Getter
public class AdminFindingGameException extends RuntimeException {
private final ErrorCode errorCode;

public AdminFindingGameException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ai.softeer.caecae.admin.domain.exception;

import ai.softeer.caecae.global.dto.response.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
* FindingGame 도메인에서 에러를 핸들링하여 HttpResponse 를 반환하는 핸들러
*/
@Slf4j
@ControllerAdvice
public class AdminFindingGameExceptionHandler {
// FindingGameException 에 대한 에러 핸들링
@ExceptionHandler(value = AdminFindingGameException.class)
public ResponseEntity<ErrorResponse> handleFindingGameException(AdminFindingGameException adminException) {
log.error(adminException.getMessage(), adminException);
return ErrorResponse.of(adminException.getErrorCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import lombok.Getter;

@Getter
public class AdminException extends RuntimeException {
public class AdminRacingGameException extends RuntimeException {
private final ErrorCode errorCode;

public AdminException(ErrorCode errorCode) {
public AdminRacingGameException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
*/
@Slf4j
@ControllerAdvice
public class AdminExceptionHandler {
public class AdminRacingGameExceptionHandler {
// RacingGameException 에 대한 에러 핸들링
@ExceptionHandler(value = AdminException.class)
public ResponseEntity<ErrorResponse> handleRacingGameException(AdminException adminException) {
@ExceptionHandler(value = AdminRacingGameException.class)
public ResponseEntity<ErrorResponse> handleRacingGameException(AdminRacingGameException adminException) {
log.error(adminException.getMessage(), adminException);
return ErrorResponse.of(adminException.getErrorCode());
}
Expand Down
Loading

0 comments on commit de1ef93

Please sign in to comment.