diff --git a/wxdata/include/scwx/types/iem_types.hpp b/wxdata/include/scwx/types/iem_types.hpp new file mode 100644 index 00000000..ee461c36 --- /dev/null +++ b/wxdata/include/scwx/types/iem_types.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include +#include + +#include + +namespace scwx::types::iem +{ + +/** + * @brief AFOS Entry object + * + * + */ +struct AfosEntry +{ + std::int64_t index_ {}; + std::string entered_ {}; + std::string pil_ {}; + std::string productId_ {}; + std::string cccc_ {}; + std::int64_t count_ {}; + std::string link_ {}; + std::string textLink_ {}; +}; + +/** + * @brief AFOS List object + * + * + */ +struct AfosList +{ + std::vector data_ {}; +}; + +/** + * @brief Bad Request (400) object + */ +struct BadRequest +{ + std::string detail_ {}; +}; + +/** + * @brief Validation Error (422) object + */ +struct ValidationError +{ + struct Detail + { + std::string type_ {}; + std::vector> loc_ {}; + std::string msg_ {}; + std::string input_ {}; + struct Context + { + std::string error_ {}; + } ctx_; + }; + + std::vector detail_ {}; +}; + +AfosList tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv); +BadRequest tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv); +ValidationError tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv); + +} // namespace scwx::types::iem diff --git a/wxdata/source/scwx/types/iem_types.cpp b/wxdata/source/scwx/types/iem_types.cpp new file mode 100644 index 00000000..c1921ede --- /dev/null +++ b/wxdata/source/scwx/types/iem_types.cpp @@ -0,0 +1,103 @@ +#include + +#include + +namespace scwx::types::iem +{ + +AfosEntry tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + AfosEntry entry {}; + + // Required parameters + entry.index_ = jo.at("index").as_int64(); + entry.entered_ = jo.at("entered").as_string(); + entry.pil_ = jo.at("pil").as_string(); + entry.productId_ = jo.at("product_id").as_string(); + entry.cccc_ = jo.at("cccc").as_string(); + entry.count_ = jo.at("count").as_int64(); + entry.link_ = jo.at("link").as_string(); + entry.textLink_ = jo.at("text_link").as_string(); + + return entry; +} + +AfosList tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + AfosList list {}; + + // Required parameters + list.data_ = boost::json::value_to>(jo.at("data")); + + return list; +} + +BadRequest tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + BadRequest badRequest {}; + + // Required parameters + badRequest.detail_ = jo.at("detail").as_string(); + + return badRequest; +} + +ValidationError::Detail::Context +tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + ValidationError::Detail::Context ctx {}; + + // Required parameters + ctx.error_ = jo.at("error").as_string(); + + return ctx; +} + +ValidationError::Detail +tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + ValidationError::Detail detail {}; + + // Required parameters + detail.type_ = jo.at("type").as_string(); + detail.loc_ = boost::json::value_to< + std::vector>>(jo.at("loc")); + detail.msg_ = jo.at("msg").as_string(); + detail.input_ = jo.at("input").as_string(); + + detail.ctx_ = + boost::json::value_to(jo.at("ctx")); + + return detail; +} + +ValidationError tag_invoke(boost::json::value_to_tag, + const boost::json::value& jv) +{ + auto& jo = jv.as_object(); + + ValidationError error {}; + + // Required parameters + error.detail_ = boost::json::value_to>( + jo.at("detail")); + + return error; +} + +} // namespace scwx::types::iem diff --git a/wxdata/wxdata.cmake b/wxdata/wxdata.cmake index 4b08ad19..92de3bf0 100644 --- a/wxdata/wxdata.cmake +++ b/wxdata/wxdata.cmake @@ -72,6 +72,8 @@ set(SRC_PROVIDER source/scwx/provider/aws_level2_data_provider.cpp source/scwx/provider/nexrad_data_provider.cpp source/scwx/provider/nexrad_data_provider_factory.cpp source/scwx/provider/warnings_provider.cpp) +set(HDR_TYPES include/scwx/types/iem_types.hpp) +set(SRC_TYPES source/scwx/types/iem_types.cpp) set(HDR_UTIL include/scwx/util/digest.hpp include/scwx/util/enum.hpp include/scwx/util/environment.hpp @@ -228,6 +230,8 @@ add_library(wxdata OBJECT ${HDR_AWIPS} ${SRC_NETWORK} ${HDR_PROVIDER} ${SRC_PROVIDER} + ${HDR_TYPES} + ${SRC_TYPES} ${HDR_UTIL} ${SRC_UTIL} ${HDR_WSR88D} @@ -248,6 +252,8 @@ source_group("Header Files\\network" FILES ${HDR_NETWORK}) source_group("Source Files\\network" FILES ${SRC_NETWORK}) source_group("Header Files\\provider" FILES ${HDR_PROVIDER}) source_group("Source Files\\provider" FILES ${SRC_PROVIDER}) +source_group("Header Files\\types" FILES ${HDR_TYPES}) +source_group("Source Files\\types" FILES ${SRC_TYPES}) source_group("Header Files\\util" FILES ${HDR_UTIL}) source_group("Source Files\\util" FILES ${SRC_UTIL}) source_group("Header Files\\wsr88d" FILES ${HDR_WSR88D})