source: Git/src/main/java/com/wediscussmovies/project/web/controller/MovieController.java@ 2d57cad

main
Last change on this file since 2d57cad was 6e7b472, checked in by Petar Partaloski <ppartaloski@…>, 2 years ago

Initial commit, barebones setup

  • Property mode set to 100644
File size: 1.1 KB
Line 
1package com.wediscussmovies.project.web.controller;
2
3import com.wediscussmovies.project.model.Movie;
4import com.wediscussmovies.project.service.MovieService;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.RequestMapping;
9import org.springframework.web.bind.annotation.RequestParam;
10
11import java.util.List;
12
13@Controller
14@RequestMapping("/movies")
15public class MovieController {
16 private final MovieService movieService;
17
18 public MovieController(MovieService movieService) {
19 this.movieService = movieService;
20 }
21
22 @GetMapping
23 public String getMovies(@RequestParam(required = false) String titleQuery, Model model){
24 List<Movie> movies;
25 if(titleQuery == null || titleQuery.isEmpty()) {
26 movies = movieService.listAll();
27 }
28 else{
29 movies = movieService.searchByTitle(titleQuery);
30 }
31 model.addAttribute("movies", movies);
32 model.addAttribute("contentTemplate", "moviesList");
33 return "template";
34 }
35
36}
Note: See TracBrowser for help on using the repository browser.