Skip to content

Commit

Permalink
Merge pull request kahluaband#47 from kjiyun/tickets
Browse files Browse the repository at this point in the history
kahluaband#9 Feat: add exception in ticket when student id is not unique
  • Loading branch information
kjiyun authored Aug 1, 2024
2 parents 8c2ed14 + ce7621a commit 0d7ad49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ErrorStatus implements BaseCode {
// 티켓 에러
TICKET_NOT_FOUND(HttpStatus.NOT_FOUND, "TICKET NOT FOUND", "티켓을 찾을 수 없습니다."),
TICKET_COLUMN_INVALID(HttpStatus.BAD_REQUEST, "TICKET COLUMN INVALID", "올바르지 않은 티켓 속성입니다."),
ALREADY_EXIST_STUDENT_ID(HttpStatus.BAD_REQUEST, "ALREADY EXIST STUDENT_ID", "이미 존재하는 학번입니다."),

//지원하기 에러
ALREADY_EXIST_APPLICANT(HttpStatus.BAD_REQUEST, "ALREADY EXIST APPLICANT", "이미 존재하는 지원자입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import kahlua.KahluaProject.repository.ParticipantsRepository;
import kahlua.KahluaProject.repository.TicketRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
Expand All @@ -35,7 +36,12 @@ public TicketCreateResponse createTicket(TicketCreateRequest ticketCreateRequest
String reservationId = uniqueReservationId();

Ticket savedTicket = TicketConverter.toTicket(ticketCreateRequest, reservationId);
ticketRepository.save(savedTicket);

try {
ticketRepository.save(savedTicket);
} catch (DataIntegrityViolationException e) { //SQLIntegrityConstraintViolationException 발생하는 경우
throw new GeneralException(ErrorStatus.ALREADY_EXIST_STUDENT_ID);
}

// service 혹은 converter
List<Participants> members = ticketCreateRequest.getMembers().stream()
Expand Down

0 comments on commit 0d7ad49

Please sign in to comment.