/** * Only matches 'GET /moviies/{id}}' requests for JSON content; a 404 is sent otherwise. TODO send * a 406 if an unsupported representation, such as XML, is requested. See SPR-7353. */ @RequestMapping( value = "/movies/{id}", method = RequestMethod.GET, headers = "Accept=application/json") public @ResponseBody Movie getMovie(@PathVariable String id) { return moviesRepository.getMovie(id); }
@RequestMapping( value = "/movies/{movieId}", method = RequestMethod.POST, headers = "Accept=text/html") public String updateMovie( Model model, @PathVariable String movieId, @RequestParam(value = "rated", required = false) Integer stars, @RequestParam(value = "comment", required = false) String comment) { Movie movie = moviesRepository.getMovie(movieId); User user = userDetailsService.getUserFromSession(); moviesRepository.rateMovie( movie, user, stars == null ? -1 : stars, comment != null ? comment.trim() : null); return singleMovieView(model, movieId); }
@RequestMapping( value = "/movies/{movieId}", method = RequestMethod.GET, headers = "Accept=text/html") public String singleMovieView(final Model model, @PathVariable String movieId) { User user = addUser(model); Movie movie = moviesRepository.getMovie(movieId); model.addAttribute("id", movieId); if (movie != null) { model.addAttribute("movie", movie); final int stars = movie.getStars(); model.addAttribute("stars", stars); Rating rating = null; if (user != null) rating = movie.getRelationshipTo(user, Rating.class, "RATED"); if (rating == null) rating = new Rating().rate(stars, null); model.addAttribute("userRating", rating); } return "/movies/show"; }