diff --git a/customer-service/src/main/java/com/example/customerservice/actor/controller/AppearanceController.java b/customer-service/src/main/java/com/example/customerservice/actor/controller/AppearanceController.java index 191391c..ae201f9 100644 --- a/customer-service/src/main/java/com/example/customerservice/actor/controller/AppearanceController.java +++ b/customer-service/src/main/java/com/example/customerservice/actor/controller/AppearanceController.java @@ -13,7 +13,7 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/appearance") +@RequestMapping("/api/movie/appearance") public class AppearanceController { private final AppearanceService appearanceService; @@ -22,10 +22,8 @@ public ResponseEntity getAppearance( @PositiveOrZero @RequestParam(defaultValue = "0") int page, @PositiveOrZero @RequestParam(defaultValue = "10") int size, @RequestParam(value = "actor") String actor - ){ AppearancePageResponse response = appearanceService.getAppearanceByName(actor, PageRequest.of(page, size)); return ResponseEntity.ok(response); } - } diff --git a/customer-service/src/main/java/com/example/customerservice/contents/controller/ContentsScheduleController.java b/customer-service/src/main/java/com/example/customerservice/contents/controller/ContentsScheduleController.java index 299726f..196c3ed 100644 --- a/customer-service/src/main/java/com/example/customerservice/contents/controller/ContentsScheduleController.java +++ b/customer-service/src/main/java/com/example/customerservice/contents/controller/ContentsScheduleController.java @@ -2,6 +2,11 @@ import com.example.customerservice.contents.entity.SchedulerStatus; import com.example.customerservice.contents.service.ContentsSchedulerService; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.ExampleObject; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.DeleteMapping; @@ -12,11 +17,31 @@ @RestController @RequiredArgsConstructor -@RequestMapping("/api/task") +@RequestMapping("/api/book") public class ContentsScheduleController { private final ContentsSchedulerService contentsSchedulerService; - @PostMapping("/new-book") + @Operation( + summary = "도서 동기화 작업 시작", + description = "도서 업데이트 작업을 예약합니다. 매주 수요일에 실행됩니다.", + responses = { + @ApiResponse( + responseCode = "200", + description = "작업이 예약되었습니다.", + content = @Content( + examples = @ExampleObject(value = "도서 업데이트 작업이 매주 수요일마다 실행되도록 예약되었습니다.") + ) + ), + @ApiResponse( + responseCode = "400", + description = "이미 작업이 실행 중입니다.", + content = @Content( + examples = @ExampleObject(value = "업데이트 작업이 이미 실행 중입니다.") + ) + ) + } + ) + @PostMapping("/start") public ResponseEntity startBookSync() { SchedulerStatus status = contentsSchedulerService.startBookSync(50); @@ -30,7 +55,28 @@ public ResponseEntity startBookSync() { } } - @DeleteMapping("/new-book") + + @Operation( + summary = "도서 동기화 작업 중지", + description = "현재 실행 중인 도서 업데이트 작업을 중지합니다.", + responses = { + @ApiResponse( + responseCode = "200", + description = "작업이 중지되었습니다.", + content = @Content( + examples = @ExampleObject(value = "도서 업데이트 작업이 중지되었습니다.") + ) + ), + @ApiResponse( + responseCode = "400", + description = "중지할 작업이 없습니다.", + content = @Content( + examples = @ExampleObject(value = "현재 실행 중인 업데이트 작업이 없습니다.") + ) + ) + } + ) + @DeleteMapping("/stop") public ResponseEntity stopBookSync() { SchedulerStatus status = contentsSchedulerService.stopBookSync(); @@ -43,4 +89,26 @@ public ResponseEntity stopBookSync() { throw new IllegalStateException("Unexpected status: " + status); } } + @Operation( + summary = "최초 도서 데이터 저장", + description = "최신 도서 100권의 데이터를 동기화합니다.", + responses = { + @ApiResponse( + responseCode = "200", + description = "도서 데이터 로드 완료", + content = @Content( + examples = @ExampleObject(value = "최신 도서 100권 로드 완료되었습니다.") + ) + ), + @ApiResponse( + responseCode = "500", + description = "서버 에러" + ) + } + ) + @PostMapping("/first/book") + public ResponseEntity saveBooksFirstData() throws JsonProcessingException { + contentsSchedulerService.saveNewBookWithLimit100(); + return ResponseEntity.ok("최신 도서 100권 로드 완료되었습니다."); + } } diff --git a/customer-service/src/main/java/com/example/customerservice/contents/service/ContentsSchedulerService.java b/customer-service/src/main/java/com/example/customerservice/contents/service/ContentsSchedulerService.java index 0bba7b5..bdecff2 100644 --- a/customer-service/src/main/java/com/example/customerservice/contents/service/ContentsSchedulerService.java +++ b/customer-service/src/main/java/com/example/customerservice/contents/service/ContentsSchedulerService.java @@ -58,6 +58,20 @@ public void fetchBooksForAllPages(int maxResults) throws JsonProcessingException System.out.println("Execution time: " + timeElapsed.toSeconds() + " seconds"); } + public void saveNewBookWithLimit100() throws JsonProcessingException { + int totalPages = 2; + int maxResults = 50; + ObjectMapper objectMapper = new ObjectMapper(); + + for (int page = 1; page <= totalPages; page++) { + String pageResponse = bookApiClient.fetchBooksByPage(page, maxResults); + JsonNode items = objectMapper.readTree(pageResponse).path("item"); + + List contentsList = AladinUtils.parseContentsData(items, "Book"); + saveContentsToDatabase(contentsList); + } + } + void saveContentsToDatabase(List contentsList) { List existingTitlesAndWriters = contentsRepository.findAllTitlesAndWriters();