Add a view to show movies of a given user (or all movies if no user is specified).
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
package com.camillepradel.movierecommender.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.camillepradel.movierecommender.model.Genre;
|
||||
import com.camillepradel.movierecommender.model.Movie;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
String message = "Welcome to Spring MVC!";
|
||||
@ -20,4 +26,26 @@ public class MainController {
|
||||
mv.addObject("name", name);
|
||||
return mv;
|
||||
}
|
||||
|
||||
@RequestMapping("/movies")
|
||||
public ModelAndView showMovies(
|
||||
@RequestParam(value = "user_id", required = false) Integer userId) {
|
||||
System.out.println("show Movies of user " + userId);
|
||||
|
||||
// TODO: write query to retrieve all movies from DB or all movies rated by user with id userId,
|
||||
// depending on whether or not a value was given for userId
|
||||
List<Movie> movies = new LinkedList<Movie>();
|
||||
Genre genre0 = new Genre(0, "genre0");
|
||||
Genre genre1 = new Genre(1, "genre1");
|
||||
Genre genre2 = new Genre(2, "genre2");
|
||||
movies.add(new Movie(0, "Titre 0", Arrays.asList(new Genre[] {genre0, genre1})));
|
||||
movies.add(new Movie(1, "Titre 1", Arrays.asList(new Genre[] {genre0, genre2})));
|
||||
movies.add(new Movie(2, "Titre 2", Arrays.asList(new Genre[] {genre1})));
|
||||
movies.add(new Movie(3, "Titre 3", Arrays.asList(new Genre[] {genre0, genre1, genre2})));
|
||||
|
||||
ModelAndView mv = new ModelAndView("movies");
|
||||
mv.addObject("userId", userId);
|
||||
mv.addObject("movies", movies);
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.camillepradel.movierecommender.model;
|
||||
|
||||
public class Genre {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Genre(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.camillepradel.movierecommender.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Movie {
|
||||
|
||||
private int id;
|
||||
private String title;
|
||||
private List<Genre> genres;
|
||||
|
||||
public Movie(int id, String title, List<Genre> genres) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.genres = genres;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public List<Genre> getGenres() {
|
||||
return this.genres;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user