Skip to content

Commit

Permalink
Merge pull request #54 from syyling/feat/49
Browse files Browse the repository at this point in the history
[fix] 영화 검색 결과 조회 로직 수정
  • Loading branch information
syyling authored May 30, 2024
2 parents ff95cd0 + 8213a4a commit 4c1447c
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public List<MovieResponse.MovieTitleResponse> getMovieTitleList(String title) {
return tmdbMovieTtitleResponseList;
}

/**
* TODO: 성능 향상 필요
*/
public List<MovieResponse.MovieTitleSearchResponse> getMovieTitleSearchResult(String title) {
List<MovieResponse.MovieTitleSearchResponse> tmdbMovieTitleSearchResponseList = new ArrayList<>();
JSONObject jsonObject = new JSONObject(tmdbSearchComponent.findMovieTitleList(title, "ko-KR"));
Expand All @@ -44,8 +47,8 @@ public List<MovieResponse.MovieTitleSearchResponse> getMovieTitleSearchResult(St
JSONObject result = (JSONObject) results.get(i);
String titleResult = result.get("title").toString();
String year = result.get("release_date").toString().substring(0, 4);
System.out.println(titleResult + " " + year);
JSONObject koficResponse = new JSONObject(koficComponent.findMovieByTitleAndYear(koficKey, titleResult, year, year));

JSONObject movieListResult = (JSONObject) koficResponse.get("movieListResult");
JSONArray dataResult = (JSONArray) movieListResult.get("movieList");
if(!dataResult.isEmpty()) {
Expand All @@ -68,6 +71,39 @@ public List<MovieResponse.MovieTitleSearchResponse> getMovieTitleSearchResult(St
.build();
tmdbMovieTitleSearchResponseList.add(tmdbMovieTitleSearchResponse);
}
else {
int i1 = Integer.parseInt(year) + 1;
String openYear = String.valueOf(i1);
koficResponse = new JSONObject(koficComponent.findMovieByTitleAndYear(koficKey, titleResult, openYear, openYear));
movieListResult = (JSONObject) koficResponse.get("movieListResult");
dataResult = (JSONArray) movieListResult.get("movieList");
if(dataResult.isEmpty()) continue;
for(int k=0; k<dataResult.length();k++) {
JSONObject movie = (JSONObject) dataResult.get(k);
String movieNm = movie.get("movieNm").toString();
if(movieNm.equals(titleResult)) {
String nation = movie.get("nationAlt").toString();
JSONArray directors = (JSONArray) movie.get("directors");
StringBuilder director = new StringBuilder();
for(int j=0; j<directors.length(); j++) {
JSONObject directorObject = (JSONObject) directors.get(j);
director.append(directorObject.get("peopleNm"));
if(j<directors.length()-1) director.append(",");
}
MovieResponse.MovieTitleSearchResponse tmdbMovieTitleSearchResponse = MovieResponse.MovieTitleSearchResponse.builder()
.tmdbId(result.get("id").toString())
.title(titleResult)
.year(year)
.poster("https://image.tmdb.org/t/p/original" + result.get("poster_path"))
.director(director.toString())
.nation(nation)
.build();
tmdbMovieTitleSearchResponseList.add(tmdbMovieTitleSearchResponse);
break;
}
}

}
}
return tmdbMovieTitleSearchResponseList;
}
Expand Down

0 comments on commit 4c1447c

Please sign in to comment.