WinnerController Swagger 문서화 추가 및 이벤트/참여자 예외 처리 개선

- WinnerController에 Swagger 어노테이션 추가 (Operation, Parameter, ParameterObject)
- 당첨자 목록 조회 API 기본 정렬 설정 (winnerRank ASC, size=20)
- ParticipationService에서 이벤트/참여자 구분 로직 개선
  - 이벤트 없음: EventNotFoundException 발생
  - 참여자 없음: ParticipantNotFoundException 발생
- EventCacheService 제거 (Redis 기반 검증에서 DB 기반 검증으로 변경)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
doyeon
2025-10-27 11:15:04 +09:00
parent 958184c9d1
commit 9039424c40
18 changed files with 1330 additions and 45 deletions
@@ -2,6 +2,8 @@ package com.kt.event.common.exception;
import com.kt.event.common.dto.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.mapping.PropertyReferenceException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
@@ -161,6 +163,66 @@ public class GlobalExceptionHandler {
.body(errorResponse);
}
/**
* 데이터 무결성 제약 위반 예외 처리
*
* @param ex 데이터 무결성 예외
* @return 에러 응답
*/
@ExceptionHandler(DataIntegrityViolationException.class)
public ResponseEntity<ErrorResponse> handleDataIntegrityViolationException(DataIntegrityViolationException ex) {
log.warn("Data integrity violation: {}", ex.getMessage());
String message = "데이터 중복 또는 무결성 제약 위반이 발생했습니다";
String details = ex.getMessage();
// 중복 키 에러인 경우 메시지 개선
if (ex.getMessage() != null) {
if (ex.getMessage().contains("uk_event_phone") || ex.getMessage().contains("phone_number")) {
message = "이미 참여하신 이벤트입니다";
details = "동일한 전화번호로 이미 참여 기록이 있습니다";
} else if (ex.getMessage().contains("participant_id")) {
message = "참여 처리 중 오류가 발생했습니다";
details = "잠시 후 다시 시도해주세요";
}
}
ErrorResponse errorResponse = ErrorResponse.of(
ErrorCode.DUPLICATE_PARTICIPATION.getCode(),
message,
details
);
return ResponseEntity
.status(HttpStatus.CONFLICT)
.body(errorResponse);
}
/**
* 잘못된 정렬 필드 예외 처리
*
* @param ex 속성 참조 예외
* @return 에러 응답
*/
@ExceptionHandler(PropertyReferenceException.class)
public ResponseEntity<ErrorResponse> handlePropertyReferenceException(PropertyReferenceException ex) {
log.warn("Invalid sort property: {}", ex.getMessage());
String message = "잘못된 정렬 필드입니다";
String details = String.format("'%s' 필드는 존재하지 않습니다. 사용 가능한 필드: id, participantId, eventId, name, phoneNumber, email, storeVisited, bonusEntries, agreeMarketing, agreePrivacy, isWinner, winnerRank, wonAt, createdAt, updatedAt",
ex.getPropertyName());
ErrorResponse errorResponse = ErrorResponse.of(
ErrorCode.COMMON_003.getCode(),
message,
details
);
return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.body(errorResponse);
}
/**
* 일반 예외 처리
*