Compare commits
9 Commits
feature/do
...
feature/ge
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
deb6550f14 | ||
|
|
545a5a0780 | ||
|
|
535f3d69c1 | ||
|
|
fa8fa6b923 | ||
|
|
b7d7eeba5c | ||
|
|
46a2fbc256 | ||
|
|
e1987c21ba | ||
|
|
81caa62709 | ||
|
|
72e6f0628f |
@@ -32,6 +32,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, "상영관 정보를 찾을 수 없습니다."),
|
||||
@@ -102,6 +103,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,16 +1,23 @@
|
||||
package com.ticketing.server.movie.application;
|
||||
|
||||
import static com.ticketing.server.user.domain.UserGrade.ROLES.USER;
|
||||
|
||||
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;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
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,12 +28,28 @@ public class TicketController {
|
||||
|
||||
private final TicketService ticketService;
|
||||
|
||||
@GetMapping("/payments/{paymentId}")
|
||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||
@GetMapping
|
||||
@Secured(USER)
|
||||
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}")
|
||||
@Secured(USER)
|
||||
public ResponseEntity<TicketDetailsResponse> findTicketsByPaymentId(
|
||||
@PathVariable("paymentId") @NotNull Long paymentId) {
|
||||
TicketDetailsDTO tickets = ticketService.findTicketsByPaymentId(paymentId);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK)
|
||||
.body(tickets.toResponse());
|
||||
.body(
|
||||
tickets.toResponse()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public class MovieListResponse {
|
||||
|
||||
@ApiModelProperty(value = "영화 제목")
|
||||
@ApiModelProperty(value = "영화 목록")
|
||||
private List<MovieDTO> movieDtos;
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
public class MovieTimeListResponse {
|
||||
|
||||
@ApiModelProperty(value = "영화 시간표 정보")
|
||||
@ApiModelProperty(value = "영화 시간표 목록")
|
||||
private List<MovieTimeDTO> movieTimeDtos;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ticketing.server.movie.application.response;
|
||||
|
||||
import com.ticketing.server.movie.service.dto.TicketDTO;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TicketListResponse {
|
||||
|
||||
@ApiModelProperty(value = "티켓 목록")
|
||||
private List<TicketDTO> ticketDtos;
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class Ticket extends AbstractEntity {
|
||||
|
||||
@NotNull
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
||||
@JoinColumn(name = "movie_time_id", referencedColumnName = "id", updatable = false)
|
||||
private MovieTime movieTime;
|
||||
|
||||
private Long paymentId;
|
||||
|
||||
@@ -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;
|
||||
@@ -11,8 +12,16 @@ import org.springframework.stereotype.Repository;
|
||||
public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
||||
|
||||
@Query(
|
||||
value =
|
||||
"SELECT t "
|
||||
value = "SELECT t "
|
||||
+ "FROM Ticket t "
|
||||
+ "JOIN FETCH t.seat s "
|
||||
+ "WHERE t.movieTime = :movieTime "
|
||||
+ "AND t.deletedAt IS NULL"
|
||||
)
|
||||
List<Ticket> findValidTickets(MovieTime movieTime);
|
||||
|
||||
@Query(
|
||||
value = "SELECT t "
|
||||
+ "FROM Ticket t "
|
||||
+ "JOIN FETCH t.movieTime mt "
|
||||
+ "JOIN FETCH t.seat s "
|
||||
@@ -22,8 +31,7 @@ public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
||||
List<Ticket> findTicketFetchJoinByPaymentId(@Param("paymentId") Long paymentId);
|
||||
|
||||
@Query(
|
||||
value =
|
||||
"SELECT t "
|
||||
value = "SELECT t "
|
||||
+ "FROM Ticket t "
|
||||
+ "JOIN FETCH t.movieTime mt "
|
||||
+ "JOIN FETCH t.seat s "
|
||||
|
||||
@@ -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,10 +1,14 @@
|
||||
package com.ticketing.server.movie.service;
|
||||
|
||||
import com.ticketing.server.global.exception.ErrorCode;
|
||||
import com.ticketing.server.movie.domain.MovieTime;
|
||||
import com.ticketing.server.movie.domain.repository.MovieTimeRepository;
|
||||
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
||||
import com.ticketing.server.movie.domain.Ticket;
|
||||
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.dto.TicketReservationDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketSoldDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
||||
@@ -30,6 +34,21 @@ public class TicketServiceImpl implements TicketService {
|
||||
|
||||
private final TicketRepository ticketRepository;
|
||||
|
||||
private final MovieTimeRepository movieTimeRepository;
|
||||
|
||||
@Override
|
||||
public TicketListDTO getTickets(@NotNull Long movieTimeId) {
|
||||
MovieTime movieTime = movieTimeRepository.findById(movieTimeId)
|
||||
.orElseThrow(ErrorCode::throwMovieTimeNotFound);
|
||||
|
||||
List<TicketDTO> tickets = ticketRepository.findValidTickets(movieTime)
|
||||
.stream()
|
||||
.map(TicketDTO::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new TicketListDTO(tickets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId) {
|
||||
List<TicketDetailDTO> ticketDetails = ticketRepository.findTicketFetchJoinByPaymentId(paymentId)
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
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(access = AccessLevel.PRIVATE)
|
||||
public class TicketDTO {
|
||||
|
||||
private Long ticketId;
|
||||
|
||||
private Integer ticketPrice;
|
||||
|
||||
private Integer seatRow;
|
||||
|
||||
private Integer seatColumn;
|
||||
|
||||
private TicketStatus status;
|
||||
|
||||
public TicketDTO(Ticket ticket) {
|
||||
this(
|
||||
ticket.getId(),
|
||||
ticket.getTicketPrice(),
|
||||
ticket.getRow(),
|
||||
ticket.getColumn(),
|
||||
ticket.getStatus()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.ticketing.server.movie.service.dto;
|
||||
|
||||
import com.ticketing.server.movie.application.response.TicketListResponse;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class TicketListDTO {
|
||||
|
||||
private final List<TicketDTO> ticketDtos;
|
||||
|
||||
public TicketListResponse toResponse() {
|
||||
return new TicketListResponse(ticketDtos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.ticketing.server.movie.service.interfaces;
|
||||
|
||||
import com.ticketing.server.global.validator.constraints.NotEmptyCollection;
|
||||
import com.ticketing.server.movie.service.dto.TicketDetailsDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketListDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketsCancelDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketsReservationDTO;
|
||||
import com.ticketing.server.movie.service.dto.TicketsSoldDTO;
|
||||
@@ -10,6 +11,8 @@ import javax.validation.constraints.NotNull;
|
||||
|
||||
public interface TicketService {
|
||||
|
||||
TicketListDTO getTickets(@NotNull Long movieTimeId);
|
||||
|
||||
TicketDetailsDTO findTicketsByPaymentId(@NotNull Long paymentId);
|
||||
|
||||
TicketsReservationDTO ticketReservation(@NotEmptyCollection List<Long> ticketIds);
|
||||
|
||||
Reference in New Issue
Block a user