Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add synchronous GetLatestVersion method. #1315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -159,6 +159,19 @@ class DATASERVICE_READ_API CatalogClient final {
client::CancellableFuture<CatalogVersionResponse> GetLatestVersion(
CatalogVersionRequest request);

/**
* @brief Gets the catalog version synchronously.
*
* @param request The `CatalogVersionRequest` instance that contains
* a complete set of request parameters.
* @param context The `CancellationContext` instance.
*
* @return `CatalogVersionResponse` instance with the catalog configuration or
* an error
*/
CatalogVersionResponse GetLatestVersion(CatalogVersionRequest request,
client::CancellationContext context);

/**
* @brief Gets the catalog versions list.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@ class DATASERVICE_READ_API VersionsRequest final {
return *this;
}

/**
* @brief Gets the fetch option that controls how requests are handled.
*
* The default option is `OnlineIfNotFound` that queries the network if
* the requested resource is not in the cache.
*
* @return The fetch option.
*/
inline FetchOptions GetFetchOption() const { return fetch_option_; }

/**
* @brief Sets the fetch option that you can use to set the source from
* which data should be fetched.
*
* @see `GetFetchOption()` for information on usage and format.
*
* @param fetch_option The `FetchOption` enum.
*
* @return A reference to the updated `VersionsRequest` instance.
*/
inline VersionsRequest& WithFetchOption(FetchOptions fetch_option) {
fetch_option_ = fetch_option;
return *this;
}

/**
* @brief Creates a readable format for the request.
*
Expand All @@ -156,6 +181,7 @@ class DATASERVICE_READ_API VersionsRequest final {
std::int64_t start_version_;
std::int64_t end_version_;
boost::optional<std::string> billing_tag_;
FetchOptions fetch_option_{OnlineIfNotFound};
};

} // namespace read
Expand Down
5 changes: 5 additions & 0 deletions olp-cpp-sdk-dataservice-read/src/CatalogClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ CatalogClient::GetLatestVersion(CatalogVersionRequest request) {
return impl_->GetLatestVersion(std::move(request));
}

CatalogVersionResponse CatalogClient::GetLatestVersion(
CatalogVersionRequest request, client::CancellationContext context) {
return impl_->GetLatestVersion(std::move(request), std::move(context));
}

client::CancellationToken CatalogClient::ListVersions(
VersionsRequest request, VersionsResponseCallback callback) {
return impl_->ListVersions(std::move(request), std::move(callback));
Expand Down
10 changes: 10 additions & 0 deletions olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ CatalogClientImpl::GetLatestVersion(CatalogVersionRequest request) {
std::move(cancel_token), std::move(promise));
}

CatalogVersionResponse CatalogClientImpl::GetLatestVersion(
CatalogVersionRequest request, client::CancellationContext context) {
auto catalog = catalog_;
auto settings = settings_;
auto lookup_client = lookup_client_;

repository::CatalogRepository repository(catalog, settings, lookup_client);
return repository.GetLatestVersion(request, std::move(context));
}

client::CancellationToken CatalogClientImpl::ListVersions(
VersionsRequest request, VersionsResponseCallback callback) {
auto catalog = catalog_;
Expand Down
3 changes: 3 additions & 0 deletions olp-cpp-sdk-dataservice-read/src/CatalogClientImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class CatalogClientImpl final {
client::CancellableFuture<CatalogVersionResponse> GetLatestVersion(
CatalogVersionRequest request);

CatalogVersionResponse GetLatestVersion(CatalogVersionRequest request,
client::CancellationContext context);

client::CancellationToken ListVersions(VersionsRequest request,
VersionsResponseCallback callback);

Expand Down