source: source/MovieZilla-master/src/main/java/com/example/demo/controller/MovieController.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: 3.8 KB
Line 
1package com.example.demo.controller;
2
3import com.example.demo.model.Genre;
4import com.example.demo.model.IS_.MovieGenreCombination;
5import com.example.demo.model.IS_.MovieGenreKey;
6import com.example.demo.model.Movie;
7import com.example.demo.repository.GenreRepository;
8import com.example.demo.repository.MovieGenreCombinationRepository;
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("/movies")
20public class MovieController {
21 private final MovieService movieService;
22 private final MovieProjectionService movieProjectionService;
23 private final MovieGenreCombinationRepository movieGenreCombinationRepository;
24 private final GenreRepository genreRepository;
25
26 public MovieController(MovieService movieService, MovieProjectionService movieProjectionService, MovieGenreCombinationRepository movieGenreCombinationRepository, GenreRepository genreRepository) {
27 this.movieService = movieService;
28 this.movieProjectionService = movieProjectionService;
29 this.movieGenreCombinationRepository = movieGenreCombinationRepository;
30 this.genreRepository = genreRepository;
31 }
32
33
34 @GetMapping
35 public String getMoviePage(@RequestParam(required = false) String error, Model model) {
36 if (error != null && !error.isEmpty()) {
37 model.addAttribute("hasError", true);
38 model.addAttribute("error", error);
39 }
40 List<Movie> movie= this.movieService.findAll();
41 model.addAttribute("movie", movieGenreCombinationRepository.findAll());
42 model.addAttribute("bodyContent", "movies");
43 return "master-template";
44 }
45 @PreAuthorize("hasRole('ROLE_EMPLOYEE')")
46 @GetMapping("/add-form")
47 public String addMoviePage(Model model) {
48 List<Movie> movie = this.movieService.findAll();
49 List<Genre> genres = this.genreRepository.findAll();
50 model.addAttribute("movie", movie);
51 model.addAttribute("genre", genres);
52 model.addAttribute("bodyContent", "add-movie");
53 return "master-template";
54 }
55
56 @PreAuthorize("hasRole('ROLE_EMPLOYEE')")
57 @PostMapping("/add")
58 public String saveMovie(
59 @RequestParam(required = false) Integer movie_id,
60 @RequestParam String movie_name,
61 @RequestParam String movie_age_category,
62 @RequestParam String movie_cast,
63 @RequestParam String movie_film_director,
64 @RequestParam String movie_production,
65 @RequestParam String movie_time_duration,
66 @RequestParam Integer genre_id )
67 {
68
69 this.movieService.save(movie_id, movie_name, movie_age_category, movie_cast, movie_production,movie_film_director, movie_time_duration);
70 MovieGenreKey movieGenreKey = new MovieGenreKey();
71 movieGenreKey.setMovie(this.movieService.findById(movie_id).get());
72 movieGenreKey.setGenre(this.genreRepository.findById(genre_id).get());
73 MovieGenreCombination movieGenreCombination = new MovieGenreCombination();
74 movieGenreCombination.setMovieGenreKey(movieGenreKey);
75 this.movieGenreCombinationRepository.save(movieGenreCombination);
76 return "redirect:/movies";
77 }
78
79 /*
80 @RequestMapping("/view/movies/id?={movie_id}")
81 public String viewMovies(Model model, @RequestParam Integer movie_id){
82 List<MovieProjection> moviegoer = movieProjectionService.findByMovieID(movie_id);
83 model.addAttribute("moviegoer", moviegoer);
84 return "view";
85 }*/
86
87
88
89
90
91}
Note: See TracBrowser for help on using the repository browser.