diff --git a/src/main/java/ai/softeer/caecae/admin/api/AdminFindingGameController.java b/src/main/java/ai/softeer/caecae/admin/api/AdminFindingGameController.java index c3cd98b..7e108a5 100644 --- a/src/main/java/ai/softeer/caecae/admin/api/AdminFindingGameController.java +++ b/src/main/java/ai/softeer/caecae/admin/api/AdminFindingGameController.java @@ -2,6 +2,7 @@ import ai.softeer.caecae.admin.domain.dto.request.FindingGameDailyAnswerRequestDto; import ai.softeer.caecae.admin.domain.dto.response.FindingGameDailyAnswerResponseDto; +import ai.softeer.caecae.admin.domain.dto.response.FindingGameWinnerResponseDto; import ai.softeer.caecae.admin.service.AdminFindingGameService; import ai.softeer.caecae.global.dto.response.SuccessResponse; import ai.softeer.caecae.global.enums.SuccessCode; @@ -9,10 +10,7 @@ import ai.softeer.caecae.racinggame.domain.dto.response.RegisterFindingGamePeriodResponseDto; 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; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/admin/finding") @@ -45,4 +43,15 @@ public class AdminFindingGameController { FindingGameDailyAnswerResponseDto res = adminFindingGameService.saveFindingGameDailyAnswer(req); return SuccessResponse.of(SuccessCode.OK, res); } + + /** + * 어드민이 숨은 캐스퍼찾기 당첨자를 조회하는 api + * + * @return + */ + @GetMapping("/winner") + public ResponseEntity> getFindingGameWinner() { + FindingGameWinnerResponseDto res = adminFindingGameService.getFindingGameWinner(); + return SuccessResponse.of(SuccessCode.OK, res); + } } diff --git a/src/main/java/ai/softeer/caecae/admin/domain/dto/FindingGameWinnerDto.java b/src/main/java/ai/softeer/caecae/admin/domain/dto/FindingGameWinnerDto.java new file mode 100644 index 0000000..9cb8c21 --- /dev/null +++ b/src/main/java/ai/softeer/caecae/admin/domain/dto/FindingGameWinnerDto.java @@ -0,0 +1,10 @@ +package ai.softeer.caecae.admin.domain.dto; + +import lombok.Builder; + +@Builder +public record FindingGameWinnerDto( + int day, + String phone +) { +} diff --git a/src/main/java/ai/softeer/caecae/admin/domain/dto/response/FindingGameWinnerResponseDto.java b/src/main/java/ai/softeer/caecae/admin/domain/dto/response/FindingGameWinnerResponseDto.java new file mode 100644 index 0000000..7e76e73 --- /dev/null +++ b/src/main/java/ai/softeer/caecae/admin/domain/dto/response/FindingGameWinnerResponseDto.java @@ -0,0 +1,12 @@ +package ai.softeer.caecae.admin.domain.dto.response; + +import ai.softeer.caecae.admin.domain.dto.FindingGameWinnerDto; +import lombok.Builder; + +import java.util.List; + +@Builder +public record FindingGameWinnerResponseDto( + List winners +) { +} diff --git a/src/main/java/ai/softeer/caecae/admin/service/AdminFindingGameService.java b/src/main/java/ai/softeer/caecae/admin/service/AdminFindingGameService.java index d482534..c76a978 100644 --- a/src/main/java/ai/softeer/caecae/admin/service/AdminFindingGameService.java +++ b/src/main/java/ai/softeer/caecae/admin/service/AdminFindingGameService.java @@ -1,17 +1,23 @@ package ai.softeer.caecae.admin.service; import ai.softeer.caecae.admin.domain.dto.FindingGameAnswerDto; +import ai.softeer.caecae.admin.domain.dto.FindingGameWinnerDto; import ai.softeer.caecae.admin.domain.dto.request.FindingGameDailyAnswerRequestDto; import ai.softeer.caecae.admin.domain.dto.response.FindingGameDailyAnswerResponseDto; +import ai.softeer.caecae.admin.domain.dto.response.FindingGameWinnerResponseDto; import ai.softeer.caecae.admin.domain.exception.AdminFindingGameException; import ai.softeer.caecae.findinggame.domain.entity.FindingGame; import ai.softeer.caecae.findinggame.domain.entity.FindingGameAnswer; +import ai.softeer.caecae.findinggame.domain.entity.FindingGameWinner; import ai.softeer.caecae.findinggame.domain.enums.AnswerType; import ai.softeer.caecae.findinggame.repository.FindingGameAnswerDbRepository; import ai.softeer.caecae.findinggame.repository.FindingGameDbRepository; +import ai.softeer.caecae.findinggame.repository.FindingGameWinnerRepository; import ai.softeer.caecae.global.enums.ErrorCode; import ai.softeer.caecae.racinggame.domain.dto.request.RegisterFindingGamePeriodRequestDto; import ai.softeer.caecae.racinggame.domain.dto.response.RegisterFindingGamePeriodResponseDto; +import ai.softeer.caecae.user.domain.entity.User; +import ai.softeer.caecae.user.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -25,6 +31,8 @@ public class AdminFindingGameService { private final FindingGameDbRepository findingGameDbRepository; private final FindingGameAnswerDbRepository findingGameAnswerDbRepository; + private final FindingGameWinnerRepository findingGameWinnerRepository; + private final UserRepository userRepository; /** @@ -155,4 +163,28 @@ private List initFindingGames() { } return findingGames; } + + public FindingGameWinnerResponseDto getFindingGameWinner() { + List findingGameWinners = findingGameWinnerRepository.findAll(); + List findingGameWinnerDtos = new ArrayList<>(); + + for (FindingGameWinner findingGameWinner : findingGameWinners) { + Integer userId = findingGameWinner.getUser().getId(); + User user = userRepository.findById(userId).orElseThrow( + () -> new AdminFindingGameException(ErrorCode.USER_NOT_FOUND) + ); + findingGameWinnerDtos.add( + FindingGameWinnerDto.builder() + .day(findingGameWinner.getFindingGame().getId()) + .phone(user.getPhone()) + .build() + ); + + } + + return FindingGameWinnerResponseDto.builder() + .winners(findingGameWinnerDtos) + .build(); + } + } diff --git a/src/main/java/ai/softeer/caecae/findinggame/domain/entity/FindingGameWinner.java b/src/main/java/ai/softeer/caecae/findinggame/domain/entity/FindingGameWinner.java index e587316..9287acf 100644 --- a/src/main/java/ai/softeer/caecae/findinggame/domain/entity/FindingGameWinner.java +++ b/src/main/java/ai/softeer/caecae/findinggame/domain/entity/FindingGameWinner.java @@ -3,13 +3,11 @@ import ai.softeer.caecae.global.entity.BaseEntity; import ai.softeer.caecae.user.domain.entity.User; import jakarta.persistence.*; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.NoArgsConstructor; +import lombok.*; @Entity @Builder +@Getter @AllArgsConstructor @NoArgsConstructor(access = AccessLevel.PROTECTED) @IdClass(FindingGameWinnerId.class) diff --git a/src/main/java/ai/softeer/caecae/findinggame/repository/FindingGameWinnerRepository.java b/src/main/java/ai/softeer/caecae/findinggame/repository/FindingGameWinnerRepository.java index 7117de4..9023616 100644 --- a/src/main/java/ai/softeer/caecae/findinggame/repository/FindingGameWinnerRepository.java +++ b/src/main/java/ai/softeer/caecae/findinggame/repository/FindingGameWinnerRepository.java @@ -9,10 +9,12 @@ @Repository public interface FindingGameWinnerRepository extends JpaRepository { + @Modifying @Query(value = """ INSERT IGNORE INTO finding_game_winner (user_id, finding_game_id) VALUES (:userId, :gameId) """, nativeQuery = true) void insertWinner(@Param("userId") Integer userId, @Param("gameId") Integer gameId); + }