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 @@ -13,7 +13,7 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/appearance")
@RequestMapping("/api/movie/appearance")
public class AppearanceController {
private final AppearanceService appearanceService;

Expand All @@ -22,10 +22,8 @@ public ResponseEntity<AppearancePageResponse> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> startBookSync() {
SchedulerStatus status = contentsSchedulerService.startBookSync(50);

Expand All @@ -30,7 +55,28 @@ public ResponseEntity<String> 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<String> stopBookSync() {
SchedulerStatus status = contentsSchedulerService.stopBookSync();

Expand All @@ -43,4 +89,26 @@ public ResponseEntity<String> 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<String> saveBooksFirstData() throws JsonProcessingException {
contentsSchedulerService.saveNewBookWithLimit100();
return ResponseEntity.ok("최신 도서 100권 로드 완료되었습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Contents> contentsList = AladinUtils.parseContentsData(items, "Book");
saveContentsToDatabase(contentsList);
}
}

void saveContentsToDatabase(List<Contents> contentsList) {
List<String> existingTitlesAndWriters = contentsRepository.findAllTitlesAndWriters();

Expand Down
Loading