-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from syyling/feat/27
[feat/refactor/fix] 영화 제목 리스트 검색 기능 추가, 영화 제목 검색 결과 조회 기능 추가, kofic api 파라미터 추가, infra 패키지 구조 변경
- Loading branch information
Showing
9 changed files
with
160 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/com/mookive/mookive_backend/movie/application/service/MovieSearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.mookive.mookive_backend.movie.application.service; | ||
|
||
import com.mookive.mookive_backend.movie.application.dto.response.MovieResponse; | ||
import com.mookive.mookive_backend.movie.infra.component.KoficComponent; | ||
import com.mookive.mookive_backend.movie.infra.component.TmdbSearchComponent; | ||
import lombok.*; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MovieSearchService { | ||
|
||
private final TmdbSearchComponent tmdbSearchComponent; | ||
private final KoficComponent koficComponent; | ||
|
||
@Value("${kofic.service-key}") | ||
private String koficKey; | ||
|
||
public List<MovieResponse.MovieTitleResponse> getMovieTitleList(String title) { | ||
List<MovieResponse.MovieTitleResponse> tmdbMovieTtitleResponseList = new ArrayList<>(); | ||
JSONObject jsonObject = new JSONObject(tmdbSearchComponent.findMovieTitleList(title, "ko-KR")); | ||
JSONArray results = (JSONArray) jsonObject.get("results"); | ||
for(int i=0; i<results.length(); i++) { | ||
JSONObject result = (JSONObject) results.get(i); | ||
MovieResponse.MovieTitleResponse tmdbMovieTitleResponse = MovieResponse.MovieTitleResponse.builder() | ||
.title(result.get("title").toString()) | ||
.build(); | ||
tmdbMovieTtitleResponseList.add(tmdbMovieTitleResponse); | ||
} | ||
return tmdbMovieTtitleResponseList; | ||
} | ||
|
||
public List<MovieResponse.MovieTitleSearchResponse> getMovieTitleSearchResult(String title) { | ||
List<MovieResponse.MovieTitleSearchResponse> tmdbMovieTitleSearchResponseList = new ArrayList<>(); | ||
JSONObject jsonObject = new JSONObject(tmdbSearchComponent.findMovieTitleList(title, "ko-KR")); | ||
JSONArray results = (JSONArray) jsonObject.get("results"); | ||
for(int i=0; i<results.length(); i++) { | ||
JSONObject result = (JSONObject) results.get(i); | ||
String titleResult = result.get("title").toString(); | ||
String year = result.get("release_date").toString().substring(0, 4); | ||
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()) { | ||
JSONObject movie = (JSONObject) dataResult.get(0); | ||
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() | ||
.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); | ||
} | ||
} | ||
return tmdbMovieTitleSearchResponseList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ve_backend/movie/infra/TmdbComponent.java → .../movie/infra/component/TmdbComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/mookive/mookive_backend/movie/infra/component/TmdbSearchComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mookive.mookive_backend.movie.infra.component; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.service.annotation.GetExchange; | ||
import org.springframework.web.service.annotation.HttpExchange; | ||
|
||
@Component | ||
@HttpExchange | ||
public interface TmdbSearchComponent { | ||
|
||
@GetExchange() | ||
String findMovieTitleList (@RequestParam("query") String title, @RequestParam String language); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters