summaryrefslogtreecommitdiffstats
path: root/server/src/rwgps.cppm
blob: 880ea3ae143d98000bec230706e042be3dc71f1d (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module;

#include <boost/asio/io_context.hpp>
#include <boost/json/conversion.hpp>

export module routemon:rwgps;

import std;
import :http.client;
import :log;

namespace net = boost::asio;
namespace json = boost::json;

namespace routemon::rwgps {

export struct route_summary
{
  std::int64_t id;
  std::int64_t user_id;
  std::string url;
  std::string name;
  std::string description;
};

enum class notification_cause
{
  unknown,
  created,
  updated,
  deleted,
  added,
  removed,
};

enum class notification_item_type
{
  unknown,
  trip,
  route,
  event,
  event_participant,
  club_member,
  authorization,
};

enum notification_target_collection_type
{
  unknown,
  pinned,
};

struct notification_target_collection
{
  std::int64_t id;
  notification_target_collection_type type;
  std::optional<std::string> url;
};

struct notification
{
  // User that took the action
  std::int64_t user_id;
  notification_item_type item_type;
  std::optional<std::int64_t> item_id;
  // User that owns the item
  std::optional<std::int64_t> item_user_id;
  std::optional<std::string> item_url;
  notification_cause action;
  std::optional<notification_target_collection> collection;
};

struct webhook_request
{
  std::vector<notification> notifications = {};
};

auto tag_invoke(
    json::value_to_tag<webhook_request> const&, json::value const& jv)
    -> webhook_request;

struct pagination
{
  std::size_t record_count;
  std::size_t page_count;
  std::size_t page_size;
  std::optional<std::string> next_page_url;
};

struct get_routes_meta
{
  pagination pagination;
};

struct get_routes_response
{
  std::vector<route_summary> routes;
  get_routes_meta meta;
};

export class credentials
{
  std::string api_key_;
  std::string api_secret_;
  std::string auth_token_;

public:
  credentials(
      std::string&& api_key, std::string&& api_secret,
      std::string&& auth_token);
  ~credentials();

  auto api_key() const -> std::string const&;
  auto api_secret() const -> std::string const&;
  auto auth_token() const -> std::string const&;
};

export class client
{
  log::logger l_;
  http::client hc_;
  std::shared_ptr<credentials> creds_;

  auto get_routes_page(std::size_t page) -> get_routes_response;

public:
  explicit client(
      net::io_context& ioc, log::logger const& l,
      std::shared_ptr<credentials> creds);

  auto get_all_routes() -> std::vector<route_summary>;
};

} // namespace routemon::rwgps