Skip to content

Commit

Permalink
Feat: 알라딘 api 조회에서 한 페이지당 최대 책 수 조절 기능 추가 (#86)
Browse files Browse the repository at this point in the history
* #85 - feat: MaxResults 기능 구현

* #85 - test: MaxResults 기능 테스트 작성
  • Loading branch information
GGHDMS authored Feb 8, 2024
1 parent fc47f5a commit febcb42
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public class BookController {
@GetMapping("/search")
public ResponseEntity<BookApiListResponse> searchExternal(
@RequestParam String keyword,
@RequestParam Integer start) {
return ResponseEntity.ok(bookService.searchExternal(keyword, start));
@RequestParam int start,
@RequestParam(name = "max-results", defaultValue = "5") int maxResults
) {
return ResponseEntity.ok(bookService.searchExternal(keyword, start, maxResults));
}

@GetMapping("/external")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface AladinComponent {

@GetExchange("/ItemSearch.aspx")
String findAllByQuery(@RequestParam String TTBKey, @RequestParam String Query, @RequestParam String Output, @RequestParam int Start, @RequestParam int Version);
String findAllByQuery(@RequestParam String TTBKey, @RequestParam String Query, @RequestParam String Output, @RequestParam int Start, @RequestParam int MaxResults, @RequestParam int Version);

@GetExchange("/ItemLookUp.aspx")
String findByIsbn13(@RequestParam String TTBKey, @RequestParam String ItemId, @RequestParam String ItemIdType, @RequestParam String Output, @RequestParam int Version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class BookApiComponent {
private final AladinComponent aladinComponent;
private final BookApiCacheService bookApiCacheService;

public BookApiListResponse findListByKeyWordAndApi(String keyword, int start) {
JSONObject json = new JSONObject(aladinComponent.findAllByQuery(aladinKey, keyword, "JS", start, 20131101));
public BookApiListResponse findListByKeyWordAndApi(String keyword, int start, int maxResults) {
JSONObject json = new JSONObject(aladinComponent.findAllByQuery(aladinKey, keyword, "JS", start, maxResults, 20131101));

int totalResults = json.getInt("totalResults");
int startIndex = json.getInt("startIndex");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cotato/bookitlist/book/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class BookService {
private final BookApiCacheService bookApiCacheService;
private final BookRepository bookRepository;

public BookApiListResponse searchExternal(String keyword, int start) {
return bookApiComponent.findListByKeyWordAndApi(keyword, start);
public BookApiListResponse searchExternal(String keyword, int start, int maxResults) {
return bookApiComponent.findListByKeyWordAndApi(keyword, start, maxResults);
}

public BookApiDto getExternal(String isbn13) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,27 @@ void givenKeyword_whenSearching_thenReturnBookApiResponse() throws Exception {
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalResults").exists())
.andExpect(jsonPath("$.startIndex").exists())
.andExpect(jsonPath("$.itemsPerPage").exists())
.andExpect(jsonPath("$.itemsPerPage").value(5))
.andExpect(jsonPath("$.bookApiList").exists())
;
}

@Test
@DisplayName("[Api] MaxResults가 주어지면 그 수 만큼 응답을 준다.")
void givenMaxResults_whenSearching_thenReturnBookApiResponse() throws Exception {
//given
String keyword = "aladdin";

//when&then
mockMvc.perform(get("/books/search")
.param("keyword", keyword)
.param("start", "1")
.param("max-results", "10")
)
.andExpect(status().isOk())
.andExpect(jsonPath("$.totalResults").exists())
.andExpect(jsonPath("$.startIndex").exists())
.andExpect(jsonPath("$.itemsPerPage").value(10))
.andExpect(jsonPath("$.bookApiList").exists())
;
}
Expand Down

0 comments on commit febcb42

Please sign in to comment.