-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…t-date Feature/#88 total event date
- Loading branch information
Showing
7 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...rc/main/java/JGS/CasperEvent/domain/event/controller/eventController/EventController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package JGS.CasperEvent.domain.event.controller.eventController; | ||
|
||
|
||
import JGS.CasperEvent.domain.event.dto.ResponseDto.TotalEventDateResponseDto; | ||
import JGS.CasperEvent.domain.event.service.eventService.EventService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/event") | ||
|
||
public class EventController { | ||
private final EventService eventService; | ||
|
||
@GetMapping("/total") | ||
public ResponseEntity<TotalEventDateResponseDto> getTotalEventDate() { | ||
TotalEventDateResponseDto totalEventDateResponseDto = eventService.getTotalEventDate(); | ||
return ResponseEntity.ok(totalEventDateResponseDto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...src/main/java/JGS/CasperEvent/domain/event/dto/ResponseDto/TotalEventDateResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package JGS.CasperEvent.domain.event.dto.ResponseDto; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record TotalEventDateResponseDto(LocalDate totalEventStartDate, LocalDate totalEventEndDate) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
Server/src/main/java/JGS/CasperEvent/domain/event/service/eventService/EventService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package JGS.CasperEvent.domain.event.service.eventService; | ||
|
||
import JGS.CasperEvent.domain.event.dto.ResponseDto.TotalEventDateResponseDto; | ||
import JGS.CasperEvent.domain.event.entity.event.LotteryEvent; | ||
import JGS.CasperEvent.domain.event.entity.event.RushEvent; | ||
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.error.exception.CustomException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EventService { | ||
private final RushEventRepository rushEventRepository; | ||
private final LotteryEventRepository lotteryEventRepository; | ||
|
||
public TotalEventDateResponseDto getTotalEventDate() { | ||
List<LotteryEvent> lotteryEventList = lotteryEventRepository.findAll(); | ||
List<RushEvent> rushEventList = rushEventRepository.findAll(); | ||
|
||
if (lotteryEventList.isEmpty()) { | ||
throw new CustomException("추첨 이벤트가 DB에 존재하지 않습니다.", CustomErrorCode.NO_LOTTERY_EVENT); | ||
} | ||
|
||
List<LocalDate> localDateList = new ArrayList<>(); | ||
|
||
// lotteryEvent는 어차피 최대 1개만 존재 | ||
localDateList.add(lotteryEventList.get(0).getStartDateTime().toLocalDate()); | ||
localDateList.add(lotteryEventList.get(0).getEndDateTime().toLocalDate()); | ||
|
||
for (RushEvent rushEvent : rushEventList) { | ||
localDateList.add(rushEvent.getStartDateTime().toLocalDate()); | ||
} | ||
|
||
localDateList.sort(null); | ||
|
||
return new TotalEventDateResponseDto(localDateList.get(0), localDateList.get(localDateList.size() - 1)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters