We have one controller class, which exposes just one method (we can extend it further to expose more APIs). This method lists all the movies in the hardcoded movie list under a URL, /movie, as shown in the following code snippet:
@RestController
public class MovieController {
@RequestMapping(value = "/movie", method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("#oauth2.hasScope('movie') and #oauth2.hasScope('read')")
public Movie[] getMovies() {
initIt();//Movie list initialization
return movies;
}
//…
}
We are using a Movie model class utilizing all the features of the lombok library, as shown in the following code snippet:
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Movie {
private Long id;
private String title;
private String genre;
}
It has three attributes and the annotations will do all the magic and keep the model concise.