Skip to content

Commit

Permalink
MSEARCH-794: refactor inventory clients
Browse files Browse the repository at this point in the history
  • Loading branch information
mukhiddin-yusuf committed Aug 16, 2024
1 parent bc63276 commit 1a4321f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;

import org.folio.search.model.client.CqlQuery;
import org.folio.search.model.service.ResultList;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -16,13 +15,13 @@ public interface InventoryHoldingClient {
path = "/holdings",
consumes = APPLICATION_OCTET_STREAM_VALUE,
produces = APPLICATION_JSON_VALUE)
ResultList<InventoryHoldingDto> getHoldings(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);
InventoryRecordDtoCollection<InventoryHoldingDto> getHoldings(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);

@GetMapping(path = "/holdings", produces = APPLICATION_JSON_VALUE)
ResultList<InventoryHoldingDto> getHoldings(@RequestParam("limit") int limit,
@RequestParam("totalRecords") TotalRecordsType totalRecordsType);
InventoryRecordDtoCollection<InventoryHoldingDto> getHoldings(
@RequestParam("limit") int limit, @RequestParam("totalRecords") TotalRecordsType totalRecordsType);

record InventoryHoldingDto(String id) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;

import org.folio.search.model.client.CqlQuery;
import org.folio.search.model.service.ResultList;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -13,16 +12,16 @@
public interface InventoryInstanceClient {

@GetMapping(
path = "/instances",
path = "/records",
consumes = APPLICATION_OCTET_STREAM_VALUE,
produces = APPLICATION_JSON_VALUE)
ResultList<InventoryInstanceDto> getInstances(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);
InventoryRecordDtoCollection<InventoryInstanceDto> getInstances(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);

@GetMapping(path = "/instances", produces = APPLICATION_JSON_VALUE)
ResultList<InventoryInstanceDto> getInstances(@RequestParam("limit") int limit,
@RequestParam("totalRecords") TotalRecordsType totalRecordsType);
@GetMapping(path = "/records", produces = APPLICATION_JSON_VALUE)
InventoryRecordDtoCollection<InventoryInstanceDto> getInstances(
@RequestParam("limit") int limit, @RequestParam("totalRecords") TotalRecordsType totalRecordsType);

record InventoryInstanceDto(String id) {}
}
11 changes: 5 additions & 6 deletions src/main/java/org/folio/search/client/InventoryItemClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE;

import org.folio.search.model.client.CqlQuery;
import org.folio.search.model.service.ResultList;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -16,13 +15,13 @@ public interface InventoryItemClient {
path = "/items",
consumes = APPLICATION_OCTET_STREAM_VALUE,
produces = APPLICATION_JSON_VALUE)
ResultList<InventoryItemDto> getItems(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);
InventoryRecordDtoCollection<InventoryItemDto> getItems(@RequestParam("query") CqlQuery cql,
@RequestParam("offset") int offset,
@RequestParam("limit") int limit);

@GetMapping(path = "/items", produces = APPLICATION_JSON_VALUE)
ResultList<InventoryItemDto> getItems(@RequestParam("limit") int limit,
@RequestParam("totalRecords") TotalRecordsType totalRecordsType);
InventoryRecordDtoCollection<InventoryItemDto> getItems(
@RequestParam("limit") int limit, @RequestParam("totalRecords") TotalRecordsType totalRecordsType);

record InventoryItemDto(String id) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.folio.search.client;

import java.util.List;

public record InventoryRecordDtoCollection<T>(List<T> records, int totalRecords) {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface InventoryViewClient {
* @param limit - limit of resources to fetch
* @return {@link ResultList} with Instance objects inside.
*/
@GetMapping(path = "/instances", consumes = APPLICATION_OCTET_STREAM_VALUE)
@GetMapping(path = "/records", consumes = APPLICATION_OCTET_STREAM_VALUE)
ResultList<InstanceView> getInstances(@RequestParam("query") CqlQuery cql, @RequestParam("limit") int limit);

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public int fetchInventoryRecordCount(InventoryRecordType recordType) {
return 0;
}

return result.getTotalRecords();
return result.totalRecords();
} catch (Exception e) {
log.warn("Failed to fetch Inventory record counts for {}", recordType);
throw new FolioIntegrationException(
Expand Down Expand Up @@ -109,7 +109,7 @@ private List<UUID> fetchInstances(CqlQuery cqlQuery, int offset, int limit) {
return Collections.emptyList();
}

return result.getResult().stream()
return result.records().stream()
.map(InventoryInstanceClient.InventoryInstanceDto::id)
.map(UUID::fromString)
.toList();
Expand All @@ -123,7 +123,7 @@ private List<UUID> fetchItems(CqlQuery cqlQuery, int offset, int limit) {
return Collections.emptyList();
}

return result.getResult().stream()
return result.records().stream()
.map(InventoryItemClient.InventoryItemDto::id)
.map(UUID::fromString)
.toList();
Expand All @@ -137,7 +137,7 @@ private List<UUID> fetchHoldings(CqlQuery cqlQuery, int offset, int limit) {
return Collections.emptyList();
}

return result.getResult().stream()
return result.records().stream()
.map(InventoryHoldingClient.InventoryHoldingDto::id)
.map(UUID::fromString)
.toList();
Expand Down

0 comments on commit 1a4321f

Please sign in to comment.