Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 영화 검색 결과 조회 로직 수정 #54

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading