summaryrefslogtreecommitdiffstats
path: root/server/src/problem.cpp
blob: 3608f38b38aa53085209e89f18ee4d5f6666b631 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module;

#include <boost/beast/http/message.hpp>
#include <boost/json.hpp>
#include <boost/locale/message.hpp>

module routemon:problem$impl;

import :problem;

namespace routemon::problem {

auto details::set_detail(blocale::message detail) -> details&
{
  this->detail = detail;
  return *this;
}

auto details::set_instance(std::string&& instance) -> details&
{
  this->instance = instance;
  return *this;
}

auto details::set_instance(std::string_view instance) -> details&
{
  this->instance = std::string{instance};
  return *this;
}

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<unsigned>(details.status)},
  };
  if (details.detail)
    obj["detail"] = details.detail->str(locale);
  if (details.instance)
    obj["instance"] = *details.instance;
  jv = obj;
}

auto tpl::instantiate() const -> details
{
  return details{status, title, type_uri};
}

} // namespace routemon::problem