diff options
Diffstat (limited to 'server/src/problem.cpp')
| -rw-r--r-- | server/src/problem.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/src/problem.cpp b/server/src/problem.cpp new file mode 100644 index 0000000..3608f38 --- /dev/null +++ b/server/src/problem.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | module; | ||
| 2 | |||
| 3 | #include <boost/beast/http/message.hpp> | ||
| 4 | #include <boost/json.hpp> | ||
| 5 | #include <boost/locale/message.hpp> | ||
| 6 | |||
| 7 | module routemon:problem$impl; | ||
| 8 | |||
| 9 | import :problem; | ||
| 10 | |||
| 11 | namespace routemon::problem { | ||
| 12 | |||
| 13 | auto details::set_detail(blocale::message detail) -> details& | ||
| 14 | { | ||
| 15 | this->detail = detail; | ||
| 16 | return *this; | ||
| 17 | } | ||
| 18 | |||
| 19 | auto details::set_instance(std::string&& instance) -> details& | ||
| 20 | { | ||
| 21 | this->instance = instance; | ||
| 22 | return *this; | ||
| 23 | } | ||
| 24 | |||
| 25 | auto details::set_instance(std::string_view instance) -> details& | ||
| 26 | { | ||
| 27 | this->instance = std::string{instance}; | ||
| 28 | return *this; | ||
| 29 | } | ||
| 30 | |||
| 31 | auto tag_invoke( | ||
| 32 | json::value_from_tag, json::value& jv, details const& details, | ||
| 33 | std::locale locale) -> void | ||
| 34 | { | ||
| 35 | auto obj = json::object{ | ||
| 36 | {"type", details.type_uri}, | ||
| 37 | {"title", details.title.str(locale)}, | ||
| 38 | {"status", static_cast<unsigned>(details.status)}, | ||
| 39 | }; | ||
| 40 | if (details.detail) | ||
| 41 | obj["detail"] = details.detail->str(locale); | ||
| 42 | if (details.instance) | ||
| 43 | obj["instance"] = *details.instance; | ||
| 44 | jv = obj; | ||
| 45 | } | ||
| 46 | |||
| 47 | auto tpl::instantiate() const -> details | ||
| 48 | { | ||
| 49 | return details{status, title, type_uri}; | ||
| 50 | } | ||
| 51 | |||
| 52 | } // namespace routemon::problem | ||