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 | |
---|
1 | package com.wediscussmovies.project.web.controller;
|
---|
2 |
|
---|
3 | import com.wediscussmovies.project.model.Movie;
|
---|
4 | import com.wediscussmovies.project.service.MovieService;
|
---|
5 | import org.springframework.stereotype.Controller;
|
---|
6 | import org.springframework.ui.Model;
|
---|
7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
8 | import org.springframework.web.bind.annotation.RequestMapping;
|
---|
9 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
10 |
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | @Controller
|
---|
14 | @RequestMapping("/movies")
|
---|
15 | public 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.