Last active
April 11, 2018 19:17
-
-
Save yaneury/b384c78a484d517d13a2dafb4edc86cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MovieViewModel { | |
| Movie m; | |
| double avgRating; | |
| public MovieViewModel(Movie m, double avgRating) { | |
| this.m = m; | |
| this.avgRating = avgRating; | |
| } | |
| public String getTitle() { | |
| return m.getTitle(); // forward all getters from Movie | |
| } | |
| public double getAvgRating() { | |
| return avgRating; | |
| } | |
| } | |
| public class MovieAPIModel { | |
| Movie m; | |
| public MovieViewModel(Movie m) { | |
| this.m = m; | |
| } | |
| public String getTitle() { | |
| return m.getTitle(); // forward specific getters from Movie | |
| } | |
| } | |
| public class MovieViewController { | |
| @Autowired | |
| MovieService movieService; | |
| @GetMapping("/movie/{slug}") | |
| public String getMovie(@PathVariable String slug, Model m) { | |
| Movie m = movieService.getMovieBySlug(slug); | |
| MovieViewModel mvm = new MovieViewModel(m, movieService.getAvgRating(slug)); | |
| m.addAttribute("movie", mvm); | |
| return "media/movie"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment