diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java index e97d7268..81b318a6 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/controller/adminController/AdminController.java @@ -1,6 +1,8 @@ package JGS.CasperEvent.domain.event.controller.adminController; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.service.adminService.AdminService; import JGS.CasperEvent.global.response.ResponseDto; import jakarta.validation.Valid; @@ -20,9 +22,17 @@ public AdminController(AdminService adminService) { } @PostMapping("/join") - public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto){ + public ResponseEntity postAdmin(@RequestBody @Valid AdminRequestDto adminRequestDto) { return ResponseEntity .status(HttpStatus.CREATED) .body(adminService.postAdmin(adminRequestDto)); } + + @PostMapping("/event/lottery") + public ResponseEntity createLotteryEvent( + @Valid @RequestBody LotteryEventRequestDto lotteryEventRequestDto) { + return ResponseEntity + .status(HttpStatus.CREATED) + .body(adminService.createLotteryEvent(lotteryEventRequestDto)); + } } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java new file mode 100644 index 00000000..59afda19 --- /dev/null +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/RequestDto/LotteryEventRequestDto.java @@ -0,0 +1,19 @@ +package JGS.CasperEvent.domain.event.dto.RequestDto; + +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +public class LotteryEventRequestDto { + + @NotNull(message = "이벤트 시작 일자를 지정하세요.") + private LocalDateTime eventStartDate; + + @NotNull(message = "이벤트 종료 일자를 지정하세요.") + private LocalDateTime eventEndDate; + + @NotNull(message = "당첨인원 수를 지정하세요.") + private int winnerCount; +} diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java index c15eed07..7690db6a 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/LotteryEventResponseDto.java @@ -2,13 +2,12 @@ import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; public record LotteryEventResponseDto(LocalDateTime serverDateTime, LocalDateTime eventStartDate, LocalDateTime eventEndDate, long activePeriod) { - public static LotteryEventResponseDto of(LocalDateTime serverDateTime, LotteryEvent lotteryEvent) { + public static LotteryEventResponseDto of(LotteryEvent lotteryEvent, LocalDateTime serverDateTime) { return new LotteryEventResponseDto( serverDateTime, lotteryEvent.getStartDateTime(), diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java index 79c76c18..954adeb7 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/entity/event/LotteryEvent.java @@ -3,10 +3,22 @@ import jakarta.persistence.*; import lombok.Getter; +import java.time.LocalDateTime; + @Entity @Getter public class LotteryEvent extends BaseEvent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long lotteryEventId; + + public LotteryEvent(LocalDateTime eventStartDate, LocalDateTime eventEndDate, int winnerCount){ + this.eventStartDate = eventStartDate; + this.eventEndDate = eventEndDate; + this.winnerCount = winnerCount; + } + + public LotteryEvent() { + + } } diff --git a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java index e66fa193..466f7b5c 100644 --- a/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java +++ b/Server/src/main/java/JGS/CasperEvent/domain/event/service/adminService/AdminService.java @@ -1,8 +1,13 @@ package JGS.CasperEvent.domain.event.service.adminService; import JGS.CasperEvent.domain.event.dto.RequestDto.AdminRequestDto; +import JGS.CasperEvent.domain.event.dto.RequestDto.LotteryEventRequestDto; +import JGS.CasperEvent.domain.event.dto.ResponseDto.LotteryEventResponseDto; import JGS.CasperEvent.domain.event.entity.admin.Admin; +import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; import JGS.CasperEvent.domain.event.repository.AdminRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.LotteryEventRepository; +import JGS.CasperEvent.domain.event.repository.eventRepository.RushEventRepository; import JGS.CasperEvent.global.enums.CustomErrorCode; import JGS.CasperEvent.global.enums.Role; import JGS.CasperEvent.global.error.exception.CustomException; @@ -10,12 +15,16 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.NoSuchElementException; @RequiredArgsConstructor @Service public class AdminService { + private final AdminRepository adminRepository; + private final LotteryEventRepository lotteryEventRepository; + private final RushEventRepository rushEventRepository; public Admin verifyAdmin(AdminRequestDto adminRequestDto) { return adminRepository.findById(adminRequestDto.getAdminId()).orElseThrow(NoSuchElementException::new); @@ -33,4 +42,14 @@ public ResponseDto postAdmin(AdminRequestDto adminRequestDto) { return ResponseDto.of("관리자 생성 성공"); } + + public LotteryEventResponseDto createLotteryEvent(LotteryEventRequestDto lotteryEventRequestDto) { + LotteryEvent lotteryEvent = lotteryEventRepository.save(new LotteryEvent( + lotteryEventRequestDto.getEventStartDate(), + lotteryEventRequestDto.getEventEndDate(), + lotteryEventRequestDto.getWinnerCount() + )); + + return LotteryEventResponseDto.of(lotteryEvent, LocalDateTime.now()); + } } diff --git a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java index 75378d38..408ef36a 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java +++ b/Server/src/main/java/JGS/CasperEvent/global/enums/CustomErrorCode.java @@ -5,7 +5,7 @@ @Getter public enum CustomErrorCode { NO_RUSH_EVENT("선착순 이벤트를 찾을 수 없습니다.", 404), - INVALID_CASPERBOT_PARAMETER("잘못된 파라미터 입력입니다.", 400), + INVALID_PARAMETER("잘못된 파라미터 입력입니다.", 400), CASPERBOT_NOT_FOUND("배지를 찾을 수 없습니다.", 404), BAD_REQUEST("잘못된 요청입니다.", 400), UNAUTHORIZED("권한이 없습니다.", 401), diff --git a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java index de569e89..f0e00657 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java +++ b/Server/src/main/java/JGS/CasperEvent/global/error/GlobalExceptionHandler.java @@ -51,7 +51,7 @@ public ResponseEntity methodArgumentNotValidExceptionHandler(Meth return ResponseEntity .status(HttpStatus.BAD_REQUEST) - .body(ErrorResponse.of(CustomErrorCode.INVALID_CASPERBOT_PARAMETER, builder.toString())); + .body(ErrorResponse.of(CustomErrorCode.INVALID_PARAMETER, builder.toString())); } @ExceptionHandler(RuntimeException.class) diff --git a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java index f189a8d0..19d97a11 100644 --- a/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java +++ b/Server/src/main/java/JGS/CasperEvent/global/jwt/filter/VerifyAdminFilter.java @@ -16,7 +16,7 @@ @Slf4j @RequiredArgsConstructor public class VerifyAdminFilter implements Filter { - public static final String AUTHENTICATE_ADMIN = "authenticateAdmin"; + public static final String AUTHENTICATE_ADMIN = "authenticateUser"; private final ObjectMapper objectMapper; private final AdminService adminService; diff --git a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java index 7cdecf86..320b9987 100644 --- a/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java +++ b/Server/src/test/java/JGS/CasperEvent/domain/event/controller/eventController/LotteryEventControllerTest.java @@ -112,7 +112,7 @@ void createCasperBotFailureTest_RequiredFieldNotExist() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); } @@ -141,7 +141,7 @@ void createCasperBotSuccessTest_WrongValue() throws Exception { //then perform.andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.errorCode").value("INVALID_CASPERBOT_PARAMETER")) + .andExpect(jsonPath("$.errorCode").value("INVALID_PARAMETER")) .andDo(print()); }