summaryrefslogtreecommitdiffstats
path: root/server/src/database.cppm
blob: 83616d2059c3f75a03284cdcd9383f488b753618 (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
export module routemon:database;

import std;
import :sqlite3;
import :time;

namespace routemon::database {

namespace schema {

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

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

enum rwgps_notification_target_collection_type
{
  unknown,
  pinned,
};

struct rwgps_notification_target_collection
{
  std::int64_t notification_id = 0;
  std::int64_t id;
  rwgps_notification_target_collection_type type;
  std::optional<std::string> url;
};

struct rwgps_notification
{
  std::int64_t id = 0;
  time::timestamp<std::chrono::seconds> rwgps_timestamp;
  // User that took the action
  std::int64_t user_id;
  rwgps_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;
  rwgps_notification_cause action;
};

} // namespace schema

export class connection
{
  sqlite3::connection dbc_;

  explicit connection(sqlite3::connection dbc) : dbc_{std::move(dbc)} {}

  friend auto open(util::zstring_view filename) -> std::shared_ptr<connection>;

public:
  auto insert_rwgps_notifications(
      std::vector<std::pair<
          schema::rwgps_notification,
          std::optional<schema::rwgps_notification_target_collection>
      >>& notifs) -> void;
};

export auto open(util::zstring_view filename) -> std::shared_ptr<connection>;

} // namespace routemon::database