blob: b7a424a16947e435802b0f2dc32ebed05ef81c65 [file] [edit]
#ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_
#define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_
#include <cstdint>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "boost/url/params_view.hpp"
#include <nlohmann/json.hpp>
namespace milotic_tlbmc {
struct ExpandNode {
nlohmann::json::json_pointer json_pointer;
std::string url;
std::string DebugString() const {
return absl::StrCat(json_pointer.to_string(), ":", url);
}
bool operator==(const ExpandNode& other) const {
return json_pointer == other.json_pointer && url == other.url;
}
};
enum class ExpandType : std::uint8_t {
kNone = 0,
kNoLinks,
kLinksOnly,
kAll,
};
struct ExpandInfo {
int expand_level = 0;
ExpandType expand_type = ExpandType::kNone;
};
std::string ExpandTypeToUrlParam(ExpandType expand_type);
class QueryParameters {
public:
QueryParameters() = default;
static absl::StatusOr<QueryParameters> Create(
boost::urls::params_view query_parameters);
void SetExpandLevel(int expand_level) {
expand_info_.expand_level = expand_level;
}
void SetExpandType(ExpandType expand_type) {
expand_info_.expand_type = expand_type;
}
int GetExpandLevel() const { return expand_info_.expand_level; }
ExpandType GetExpandType() const { return expand_info_.expand_type; }
void SetTop(int top) { top_ = top; }
std::optional<int> GetTop() const { return top_; }
void SetFilter(std::optional<std::string> filter) {
filter_ = std::move(filter);
}
std::optional<std::string> GetFilter() const { return filter_; }
private:
ExpandInfo expand_info_;
std::optional<int> top_;
std::optional<std::string> filter_;
};
// Helper method to extract all unexpanded URLs from a RedfishResponse Json.
std::vector<ExpandNode> GetUnexpandedUrls(const nlohmann::json& resp,
ExpandType expand_type);
} // namespace milotic_tlbmc
#endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_REDFISH_QUERY_PARAMETERS_H_