add: MOVIE_TIME_NOT_FOUND exception
This commit is contained in:
@@ -26,6 +26,7 @@ public enum ErrorCode {
|
||||
USER_NOT_FOUND(NOT_FOUND, "해당 유저 정보를 찾을 수 없습니다."),
|
||||
EMAIL_NOT_FOUND(NOT_FOUND, "해당 이메일을 찾을 수 없습니다."),
|
||||
MOVIE_NOT_FOUND(NOT_FOUND, "해당 제목의 영화를 찾을 수 없습니다."),
|
||||
MOVIE_TIME_NOT_FOUND(NOT_FOUND, "해당 영화 시간표 정보를 찾을 수 없습니다"),
|
||||
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "리프레쉬 토큰을 찾을 수 없습니다."),
|
||||
PAYMENT_ID_NOT_FOUND(NOT_FOUND, "결제정보를 찾을 수 없습니다."),
|
||||
THEATER_NOT_FOUND(NOT_FOUND, "상영관 정보를 찾을 수 없습니다."),
|
||||
@@ -76,6 +77,10 @@ public enum ErrorCode {
|
||||
throw new TicketingException(MOVIE_NOT_FOUND);
|
||||
}
|
||||
|
||||
public static TicketingException throwMovieTimeNotFound() {
|
||||
throw new TicketingException(MOVIE_TIME_NOT_FOUND);
|
||||
}
|
||||
|
||||
public static TicketingException throwRefreshTokenNotFound() {
|
||||
throw new TicketingException(REFRESH_TOKEN_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.ticketing.server.movie.application;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketDetailsResponse;
|
||||
import com.ticketing.server.movie.application.response.TicketListResponse;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketListDTO;
|
||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -11,6 +14,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -21,10 +25,26 @@ public class TicketController {
|
||||
|
||||
private final TicketService ticketService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<TicketListResponse> getTickets(
|
||||
@ApiParam(value = "영화 시간표 ID", required = true) @RequestParam @NotNull Long movieTimeId) {
|
||||
TicketListDTO ticketListDto = ticketService.getTickets(movieTimeId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
ticketListDto.toResponse()
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("payments/{paymentId}")
|
||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(
|
||||
@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||
TicketDetailsDTO tickets = ticketService.findTicketsByPaymentId(paymentId);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(tickets.toResponse());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(
|
||||
tickets.toResponse()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ticketing.server.movie.domain.repository;
|
||||
|
||||
import com.ticketing.server.movie.domain.MovieTime;
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@@ -14,10 +15,10 @@ public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
||||
value = "SELECT t "
|
||||
+ "FROM Ticket t "
|
||||
+ "JOIN FETCH t.seat s "
|
||||
+ "WHERE t.movieTimeId = :movieTimeId "
|
||||
+ "WHERE t.movieTime = :movieTime "
|
||||
+ "AND t.deletedAt IS NULL"
|
||||
)
|
||||
List<Ticket> findValidTickets(@Param("movieTimesId") Long movieTimeId);
|
||||
List<Ticket> findValidTickets(MovieTime movieTime);
|
||||
|
||||
@Query(
|
||||
value =
|
||||
|
||||
@@ -38,12 +38,13 @@ public class MovieTimeServiceImpl implements MovieTimeService {
|
||||
public RegisteredMovieTimeDTO registerMovieTime(@Valid MovieTimeRegisterDTO movieTimeRegisterDto) {
|
||||
Movie movie = findMovieById(movieTimeRegisterDto.getMovieId());
|
||||
Theater theater = findTheaterByNumber(movieTimeRegisterDto.getTheaterNumber());
|
||||
|
||||
int round = movieTimeRegisterDto.getRound();
|
||||
|
||||
Optional<MovieTime> movieTime =
|
||||
movieTimeRepository.findByMovieAndTheaterAndRoundAndDeletedAtNull(movie, theater, round);
|
||||
|
||||
if(movieTime.isEmpty()) {
|
||||
if (movieTime.isEmpty()) {
|
||||
MovieTime newMovieTime = movieTimeRepository.save(
|
||||
new MovieTime(movie, theater, round, movieTimeRegisterDto.getStartAt())
|
||||
);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.ticketing.server.movie.service;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
import com.ticketing.server.movie.domain.MovieTime;
|
||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||
import com.ticketing.server.movie.domain.repository.TicketRepository;
|
||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketListDTO;
|
||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
||||
@@ -25,9 +27,19 @@ public class TicketServiceImpl implements TicketService {
|
||||
|
||||
private final TicketRepository ticketRepository;
|
||||
|
||||
private final MovieTimeRepository movieTimeRepository;
|
||||
|
||||
@Override
|
||||
public TicketListDTO getTickets(Long movieTimeId) {
|
||||
List<Ticket> tickets = ticketRepository.findValidTickets(movieTimeId);
|
||||
public TicketListDTO getTickets(@NotNull Long movieTimeId) {
|
||||
MovieTime movieTime = movieTimeRepository.findById(movieTimeId)
|
||||
.orElseThrow(ErrorCode::throwMovieTimeNotFound);
|
||||
|
||||
List<TicketDTO> tickets = ticketRepository.findValidTickets(movieTimeId)
|
||||
.stream()
|
||||
.map(TicketDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new TicketListDTO(tickets);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.ticketing.server.movie.service.dto;
|
||||
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
import com.ticketing.server.movie.domain.TicketStatus;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class TicketDTO {
|
||||
|
||||
private Long ticketId;
|
||||
@@ -15,4 +18,16 @@ public class TicketDTO {
|
||||
|
||||
private Integer seatColumn;
|
||||
|
||||
private TicketStatus status;
|
||||
|
||||
public TicketDTO(Ticket ticket) {
|
||||
this(
|
||||
ticket.getId(),
|
||||
ticket.getTicketPrice(),
|
||||
ticket.getRow(),
|
||||
ticket.getColumn(),
|
||||
ticket.getStatus()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface TicketService {
|
||||
|
||||
TicketListDTO getTickets(Long movieTimeId)
|
||||
TicketListDTO getTickets(Long movieTimeId);
|
||||
|
||||
TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user