diff --git a/src/main/java/com/mookive/mookive_backend/movie/infra/service/MovieEntityGetService.java b/src/main/java/com/mookive/mookive_backend/movie/infra/service/MovieEntityGetService.java index cb65231..49d3ef7 100644 --- a/src/main/java/com/mookive/mookive_backend/movie/infra/service/MovieEntityGetService.java +++ b/src/main/java/com/mookive/mookive_backend/movie/infra/service/MovieEntityGetService.java @@ -41,10 +41,16 @@ private TmdbResponse getTmdbResponse(String tmdbMovieId) { Object title = jsonObject.get("title"); JSONArray genres = (JSONArray) jsonObject.get("genres"); StringBuilder genre = new StringBuilder(); - for(int i=0; i<2; i++) { - JSONObject genreObject = (JSONObject) genres.get(i); + if(genres.length() == 1) { + JSONObject genreObject = (JSONObject) genres.get(0); genre.append(genreObject.get("name")); - if(i==0) genre.append(","); + } + else{ + for(int i=0; i<2; i++) { + JSONObject genreObject = (JSONObject) genres.get(i); + genre.append(genreObject.get("name")); + if(i==0) genre.append(","); + } } Object plot = jsonObject.get("overview"); Object poster = "https://image.tmdb.org/t/p/original" + jsonObject.get("poster_path"); @@ -65,6 +71,11 @@ private KoficResponse getKoficResponse(String title, String year) { JSONObject apiResponse = new JSONObject(koficComponent.findMovieByTitleAndYear(koficKey, title, year, year)); JSONObject jsonObject = (JSONObject) apiResponse.get("movieListResult"); JSONArray dataResult = (JSONArray) jsonObject.get("movieList"); + if(dataResult.isEmpty()) { + apiResponse = new JSONObject(koficComponent.findMovieByTitleAndYear(koficKey, title, "", "")); + jsonObject = (JSONObject) apiResponse.get("movieListResult"); + dataResult = (JSONArray) jsonObject.get("movieList"); + } JSONObject movie = (JSONObject) dataResult.get(0); String nation = movie.get("nationAlt").toString(); JSONArray directors = (JSONArray) movie.get("directors");