source: source/MovieZilla-master/src/main/java/com/example/demo/controller/MovieProjectionController.java

Last change on this file was fc7ec52, checked in by darkopopovski <darkopopovski39@…>, 2 years ago

all files

  • Property mode set to 100644
File size: 4.0 KB
Line 
1package com.example.demo.controller;
2
3import com.example.demo.model.Auditorium;
4import com.example.demo.model.Gives.Gives;
5import com.example.demo.model.Gives.GivesKey;
6import com.example.demo.model.Movie;
7import com.example.demo.model.MovieProjection;
8import com.example.demo.repository.*;
9import com.example.demo.service.MovieProjectionService;
10import com.example.demo.service.MovieService;
11import org.springframework.security.access.prepost.PreAuthorize;
12import org.springframework.stereotype.Controller;
13import org.springframework.ui.Model;
14import org.springframework.web.bind.annotation.*;
15
16import java.util.List;
17
18@Controller
19@RequestMapping("/projections")
20public 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}
Note: See TracBrowser for help on using the repository browser.