From 7e4ab8f5f14cdf8dc3041dc7bb97f6f871f70c59 Mon Sep 17 00:00:00 2001
From: syyling <sy0hiu@gmail.com>
Date: Wed, 29 May 2024 22:30:11 +0900
Subject: [PATCH] =?UTF-8?q?[fix]=20tmdb=20=EB=B0=98=ED=99=98=EA=B0=92=20?=
 =?UTF-8?q?=EC=9E=A5=EB=A5=B4=201=EA=B0=9C=EC=9D=B8=20=EA=B2=BD=EC=9A=B0?=
 =?UTF-8?q?=EB=8F=84=20=EC=A0=80=EC=9E=A5=ED=95=A0=20=EC=88=98=20=EC=9E=88?=
 =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95,=20kofic=20=EB=B0=98?=
 =?UTF-8?q?=ED=99=98=EA=B0=92=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?=
 =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20api=20=EC=9A=94=EC=B2=AD=ED=95=A0=20?=
 =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../infra/service/MovieEntityGetService.java    | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

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");