diff --git a/src/main/java/movie/apis/MovieService.java b/src/main/java/movie/apis/MovieService.java index 3f053f5..107b839 100644 --- a/src/main/java/movie/apis/MovieService.java +++ b/src/main/java/movie/apis/MovieService.java @@ -103,11 +103,26 @@ public class MovieService { * PUT ALL PARSING CODE INSIDE try-catch */ public void displayMoviesByGenre(Long genreId, Long page) { + // TODO: Write your code here // All parsing code must be inside try-catch try { - // Your code here + String jsonResponse = getMoviesByGenreList(genreId, page); + JsonObject jsonObject = JsonParser.parseString(jsonResponse).getAsJsonObject(); + JsonArray jsonMovies = jsonObject.getAsJsonArray("movies"); + System.out.println("\nMovies for genre " + genreId + " (Page " + page + "):"); + for (JsonElement element: jsonMovies) { + JsonObject movie = element.getAsJsonObject(); + long id = movie.get("id").getAsLong(); + String title = movie.get("title").getAsString(); + String year = movie.get("year").getAsString(); + System.out.println("ID: " + id + " | " + title + " (" + year + ")"); + } + long total = jsonObject.get("total").getAsLong(); + long totalPages = jsonObject.get("total_pages").getAsLong(); + System.out.println("Total: " + total +"\n" + "Total pages: " + totalPages); + // Your code here } catch (Exception e) { System.err.println("ERROR: " + e.getMessage()); }