1 | package com.example.demo.controller;
|
---|
2 |
|
---|
3 | import com.example.demo.model.Auditorium;
|
---|
4 | import com.example.demo.model.Gives.Gives;
|
---|
5 | import com.example.demo.model.Gives.GivesKey;
|
---|
6 | import com.example.demo.model.Movie;
|
---|
7 | import com.example.demo.model.MovieProjection;
|
---|
8 | import com.example.demo.repository.*;
|
---|
9 | import com.example.demo.service.MovieProjectionService;
|
---|
10 | import com.example.demo.service.MovieService;
|
---|
11 | import org.springframework.security.access.prepost.PreAuthorize;
|
---|
12 | import org.springframework.stereotype.Controller;
|
---|
13 | import org.springframework.ui.Model;
|
---|
14 | import org.springframework.web.bind.annotation.*;
|
---|
15 |
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | @Controller
|
---|
19 | @RequestMapping("/projections")
|
---|
20 | public class MovieProjectionController {
|
---|
21 | private final MovieProjectionService movieProjectionService;
|
---|
22 | private final MovieService movieService;
|
---|
23 | private final MovieProjectionRepository movieProjectionRepository;
|
---|
24 | private final MovieGenreCombinationRepository movieGenreCombinationRepository;
|
---|
25 | private final AuditoriumRepository auditoriumRepository;
|
---|
26 | private final GivesRepository givesRepository;
|
---|
27 | private final SeatRepository seatRepository;
|
---|
28 | public MovieProjectionController(MovieProjectionService movieProjectionService, MovieService movieService, MovieProjectionRepository movieProjectionRepository, MovieGenreCombinationRepository movieGenreCombinationRepository, AuditoriumRepository auditoriumRepository, GivesRepository givesRepository, SeatRepository seatRepository) {
|
---|
29 | this.movieProjectionService = movieProjectionService;
|
---|
30 | this.movieService = movieService;
|
---|
31 | this.movieProjectionRepository = movieProjectionRepository;
|
---|
32 | this.movieGenreCombinationRepository = movieGenreCombinationRepository;
|
---|
33 | this.auditoriumRepository = auditoriumRepository;
|
---|
34 | this.givesRepository = givesRepository;
|
---|
35 | this.seatRepository = seatRepository;
|
---|
36 | }
|
---|
37 |
|
---|
38 | @GetMapping
|
---|
39 | public String getProjectionPage(@RequestParam(required = false) String error, Model model) {
|
---|
40 | if (error != null && !error.isEmpty()) {
|
---|
41 | model.addAttribute("hasError", true);
|
---|
42 | model.addAttribute("error", error);
|
---|
43 | }
|
---|
44 | List<MovieProjection> movieprojection = this.movieProjectionService.findAll();
|
---|
45 | model.addAttribute("movieprojection", movieprojection);
|
---|
46 | model.addAttribute("bodyContent", "projections");
|
---|
47 | return "master-template";
|
---|
48 | }
|
---|
49 | @PreAuthorize("hasRole('ROLE_EMPLOYEE')")
|
---|
50 | @GetMapping("/add-form")
|
---|
51 | public String addProjectionPage(Model model) {
|
---|
52 | List<Movie> movie = this.movieService.findAll();
|
---|
53 | List<Auditorium> auditorium = this.auditoriumRepository.findAll();
|
---|
54 | model.addAttribute("movie", movie);
|
---|
55 | model.addAttribute("auditorium", auditorium);
|
---|
56 | model.addAttribute("bodyContent", "add-projection");
|
---|
57 | return "master-template";
|
---|
58 | }
|
---|
59 | @PreAuthorize("hasRole('ROLE_EMPLOYEE')")
|
---|
60 | @PostMapping("/add")
|
---|
61 | public String saveProjection(
|
---|
62 | @RequestParam(required = false) Integer projection_id,
|
---|
63 | @RequestParam String projection_movie_start,
|
---|
64 | @RequestParam String projection_movie_end,
|
---|
65 | @RequestParam String projection_screening_date,
|
---|
66 | @RequestParam String projection_type,
|
---|
67 | @RequestParam Float projection_price,
|
---|
68 | @RequestParam Integer movie_id,
|
---|
69 | @RequestParam Integer auditorium_id) {
|
---|
70 | this.movieProjectionService.save(projection_id, projection_movie_start, projection_movie_end, projection_screening_date, projection_type, projection_price, movie_id);
|
---|
71 |
|
---|
72 | Gives gives = new Gives();
|
---|
73 | GivesKey givesKey = new GivesKey();
|
---|
74 | MovieProjection movieProjection = this.movieProjectionService.findById(projection_id).get();
|
---|
75 | Auditorium auditorium = this.auditoriumRepository.findById(auditorium_id).get();
|
---|
76 | givesKey.setMovieProjection(movieProjection);
|
---|
77 | givesKey.setAuditorium(auditorium);
|
---|
78 | gives.setGivesKey(givesKey);
|
---|
79 | gives.setSeat_limitation(35);
|
---|
80 | this.givesRepository.save(gives);
|
---|
81 | return "redirect:/projections";
|
---|
82 | }
|
---|
83 | }
|
---|