implement final changes for displaying movie by ID inside movie service and main
This commit is contained in:
@@ -34,6 +34,9 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
System.out.println("Please enter movie ID: ");
|
||||||
|
long movieID = scanner.nextLong();
|
||||||
|
movieService.displayMovieDetails(movieID);
|
||||||
// TODO (BONUS): Get movie ID from user, then call movieService.displayMovieDetails()
|
// TODO (BONUS): Get movie ID from user, then call movieService.displayMovieDetails()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,10 +136,10 @@ public class MovieService {
|
|||||||
private String getMovieById(Long movieId) {
|
private String getMovieById(Long movieId) {
|
||||||
try {
|
try {
|
||||||
// TODO: Complete this method
|
// TODO: Complete this method
|
||||||
// String url = MOVIE_BY_ID_URL + movieId;
|
String url = MOVIE_BY_ID_URL + movieId;
|
||||||
// HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build();
|
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build();
|
||||||
// HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
// if (response.statusCode() == 200) return response.body();
|
if (response.statusCode() == 200) return response.body();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -196,6 +196,23 @@ public class MovieService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
JsonObject movieObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
|
||||||
|
Gson gson = new Gson();
|
||||||
|
Movie movie = gson.fromJson(jsonResponse, Movie.class);
|
||||||
|
System.out.println("________________________ " + movie.getTitle().toUpperCase()+ " (" + movie.getYear() +
|
||||||
|
") ________________________");
|
||||||
|
System.out.println("IMDB rating: " + movie.getImdb_rating() +
|
||||||
|
" | Votes: " + movie.getImdb_votes());
|
||||||
|
System.out.println("Director: " + movie.getDirector());
|
||||||
|
System.out.println("Cast: " + movie.getActors());
|
||||||
|
System.out.println("Genre: " + movie.getGenres());
|
||||||
|
System.out.println("Runtime: " + movie.getRuntime() +
|
||||||
|
" | Rated: " + movie.getRated());
|
||||||
|
System.out.println("Country: " + movie.getCountry() +
|
||||||
|
" | Released: " + movie.getReleased());
|
||||||
|
System.out.println("Plot: " + movie.getPlot());
|
||||||
|
System.out.println("Awards: " + movie.getAwards());
|
||||||
|
|
||||||
// TODO: Parse jsonResponse to JsonObject
|
// TODO: Parse jsonResponse to JsonObject
|
||||||
// HINT: Use JsonParser.parseString(jsonResponse).getAsJsonObject()
|
// HINT: Use JsonParser.parseString(jsonResponse).getAsJsonObject()
|
||||||
// TODO: use Gson to parse the json
|
// TODO: use Gson to parse the json
|
||||||
|
|||||||
Reference in New Issue
Block a user