Skip to content

Commit

Permalink
hotfix : 숨은캐스퍼찾기 당첨자 조회 로직 수정 (#59)
Browse files Browse the repository at this point in the history
* hotfix : 숨은캐스퍼찾기 당첨자 조회 로직 수정

* del : print문 삭제
  • Loading branch information
j2noo authored Aug 26, 2024
1 parent 95b86ea commit 2b10503
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

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;
import ai.softeer.caecae.racinggame.domain.dto.request.RegisterFindingGamePeriodRequestDto;
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")
Expand Down Expand Up @@ -45,4 +43,15 @@ public class AdminFindingGameController {
FindingGameDailyAnswerResponseDto res = adminFindingGameService.saveFindingGameDailyAnswer(req);
return SuccessResponse.of(SuccessCode.OK, res);
}

/**
* 어드민이 숨은 캐스퍼찾기 당첨자를 조회하는 api
*
* @return
*/
@GetMapping("/winner")
public ResponseEntity<SuccessResponse<FindingGameWinnerResponseDto>> getFindingGameWinner() {
FindingGameWinnerResponseDto res = adminFindingGameService.getFindingGameWinner();
return SuccessResponse.of(SuccessCode.OK, res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ai.softeer.caecae.admin.domain.dto;

import lombok.Builder;

@Builder
public record FindingGameWinnerDto(
int day,
String phone
) {
}
Original file line number Diff line number Diff line change
@@ -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<FindingGameWinnerDto> winners
) {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,6 +31,8 @@
public class AdminFindingGameService {
private final FindingGameDbRepository findingGameDbRepository;
private final FindingGameAnswerDbRepository findingGameAnswerDbRepository;
private final FindingGameWinnerRepository findingGameWinnerRepository;
private final UserRepository userRepository;


/**
Expand Down Expand Up @@ -155,4 +163,28 @@ private List<FindingGame> initFindingGames() {
}
return findingGames;
}

public FindingGameWinnerResponseDto getFindingGameWinner() {
List<FindingGameWinner> findingGameWinners = findingGameWinnerRepository.findAll();
List<FindingGameWinnerDto> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

@Repository
public interface FindingGameWinnerRepository extends JpaRepository<FindingGameWinner, Integer> {

@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);

}

0 comments on commit 2b10503

Please sign in to comment.