Implement movie explorer API features

This commit is contained in:
2026-06-11 17:10:51 +03:30
parent 6a01e43eb2
commit 9bd80349b2
5 changed files with 71 additions and 29 deletions
+20 -3
View File
@@ -106,9 +106,26 @@ public class MovieService {
// TODO: Write your code here
// All parsing code must be inside try-catch
try {
// Your code here
} catch (Exception e) {
String jsonResponse = getMoviesByGenreList(genreId, page);
if (jsonResponse == null || jsonResponse.isEmpty()) {
System.out.println("No response received.");
return;
}
JsonObject rootObject = JsonParser.parseString(jsonResponse).getAsJsonObject();
JsonArray moviesArray = rootObject.getAsJsonArray("movies");
int total = rootObject.get("total").getAsInt();
int totalPages = rootObject.get("total_pages").getAsInt();
Type movieListType = new TypeToken<ArrayList<Movie>>() {}.getType();
Gson gson = new Gson();
List<Movie> movies = gson.fromJson(moviesArray, movieListType);
System.out.println("Movies:");
for (Movie movie : movies) {
System.out.println("ID: " + movie.getId() + " | " + movie.getTitle() + " (" + movie.getYear() + ")");
}
System.out.println("Total movies: " + total);
System.out.println("Total pages: " + totalPages);
}
catch (Exception e) {
System.err.println("ERROR: " + e.getMessage());
}
}