상영관등록하기


상영관 등록을 위한 로직
- 프론트에서 상영관id, 영화id. 상영날짜를 보내준다
- 관리자 권한이 등록이 가능한 사람인지를 체크한다.
- 영화와 상영관의 상영시간을 가져온다.
- 상영시간을 등록한다.
1. controller
@PostMapping("/admin/showtime")
    public String saveShowtime(@ModelAttribute AdminShotimeRequest.ShowtimeSaveRequest req) {
        // 상영관 등록 처리
        int day = adminService.상영관등록하기(req);
        // 리다이렉트로 /admin/showtime 페이지로 이동
        return "redirect:/admin/showtime/"+ day;
    }2.service
//어드민 유저확인해야함 원래 -- 추가필요
    @Transactional
    public int 상영관등록하기(AdminShotimeRequest.ShowtimeSaveRequest req) {
        // 영화와 상영관을 가져옴
        Movie movie = movieRepository.findById(req.getMovieId())
                .orElseThrow(() -> new ExceptionApi401("Movie not found"));
        Screen screen = screenRepository.findById(req.getScreenId())
                .orElseThrow(() -> new ExceptionApi404("Screen not found"));
        // 상영 시간 엔티티 생성
        Showtime showtime = new Showtime();
        showtime.setMovie(movie);
        showtime.setScreen(screen);
        showtime.setPrice(req.getPrice());
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime localDateTime = LocalDateTime.parse(req.getTime(), formatter);
        // LocalDateTime을 Timestamp로 변환
        Timestamp timestamp = Timestamp.valueOf(localDateTime);
        showtime.setStartedAt(timestamp);  // 상영 시작 시간 설정
        int dayOfMonth = localDateTime.getDayOfMonth();
        // 상영 시간 저장
        showtimeRepository.save(showtime);
        return dayOfMonth;
    }3.dto
public class AdminShotimeRequest {
    @Data
    public static class LoginDTO {
        @NotEmpty
        private String username;
        @NotEmpty
        private String password;
    }
    @Data
    public static class ShowtimeSaveRequest {
        private Long movieId;
        private String time;  // 상영 시작 시간
        private Long screenId;  // 상영관 ID
        private Integer price =10;
        public ShowtimeSaveRequest(){}
        public ShowtimeSaveRequest(Long movieId, String time, Long screenId) {
            this.movieId = movieId;
            this.time = time;
            this.screenId = screenId;
        }
    }
}추가로직
등록하려는 상영시간에 중복되는 시간이 없는지 검증을 하는 로직이 필요해 보인다.
Share article