From 973aec43ea54bbf95b64fbcb636403401d1ca60e Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 28 Aug 2026 18:03:05 +0200 Subject: Import from e4b104792206ee7ea64bf39c6b7d2c0c230f9d14 --- server/src/problem.cppm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 server/src/problem.cppm (limited to 'server/src/problem.cppm') diff --git a/server/src/problem.cppm b/server/src/problem.cppm new file mode 100644 index 0000000..8764962 --- /dev/null +++ b/server/src/problem.cppm @@ -0,0 +1,60 @@ +module; + +#include +#include +#include + +export module routemon:problem; + +import std; +import :locale; + +namespace http = boost::beast::http; +namespace json = boost::json; + +namespace routemon::problem { + + export struct details { + http::status status; + blocale::message title; + std::string_view type_uri; + std::optional detail = std::nullopt; + std::optional instance = std::nullopt; + + auto set_detail(blocale::message detail) -> details& { + this->detail = detail; + return *this; + } + + auto set_instance(std::string&& instance) -> details& { + this->instance = instance; + return *this; + } + auto set_instance(std::string_view instance) -> details& { + this->instance = std::string{instance}; + return *this; + } + }; + + export auto tag_invoke(json::value_from_tag, json::value& jv, details const& details, std::locale locale) -> void { + auto obj = json::object{ + {"type", details.type_uri}, + {"title", details.title.str(locale)}, + {"status", static_cast(details.status)}, + }; + if (details.detail) obj["detail"] = details.detail->str(locale); + if (details.instance) obj["instance"] = *details.instance; + jv = obj; + } + + export struct tpl { + http::status status; + blocale::message title; + std::string_view type_uri; + + auto instantiate() const -> details { + return details{status, title, type_uri}; + } + }; + +} -- cgit v1.3