diff options
| author | Rutger Broekhoff | 2026-11-30 11:47:36 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2026-11-30 11:47:36 +0100 |
| commit | 02475e05ccd1aa15c6a6163834f28bfebbef796f (patch) | |
| tree | 6bc6f453f07dc76f763310e1e5eade9a3e1115b7 /server/src/database.cppm | |
| parent | 5732f6c14618f50ffaf315b93795340219a67c66 (diff) | |
| download | routemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.tar.gz routemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.zip | |
RWGPS webhook and such
Diffstat (limited to 'server/src/database.cppm')
| -rw-r--r-- | server/src/database.cppm | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/server/src/database.cppm b/server/src/database.cppm index ff5cae4..83616d2 100644 --- a/server/src/database.cppm +++ b/server/src/database.cppm | |||
| @@ -2,21 +2,79 @@ export module routemon:database; | |||
| 2 | 2 | ||
| 3 | import std; | 3 | import std; |
| 4 | import :sqlite3; | 4 | import :sqlite3; |
| 5 | import :time; | ||
| 5 | 6 | ||
| 6 | namespace routemon::database { | 7 | namespace routemon::database { |
| 7 | 8 | ||
| 9 | namespace schema { | ||
| 10 | |||
| 11 | enum class rwgps_notification_cause | ||
| 12 | { | ||
| 13 | unknown, | ||
| 14 | created, | ||
| 15 | updated, | ||
| 16 | deleted, | ||
| 17 | added, | ||
| 18 | removed, | ||
| 19 | }; | ||
| 20 | |||
| 21 | enum class rwgps_notification_item_type | ||
| 22 | { | ||
| 23 | unknown, | ||
| 24 | trip, | ||
| 25 | route, | ||
| 26 | event, | ||
| 27 | event_participant, | ||
| 28 | club_member, | ||
| 29 | authorization, | ||
| 30 | }; | ||
| 31 | |||
| 32 | enum rwgps_notification_target_collection_type | ||
| 33 | { | ||
| 34 | unknown, | ||
| 35 | pinned, | ||
| 36 | }; | ||
| 37 | |||
| 38 | struct rwgps_notification_target_collection | ||
| 39 | { | ||
| 40 | std::int64_t notification_id = 0; | ||
| 41 | std::int64_t id; | ||
| 42 | rwgps_notification_target_collection_type type; | ||
| 43 | std::optional<std::string> url; | ||
| 44 | }; | ||
| 45 | |||
| 46 | struct rwgps_notification | ||
| 47 | { | ||
| 48 | std::int64_t id = 0; | ||
| 49 | time::timestamp<std::chrono::seconds> rwgps_timestamp; | ||
| 50 | // User that took the action | ||
| 51 | std::int64_t user_id; | ||
| 52 | rwgps_notification_item_type item_type; | ||
| 53 | std::optional<std::int64_t> item_id; | ||
| 54 | // User that owns the item | ||
| 55 | std::optional<std::int64_t> item_user_id; | ||
| 56 | std::optional<std::string> item_url; | ||
| 57 | rwgps_notification_cause action; | ||
| 58 | }; | ||
| 59 | |||
| 60 | } // namespace schema | ||
| 61 | |||
| 8 | export class connection | 62 | export class connection |
| 9 | { | 63 | { |
| 10 | sqlite3::connection dbc_; | 64 | sqlite3::connection dbc_; |
| 11 | 65 | ||
| 12 | explicit connection(sqlite3::connection dbc) : dbc_{std::move(dbc)} {} | 66 | explicit connection(sqlite3::connection dbc) : dbc_{std::move(dbc)} {} |
| 13 | 67 | ||
| 14 | friend auto open(std::string const& filename) -> std::shared_ptr<connection>; | 68 | friend auto open(util::zstring_view filename) -> std::shared_ptr<connection>; |
| 15 | 69 | ||
| 16 | public: | 70 | public: |
| 17 | // Nothing here yet | 71 | auto insert_rwgps_notifications( |
| 72 | std::vector<std::pair< | ||
| 73 | schema::rwgps_notification, | ||
| 74 | std::optional<schema::rwgps_notification_target_collection> | ||
| 75 | >>& notifs) -> void; | ||
| 18 | }; | 76 | }; |
| 19 | 77 | ||
| 20 | export auto open(std::string const& filename) -> std::shared_ptr<connection>; | 78 | export auto open(util::zstring_view filename) -> std::shared_ptr<connection>; |
| 21 | 79 | ||
| 22 | } // namespace routemon::database | 80 | } // namespace routemon::database |