Skip to content
Merged
Show file tree
Hide file tree
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 @@ -100,56 +100,27 @@ public KoficMovieInfoDto fetchActor(String movieCode) {


/**
* batch 에 사용합니다.
* 요청이 많아지면 API 키 만료 되서 사용 X
* 올해의 영화 100개 불러오기
*/
// public KoficMovieListDto fetchBathMovie(int page, int maxResults) {
// LocalDate today = LocalDate.now();
//
// String startDate = today.minusYears(2).format(DateTimeFormatter.ofPattern("yyyy"));
// String endDate = today.format(DateTimeFormatter.ofPattern("yyyy"));
//
// URI uri = UriComponentsBuilder.fromUriString(KOFIC_URL + "/searchMovieList.json")
// .queryParam("key", API_KEY)
// .queryParam("curPage", page)
// .queryParam("itemPerPage", maxResults)
// .queryParam("openStartDt", startDate)
// .queryParam("openEndDt", endDate)
// .build()
// .toUri();
//
// try {
// String response = restTemplate.getForObject(uri, String.class);
// ObjectMapper objectMapper = new ObjectMapper();
// return objectMapper.readValue(response, KoficMovieListDto.class);
// } catch (Exception e) {
// throw new RuntimeException("Failed", e);
// }
// }

// public Integer fetchMoviesTotalsCount() {
// LocalDate today = LocalDate.now();
//
// String startDate = today.minusYears(2).format(DateTimeFormatter.ofPattern("yyyy"));
// String endDate = today.format(DateTimeFormatter.ofPattern("yyyy"));
//
// URI uri = UriComponentsBuilder.fromUriString(KOFIC_URL + "/searchMovieList.json")
// .queryParam("key", API_KEY)
// .queryParam("curPage", "1")
// .queryParam("itemPerPage", "10")
// .queryParam("openStartDt", startDate)
// .queryParam("openEndDt", endDate)
// .build()
// .toUri();
//
// try {
// String response = restTemplate.getForObject(uri, String.class);
// ObjectMapper objectMapper = new ObjectMapper();
// KoficMovieListDto koficMovieListDto = objectMapper.readValue(response, KoficMovieListDto.class);
//
// return koficMovieListDto.getMovieListResult().getTotalCount();
// } catch (Exception e) {
// throw new RuntimeException("Failed", e);
// }
// }
public KoficMovieListDto getMoviesOfThisYearWithLimit100() {
LocalDate today = LocalDate.now();

String date = today.format(DateTimeFormatter.ofPattern("yyyy"));

URI uri = UriComponentsBuilder.fromUriString(KOFIC_URL + "/searchMovieList.json")
.queryParam("key", API_KEY)
.queryParam("curPage", "1")
.queryParam("itemPerPage", "100")
.queryParam("openStartDt", date)
.build()
.toUri();

try {
String response = restTemplate.getForObject(uri, String.class);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(response, KoficMovieListDto.class);
} catch (Exception e) {
throw new RuntimeException("Failed", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.example.customerservice.movie.service.MovieSchedulerService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -18,7 +17,7 @@ public class MovieController {

@PostMapping("/start")
public ResponseEntity<SchedulerStatus> startScheduler() {
SchedulerStatus status = movieSchedulerService.startMovieSync(true);
SchedulerStatus status = movieSchedulerService.startMovieSync(false);
return ResponseEntity.ok(status);
}

Expand All @@ -28,10 +27,9 @@ public ResponseEntity<SchedulerStatus> stopScheduler() {
return ResponseEntity.ok(status);
}

/** 요청이 많아지면 API 키 만료 되서 사용 X **/
// @GetMapping("/batch")
// public String startBath() {
// movieSchedulerService.startBathSaveMovie();
// return "success";
// }
@PostMapping("/first/data")
public ResponseEntity<String> saveMoviesFirstData() {
movieSchedulerService.saveMoviesOfThisYearWithLimit100();
return ResponseEntity.ok("success");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class MovieSchedulerService {
/**
* 스케줄
*/
public SchedulerStatus startMovieSync(boolean isTestMode) { //TODO: 테스트 용 불린값을 제외 해야한다.
public SchedulerStatus startMovieSync(boolean isTestMode) {
if (scheduledTask != null && !scheduledTask.isCancelled()) {
log.warn("Movie synchronization scheduler is already running.");
return SchedulerStatus.ALREADY_RUNNING;
Expand Down Expand Up @@ -172,21 +172,17 @@ private int checkTotalPages() {


/**
* 배치 개발
* 요청이 많아지면 API 키 만료 되서 사용 X
* 예시 데이터 저장: 올해 영화 총 100 개 저장
*/
// @Transactional
// public void startBathSaveMovie() {
// Integer totalPages = checkTotalPages();
// for (int page = 1; page < totalPages; page++) {
// KoficMovieListDto koficMovieListDto = movieApiClient.fetchBathMovie(page, maxItemCount);
// List<MovieList> movieList = koficMovieListDto.getMovieListResult().getMovieList();
//
// movieList.forEach(movieListItem -> {
// if (!contentsRepository.existsByTitle(movieListItem.getMovieName())) {
// processMovieAndActors(movieListItem);
// }
// });
// }
// }
@Transactional
public void saveMoviesOfThisYearWithLimit100() {
KoficMovieListDto koficMovieListDto = movieApiClient.getMoviesOfThisYearWithLimit100();
List<MovieList> movieList = koficMovieListDto.getMovieListResult().getMovieList();

movieList.forEach(movieListItem -> {
if (!contentsRepository.existsByTitle(movieListItem.getMovieName())) {
processMovieAndActors(movieListItem);
}
});
}
}
Loading