Skip to content

Commit

Permalink
feat: add year at datafield
Browse files Browse the repository at this point in the history
  • Loading branch information
JONG-KYEONG committed Aug 13, 2024
1 parent 5d1b45b commit d843d88
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 8 deletions.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified server/.gradle/8.8/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified server/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions server/build/resources/main/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
#
#tmdb.api.key=${TMDB_API_KEY}

spring.servlet.multipart.max-file-size=50MB
spring.servlet.multipart.max-request-size=50MB

spring.security.oauth2.client.registration.google.client-id=240772131497-d17ho20q4gb42n5s42ncohdh5k9379rc.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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
spring.security.oauth2.client.registration.google.redirect-uri=http://glogglogglog-env.eba-fuksumx7.ap-northeast-2.elasticbeanstalk.com/oauth2/callback/google
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified server/build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public ContentDetailResponse getContentDetailResponse(Long userId, Long contentI
.contentId(contentId)
.contentImage(dataField.getImage())
.contentType(dataField.getMediaType())
.year(dataField.getYear())
.addressTag(addressTags)
.contentTitle(dataField.getTitleName())
.isScraped(isScraped(user,dataField))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public record ContentDetailResponse(
String contentTitle,
String contentImage,
String contentType,
String year,
Boolean isScraped,
List<String> addressTag,
List<PlaceDto> placeDtos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public class DataField {
private String image;
@Column(name = "genre")
private String genre;
@Column(name = "year")
private String year;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public void saveImage(){
List<DataField> dataFields = dataFieldRepository.findAll();
for(DataField dataField : dataFields){
if(dataField.getMediaType().equals("movie")){
dataField.setGenre(getMovieGenres(dataField.getTitleName()));
dataField.setYear(getMovieReleaseYear(dataField.getTitleName()));
dataFieldRepository.save(dataField);
}
else{
dataField.setGenre(getTvShowGenres(dataField.getTitleName()));
dataField.setYear(getTvShowStartYear(dataField.getTitleName()));
dataFieldRepository.save(dataField);
}
}
Expand Down Expand Up @@ -156,4 +156,62 @@ public String getMovieGenres(String query) {
return "No genres found";
}

// TV 드라마 방영 시작 년도 가져오기
public String getTvShowStartYear(String query) {
String searchUrl = UriComponentsBuilder.fromHttpUrl("https://api.themoviedb.org/3/search/tv")
.queryParam("api_key", apiKey)
.queryParam("query", query)
.queryParam("language", "ko-KR")
.toUriString();

Map<String, Object> searchResponse = restTemplate.getForObject(searchUrl, Map.class);

if (searchResponse != null && !((List<?>) searchResponse.get("results")).isEmpty()) {
Map<String, Object> firstResult = ((List<Map<String, Object>>) searchResponse.get("results")).get(0);
String id = String.valueOf(firstResult.get("id"));

String detailsUrl = UriComponentsBuilder.fromHttpUrl("https://api.themoviedb.org/3/tv/" + id)
.queryParam("api_key", apiKey)
.queryParam("language", "ko-KR")
.toUriString();

Map<String, Object> detailsResponse = restTemplate.getForObject(detailsUrl, Map.class);

if (detailsResponse != null && detailsResponse.get("first_air_date") != null) {
String firstAirDate = String.valueOf(detailsResponse.get("first_air_date"));
return firstAirDate.split("-")[0]; // 첫 번째 요소로부터 년도만 추출
}
}
return "";
}

// 영화 상영 년도 가져오기
public String getMovieReleaseYear(String query) {
String searchUrl = UriComponentsBuilder.fromHttpUrl("https://api.themoviedb.org/3/search/movie")
.queryParam("api_key", apiKey)
.queryParam("query", query)
.queryParam("language", "ko-KR")
.toUriString();

Map<String, Object> searchResponse = restTemplate.getForObject(searchUrl, Map.class);

if (searchResponse != null && !((List<?>) searchResponse.get("results")).isEmpty()) {
Map<String, Object> firstResult = ((List<Map<String, Object>>) searchResponse.get("results")).get(0);
String id = String.valueOf(firstResult.get("id"));

String detailsUrl = UriComponentsBuilder.fromHttpUrl("https://api.themoviedb.org/3/movie/" + id)
.queryParam("api_key", apiKey)
.queryParam("language", "ko-KR")
.toUriString();

Map<String, Object> detailsResponse = restTemplate.getForObject(detailsUrl, Map.class);

if (detailsResponse != null && detailsResponse.get("release_date") != null) {
String releaseDate = String.valueOf(detailsResponse.get("release_date"));
return releaseDate.split("-")[0]; // 첫 번째 요소로부터 년도만 추출
}
}
return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ public class TmdbController {
private final TmdbService tmdbService;

// @GetMapping("/movie-image")
// public String getMovieImage() {
// tmdbService.saveImage();
// return "success save image";
// public String getMovieImage(@RequestParam String title) {
// return tmdbService.getTvShowStartYear(title);
// }
}

0 comments on commit d843d88

Please sign in to comment.