From 6eaaae37b3de0b437a2afc56d8b10db6eb8ef7b9 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:59:19 +0200 Subject: [PATCH] Rename events to calendar objects --- ...ae332f8eb18dddbd80d31989c074804f31dee.json | 12 ++++ ...fa292d8e9b7d898bbdd1169fe6d4edf1c5758.json | 12 ++++ ...35d5e2bf913c30f9f3e7bd9fecc7d4376be0f.json | 12 ++++ ...2d3fe2f87dbb09c035f9ad665a5b0f6234701.json | 12 ++++ ...f2bbcac61cee89d366aa8b0a9d535b49a3669.json | 26 +++++++ ...9ee4d782b5bf40537c4c24d9d549a48e61170.json | 12 ++++ ...d95b6bf86268b64e714fa7ca587eae9e5df15.json | 12 ++++ ...484a776e8eccb2b72a2fb2d4a5edea90067e5.json | 68 +++++++++++++++++++ ...c77bb95c1a25b6a3c0c389ef0ad4f468320ee.json | 12 ++++ ...28e6b8420f749a4071919bf2a83e26454a694.json | 26 +++++++ ...fc9279d3a5c5386922fa63361d345bd4f93cb.json | 12 ++++ ...f1d596f54d50f5421142dc02d2d7798be47e1.json | 12 ++++ ...a4af1c2f34515288bade397b87a1e43d789df.json | 12 ++++ ...d42826c8b31f06d16a09687de70a881bec57f.json | 26 +++++++ ...2bc29f66761eb52adcb16cde56d56ab5c1ecf.json | 12 ++++ ...fb3d6876598ecde4db98d7a303c9e4c676376.json | 68 +++++++++++++++++++ .../methods/report/calendar_multiget.rs | 12 ++-- .../calendar/methods/report/calendar_query.rs | 10 +-- .../methods/report/sync_collection.rs | 12 ++-- .../{20240621161002_init.sql => 1_init.sql} | 4 +- .../store/src/{store.rs => calendar_store.rs} | 0 crates/store/src/lib.rs | 5 +- crates/store/src/sqlite_store.rs | 47 +++++++------ crates/store/tests/test_calendar.rs | 2 +- 24 files changed, 394 insertions(+), 44 deletions(-) create mode 100644 .sqlx/query-02a9260d0ff496a6bf226fc8238ae332f8eb18dddbd80d31989c074804f31dee.json create mode 100644 .sqlx/query-11d6a5b6c273bb60434061846f1fa292d8e9b7d898bbdd1169fe6d4edf1c5758.json create mode 100644 .sqlx/query-2834e16e6a7acb58141a2433f7735d5e2bf913c30f9f3e7bd9fecc7d4376be0f.json create mode 100644 .sqlx/query-3f600740417b6fd02eb347c24302d3fe2f87dbb09c035f9ad665a5b0f6234701.json create mode 100644 .sqlx/query-3fb50028a203f9865d9440bfd5ef2bbcac61cee89d366aa8b0a9d535b49a3669.json create mode 100644 .sqlx/query-8992d192b42830ea5f7264abb879ee4d782b5bf40537c4c24d9d549a48e61170.json create mode 100644 .sqlx/query-a4371f228f94afd8e6f4ac4b0f7d95b6bf86268b64e714fa7ca587eae9e5df15.json create mode 100644 .sqlx/query-b66f33bc98029e9bc6427e61d15484a776e8eccb2b72a2fb2d4a5edea90067e5.json create mode 100644 .sqlx/query-c7a56d737fc8627427d0be202c3c77bb95c1a25b6a3c0c389ef0ad4f468320ee.json create mode 100644 .sqlx/query-cbfcbe0e211d6104bd0120fb0eb28e6b8420f749a4071919bf2a83e26454a694.json create mode 100644 .sqlx/query-d162556505138438dd2b8ae14fffc9279d3a5c5386922fa63361d345bd4f93cb.json create mode 100644 .sqlx/query-deeee7413b3d03d3a68709ae10bf1d596f54d50f5421142dc02d2d7798be47e1.json create mode 100644 .sqlx/query-eba774e8d8afa04d33443b42ec3a4af1c2f34515288bade397b87a1e43d789df.json create mode 100644 .sqlx/query-ec583c44374b71591c2a76881f5d42826c8b31f06d16a09687de70a881bec57f.json create mode 100644 .sqlx/query-f13006549869125c63731055d242bc29f66761eb52adcb16cde56d56ab5c1ecf.json create mode 100644 .sqlx/query-f387e6ef026d8314e78c0672652fb3d6876598ecde4db98d7a303c9e4c676376.json rename crates/store/migrations/{20240621161002_init.sql => 1_init.sql} (92%) rename crates/store/src/{store.rs => calendar_store.rs} (100%) diff --git a/.sqlx/query-02a9260d0ff496a6bf226fc8238ae332f8eb18dddbd80d31989c074804f31dee.json b/.sqlx/query-02a9260d0ff496a6bf226fc8238ae332f8eb18dddbd80d31989c074804f31dee.json new file mode 100644 index 0000000..d37f103 --- /dev/null +++ b/.sqlx/query-02a9260d0ff496a6bf226fc8238ae332f8eb18dddbd80d31989c074804f31dee.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE calendars SET deleted_at = NULL WHERE (principal, id) = (?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "02a9260d0ff496a6bf226fc8238ae332f8eb18dddbd80d31989c074804f31dee" +} diff --git a/.sqlx/query-11d6a5b6c273bb60434061846f1fa292d8e9b7d898bbdd1169fe6d4edf1c5758.json b/.sqlx/query-11d6a5b6c273bb60434061846f1fa292d8e9b7d898bbdd1169fe6d4edf1c5758.json new file mode 100644 index 0000000..c714b37 --- /dev/null +++ b/.sqlx/query-11d6a5b6c273bb60434061846f1fa292d8e9b7d898bbdd1169fe6d4edf1c5758.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "DELETE FROM calendarobjects WHERE cid = ? AND uid = ?", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "11d6a5b6c273bb60434061846f1fa292d8e9b7d898bbdd1169fe6d4edf1c5758" +} diff --git a/.sqlx/query-2834e16e6a7acb58141a2433f7735d5e2bf913c30f9f3e7bd9fecc7d4376be0f.json b/.sqlx/query-2834e16e6a7acb58141a2433f7735d5e2bf913c30f9f3e7bd9fecc7d4376be0f.json new file mode 100644 index 0000000..54384e5 --- /dev/null +++ b/.sqlx/query-2834e16e6a7acb58141a2433f7735d5e2bf913c30f9f3e7bd9fecc7d4376be0f.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "DELETE FROM calendars WHERE (principal, id) = (?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "2834e16e6a7acb58141a2433f7735d5e2bf913c30f9f3e7bd9fecc7d4376be0f" +} diff --git a/.sqlx/query-3f600740417b6fd02eb347c24302d3fe2f87dbb09c035f9ad665a5b0f6234701.json b/.sqlx/query-3f600740417b6fd02eb347c24302d3fe2f87dbb09c035f9ad665a5b0f6234701.json new file mode 100644 index 0000000..0c8bc94 --- /dev/null +++ b/.sqlx/query-3f600740417b6fd02eb347c24302d3fe2f87dbb09c035f9ad665a5b0f6234701.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "REPLACE INTO calendarobjects (principal, cid, uid, ics) VALUES (?, ?, ?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 4 + }, + "nullable": [] + }, + "hash": "3f600740417b6fd02eb347c24302d3fe2f87dbb09c035f9ad665a5b0f6234701" +} diff --git a/.sqlx/query-3fb50028a203f9865d9440bfd5ef2bbcac61cee89d366aa8b0a9d535b49a3669.json b/.sqlx/query-3fb50028a203f9865d9440bfd5ef2bbcac61cee89d366aa8b0a9d535b49a3669.json new file mode 100644 index 0000000..a63c3e8 --- /dev/null +++ b/.sqlx/query-3fb50028a203f9865d9440bfd5ef2bbcac61cee89d366aa8b0a9d535b49a3669.json @@ -0,0 +1,26 @@ +{ + "db_name": "SQLite", + "query": "SELECT uid, ics FROM calendarobjects WHERE (principal, cid, uid) = (?, ?, ?)", + "describe": { + "columns": [ + { + "name": "uid", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "ics", + "ordinal": 1, + "type_info": "Text" + } + ], + "parameters": { + "Right": 3 + }, + "nullable": [ + false, + false + ] + }, + "hash": "3fb50028a203f9865d9440bfd5ef2bbcac61cee89d366aa8b0a9d535b49a3669" +} diff --git a/.sqlx/query-8992d192b42830ea5f7264abb879ee4d782b5bf40537c4c24d9d549a48e61170.json b/.sqlx/query-8992d192b42830ea5f7264abb879ee4d782b5bf40537c4c24d9d549a48e61170.json new file mode 100644 index 0000000..982b2f3 --- /dev/null +++ b/.sqlx/query-8992d192b42830ea5f7264abb879ee4d782b5bf40537c4c24d9d549a48e61170.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "\n UPDATE calendars\n SET synctoken = synctoken + 1\n WHERE (principal, id) = (?1, ?2)", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "8992d192b42830ea5f7264abb879ee4d782b5bf40537c4c24d9d549a48e61170" +} diff --git a/.sqlx/query-a4371f228f94afd8e6f4ac4b0f7d95b6bf86268b64e714fa7ca587eae9e5df15.json b/.sqlx/query-a4371f228f94afd8e6f4ac4b0f7d95b6bf86268b64e714fa7ca587eae9e5df15.json new file mode 100644 index 0000000..1ff3ec2 --- /dev/null +++ b/.sqlx/query-a4371f228f94afd8e6f4ac4b0f7d95b6bf86268b64e714fa7ca587eae9e5df15.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE calendars SET deleted_at = datetime() WHERE (principal, id) = (?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 2 + }, + "nullable": [] + }, + "hash": "a4371f228f94afd8e6f4ac4b0f7d95b6bf86268b64e714fa7ca587eae9e5df15" +} diff --git a/.sqlx/query-b66f33bc98029e9bc6427e61d15484a776e8eccb2b72a2fb2d4a5edea90067e5.json b/.sqlx/query-b66f33bc98029e9bc6427e61d15484a776e8eccb2b72a2fb2d4a5edea90067e5.json new file mode 100644 index 0000000..4e2e95d --- /dev/null +++ b/.sqlx/query-b66f33bc98029e9bc6427e61d15484a776e8eccb2b72a2fb2d4a5edea90067e5.json @@ -0,0 +1,68 @@ +{ + "db_name": "SQLite", + "query": "SELECT principal, id, synctoken, \"order\", displayname, description, color, timezone, deleted_at\n FROM calendars\n WHERE (principal, id) = (?, ?)", + "describe": { + "columns": [ + { + "name": "principal", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "id", + "ordinal": 1, + "type_info": "Text" + }, + { + "name": "synctoken", + "ordinal": 2, + "type_info": "Integer" + }, + { + "name": "order", + "ordinal": 3, + "type_info": "Integer" + }, + { + "name": "displayname", + "ordinal": 4, + "type_info": "Text" + }, + { + "name": "description", + "ordinal": 5, + "type_info": "Text" + }, + { + "name": "color", + "ordinal": 6, + "type_info": "Text" + }, + { + "name": "timezone", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "deleted_at", + "ordinal": 8, + "type_info": "Datetime" + } + ], + "parameters": { + "Right": 2 + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + true, + false, + true + ] + }, + "hash": "b66f33bc98029e9bc6427e61d15484a776e8eccb2b72a2fb2d4a5edea90067e5" +} diff --git a/.sqlx/query-c7a56d737fc8627427d0be202c3c77bb95c1a25b6a3c0c389ef0ad4f468320ee.json b/.sqlx/query-c7a56d737fc8627427d0be202c3c77bb95c1a25b6a3c0c389ef0ad4f468320ee.json new file mode 100644 index 0000000..79cd4da --- /dev/null +++ b/.sqlx/query-c7a56d737fc8627427d0be202c3c77bb95c1a25b6a3c0c389ef0ad4f468320ee.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE calendars SET principal = ?, id = ?, displayname = ?, description = ?, \"order\" = ?, color = ?, timezone = ?\n WHERE (principal, id) = (?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 9 + }, + "nullable": [] + }, + "hash": "c7a56d737fc8627427d0be202c3c77bb95c1a25b6a3c0c389ef0ad4f468320ee" +} diff --git a/.sqlx/query-cbfcbe0e211d6104bd0120fb0eb28e6b8420f749a4071919bf2a83e26454a694.json b/.sqlx/query-cbfcbe0e211d6104bd0120fb0eb28e6b8420f749a4071919bf2a83e26454a694.json new file mode 100644 index 0000000..b36b718 --- /dev/null +++ b/.sqlx/query-cbfcbe0e211d6104bd0120fb0eb28e6b8420f749a4071919bf2a83e26454a694.json @@ -0,0 +1,26 @@ +{ + "db_name": "SQLite", + "query": "SELECT uid, ics FROM calendarobjects WHERE principal = ? AND cid = ? AND deleted_at IS NULL", + "describe": { + "columns": [ + { + "name": "uid", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "ics", + "ordinal": 1, + "type_info": "Text" + } + ], + "parameters": { + "Right": 2 + }, + "nullable": [ + false, + false + ] + }, + "hash": "cbfcbe0e211d6104bd0120fb0eb28e6b8420f749a4071919bf2a83e26454a694" +} diff --git a/.sqlx/query-d162556505138438dd2b8ae14fffc9279d3a5c5386922fa63361d345bd4f93cb.json b/.sqlx/query-d162556505138438dd2b8ae14fffc9279d3a5c5386922fa63361d345bd4f93cb.json new file mode 100644 index 0000000..4a520f4 --- /dev/null +++ b/.sqlx/query-d162556505138438dd2b8ae14fffc9279d3a5c5386922fa63361d345bd4f93cb.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE calendarobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 3 + }, + "nullable": [] + }, + "hash": "d162556505138438dd2b8ae14fffc9279d3a5c5386922fa63361d345bd4f93cb" +} diff --git a/.sqlx/query-deeee7413b3d03d3a68709ae10bf1d596f54d50f5421142dc02d2d7798be47e1.json b/.sqlx/query-deeee7413b3d03d3a68709ae10bf1d596f54d50f5421142dc02d2d7798be47e1.json new file mode 100644 index 0000000..49de9ab --- /dev/null +++ b/.sqlx/query-deeee7413b3d03d3a68709ae10bf1d596f54d50f5421142dc02d2d7798be47e1.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "UPDATE calendarobjects SET deleted_at = NULL, updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 3 + }, + "nullable": [] + }, + "hash": "deeee7413b3d03d3a68709ae10bf1d596f54d50f5421142dc02d2d7798be47e1" +} diff --git a/.sqlx/query-eba774e8d8afa04d33443b42ec3a4af1c2f34515288bade397b87a1e43d789df.json b/.sqlx/query-eba774e8d8afa04d33443b42ec3a4af1c2f34515288bade397b87a1e43d789df.json new file mode 100644 index 0000000..6b80dd3 --- /dev/null +++ b/.sqlx/query-eba774e8d8afa04d33443b42ec3a4af1c2f34515288bade397b87a1e43d789df.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "INSERT INTO calendars (principal, id, displayname, description, \"order\", color, timezone)\n VALUES (?, ?, ?, ?, ?, ?, ?)", + "describe": { + "columns": [], + "parameters": { + "Right": 7 + }, + "nullable": [] + }, + "hash": "eba774e8d8afa04d33443b42ec3a4af1c2f34515288bade397b87a1e43d789df" +} diff --git a/.sqlx/query-ec583c44374b71591c2a76881f5d42826c8b31f06d16a09687de70a881bec57f.json b/.sqlx/query-ec583c44374b71591c2a76881f5d42826c8b31f06d16a09687de70a881bec57f.json new file mode 100644 index 0000000..9675c5f --- /dev/null +++ b/.sqlx/query-ec583c44374b71591c2a76881f5d42826c8b31f06d16a09687de70a881bec57f.json @@ -0,0 +1,26 @@ +{ + "db_name": "SQLite", + "query": "\n SELECT DISTINCT uid, max(0, synctoken) as \"synctoken!: i64\" from calendarobjectchangelog\n WHERE synctoken > ?\n ORDER BY synctoken ASC\n ", + "describe": { + "columns": [ + { + "name": "uid", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "synctoken!: i64", + "ordinal": 1, + "type_info": "Null" + } + ], + "parameters": { + "Right": 1 + }, + "nullable": [ + false, + null + ] + }, + "hash": "ec583c44374b71591c2a76881f5d42826c8b31f06d16a09687de70a881bec57f" +} diff --git a/.sqlx/query-f13006549869125c63731055d242bc29f66761eb52adcb16cde56d56ab5c1ecf.json b/.sqlx/query-f13006549869125c63731055d242bc29f66761eb52adcb16cde56d56ab5c1ecf.json new file mode 100644 index 0000000..f75d93b --- /dev/null +++ b/.sqlx/query-f13006549869125c63731055d242bc29f66761eb52adcb16cde56d56ab5c1ecf.json @@ -0,0 +1,12 @@ +{ + "db_name": "SQLite", + "query": "\n INSERT INTO calendarobjectchangelog (principal, cid, uid, operation, synctoken)\n VALUES (?1, ?2, ?3, ?4, (\n SELECT synctoken FROM calendars WHERE (principal, id) = (?1, ?2)\n ))", + "describe": { + "columns": [], + "parameters": { + "Right": 4 + }, + "nullable": [] + }, + "hash": "f13006549869125c63731055d242bc29f66761eb52adcb16cde56d56ab5c1ecf" +} diff --git a/.sqlx/query-f387e6ef026d8314e78c0672652fb3d6876598ecde4db98d7a303c9e4c676376.json b/.sqlx/query-f387e6ef026d8314e78c0672652fb3d6876598ecde4db98d7a303c9e4c676376.json new file mode 100644 index 0000000..037b1f6 --- /dev/null +++ b/.sqlx/query-f387e6ef026d8314e78c0672652fb3d6876598ecde4db98d7a303c9e4c676376.json @@ -0,0 +1,68 @@ +{ + "db_name": "SQLite", + "query": "SELECT principal, id, synctoken, displayname, \"order\", description, color, timezone, deleted_at\n FROM calendars\n WHERE principal = ? AND deleted_at IS NULL", + "describe": { + "columns": [ + { + "name": "principal", + "ordinal": 0, + "type_info": "Text" + }, + { + "name": "id", + "ordinal": 1, + "type_info": "Text" + }, + { + "name": "synctoken", + "ordinal": 2, + "type_info": "Integer" + }, + { + "name": "displayname", + "ordinal": 3, + "type_info": "Text" + }, + { + "name": "order", + "ordinal": 4, + "type_info": "Integer" + }, + { + "name": "description", + "ordinal": 5, + "type_info": "Text" + }, + { + "name": "color", + "ordinal": 6, + "type_info": "Text" + }, + { + "name": "timezone", + "ordinal": 7, + "type_info": "Text" + }, + { + "name": "deleted_at", + "ordinal": 8, + "type_info": "Datetime" + } + ], + "parameters": { + "Right": 1 + }, + "nullable": [ + false, + false, + false, + true, + false, + true, + true, + false, + true + ] + }, + "hash": "f387e6ef026d8314e78c0672652fb3d6876598ecde4db98d7a303c9e4c676376" +} diff --git a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs index 0dc70a6..57d6c3a 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs @@ -25,7 +25,7 @@ pub struct CalendarMultigetRequest { href: Vec, } -pub async fn get_events_calendar_multiget( +pub async fn get_objects_calendar_multiget( cal_query: &CalendarMultigetRequest, prefix: &str, principal: &str, @@ -68,8 +68,8 @@ pub async fn handle_calendar_multiget( cid: &str, cal_store: &RwLock, ) -> Result, String>, Error> { - let events = - get_events_calendar_multiget(&cal_multiget, prefix, principal, cid, cal_store).await?; + let objects = + get_objects_calendar_multiget(&cal_multiget, prefix, principal, cid, cal_store).await?; let props = match cal_multiget.prop { PropfindType::Allprop => { @@ -84,10 +84,10 @@ pub async fn handle_calendar_multiget( let props: Vec<&str> = props.iter().map(String::as_str).collect(); let mut responses = Vec::new(); - for event in events { - let path = format!("{}/{}", req.path(), event.get_uid()); + for object in objects { + let path = format!("{}/{}", req.path(), object.get_uid()); responses.push( - CalendarObjectResource::from(event) + CalendarObjectResource::from(object) .propfind(prefix, &path, props.clone()) .await?, ); diff --git a/crates/caldav/src/calendar/methods/report/calendar_query.rs b/crates/caldav/src/calendar/methods/report/calendar_query.rs index bcee835..617b3ec 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_query.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_query.rs @@ -160,7 +160,7 @@ pub struct CalendarQueryRequest { timezone: Option, } -pub async fn get_events_calendar_query( +pub async fn get_objects_calendar_query( cal_query: &CalendarQueryRequest, principal: &str, cid: &str, @@ -181,7 +181,7 @@ pub async fn handle_calendar_query( cid: &str, cal_store: &RwLock, ) -> Result, String>, Error> { - let events = get_events_calendar_query(&cal_query, principal, cid, cal_store).await?; + let objects = get_objects_calendar_query(&cal_query, principal, cid, cal_store).await?; let props = match cal_query.prop { PropfindType::Allprop => { @@ -196,10 +196,10 @@ pub async fn handle_calendar_query( let props: Vec<&str> = props.iter().map(String::as_str).collect(); let mut responses = Vec::new(); - for event in events { - let path = format!("{}/{}", req.path(), event.get_uid()); + for object in objects { + let path = format!("{}/{}", req.path(), object.get_uid()); responses.push( - CalendarObjectResource::from(event) + CalendarObjectResource::from(object) .propfind(prefix, &path, props.clone()) .await?, ); diff --git a/crates/caldav/src/calendar/methods/report/sync_collection.rs b/crates/caldav/src/calendar/methods/report/sync_collection.rs index c1d04b4..0295a5b 100644 --- a/crates/caldav/src/calendar/methods/report/sync_collection.rs +++ b/crates/caldav/src/calendar/methods/report/sync_collection.rs @@ -63,24 +63,24 @@ pub async fn handle_sync_collection( let props: Vec<&str> = props.iter().map(String::as_str).collect(); let old_synctoken = parse_synctoken(&sync_collection.sync_token).unwrap_or(0); - let (new_events, deleted_events, new_synctoken) = cal_store + let (new_objects, deleted_objects, new_synctoken) = cal_store .read() .await .sync_changes(principal, cid, old_synctoken) .await?; let mut responses = Vec::new(); - for event in new_events { - let path = format!("{}/{}", req.path(), event.get_uid()); + for object in new_objects { + let path = format!("{}/{}", req.path(), object.get_uid()); responses.push( - CalendarObjectResource::from(event) + CalendarObjectResource::from(object) .propfind(prefix, &path, props.clone()) .await?, ); } - for event_uid in deleted_events { - let path = format!("{}/{}", req.path(), event_uid); + for object_uid in deleted_objects { + let path = format!("{}/{}", req.path(), object_uid); responses.push(ResponseElement { href: path, status: Some(format!("HTTP/1.1 {}", StatusCode::NOT_FOUND)), diff --git a/crates/store/migrations/20240621161002_init.sql b/crates/store/migrations/1_init.sql similarity index 92% rename from crates/store/migrations/20240621161002_init.sql rename to crates/store/migrations/1_init.sql index da19f91..133d9bb 100644 --- a/crates/store/migrations/20240621161002_init.sql +++ b/crates/store/migrations/1_init.sql @@ -11,7 +11,7 @@ CREATE TABLE calendars ( PRIMARY KEY (principal, id) ); -CREATE TABLE events ( +CREATE TABLE calendarobjects ( principal TEXT NOT NULL, cid TEXT NOT NULL, uid TEXT NOT NULL, @@ -22,7 +22,7 @@ CREATE TABLE events ( FOREIGN KEY (principal, cid) REFERENCES calendars(principal, id) ); -CREATE TABLE eventchangelog ( +CREATE TABLE calendarobjectchangelog ( -- The actual sync token is the SQLite field 'ROWID' principal TEXT NOT NULL, cid TEXT NOT NULL, diff --git a/crates/store/src/store.rs b/crates/store/src/calendar_store.rs similarity index 100% rename from crates/store/src/store.rs rename to crates/store/src/calendar_store.rs diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index f3eeafd..24849d8 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -1,7 +1,8 @@ +pub mod calendar_store; pub mod error; pub mod model; pub mod sqlite_store; -pub mod store; pub mod timestamp; +pub use calendar_store::CalendarStore; pub use error::Error; -pub use store::CalendarStore; + diff --git a/crates/store/src/sqlite_store.rs b/crates/store/src/sqlite_store.rs index fa99b97..e9a7518 100644 --- a/crates/store/src/sqlite_store.rs +++ b/crates/store/src/sqlite_store.rs @@ -41,7 +41,7 @@ enum CalendarChangeOperation { } // Logs an operation to the events -async fn log_event_operation( +async fn log_object_operation( tx: &mut Transaction<'_, Sqlite>, principal: &str, cid: &str, @@ -61,7 +61,7 @@ async fn log_event_operation( sqlx::query!( r#" - INSERT INTO eventchangelog (principal, cid, uid, operation, synctoken) + INSERT INTO calendarobjectchangelog (principal, cid, uid, operation, synctoken) VALUES (?1, ?2, ?3, ?4, ( SELECT synctoken FROM calendars WHERE (principal, id) = (?1, ?2) ))"#, @@ -189,7 +189,7 @@ impl CalendarStore for SqliteCalendarStore { async fn get_objects(&self, principal: &str, cid: &str) -> Result, Error> { sqlx::query_as!( CalendarObjectRow, - "SELECT uid, ics FROM events WHERE principal = ? AND cid = ? AND deleted_at IS NULL", + "SELECT uid, ics FROM calendarobjects WHERE principal = ? AND cid = ? AND deleted_at IS NULL", principal, cid ) @@ -206,17 +206,16 @@ impl CalendarStore for SqliteCalendarStore { cid: &str, uid: &str, ) -> Result { - let event = sqlx::query_as!( + Ok(sqlx::query_as!( CalendarObjectRow, - "SELECT uid, ics FROM events WHERE (principal, cid, uid) = (?, ?, ?)", + "SELECT uid, ics FROM calendarobjects WHERE (principal, cid, uid) = (?, ?, ?)", principal, cid, uid ) .fetch_one(&self.db) .await? - .try_into()?; - Ok(event) + .try_into()?) } async fn put_object( @@ -231,7 +230,7 @@ impl CalendarStore for SqliteCalendarStore { // input validation CalendarObject::from_ics(uid.to_owned(), ics.to_owned())?; sqlx::query!( - "REPLACE INTO events (principal, cid, uid, ics) VALUES (?, ?, ?, ?)", + "REPLACE INTO calendarobjects (principal, cid, uid, ics) VALUES (?, ?, ?, ?)", principal, cid, uid, @@ -240,7 +239,7 @@ impl CalendarStore for SqliteCalendarStore { .execute(&mut *tx) .await?; - log_event_operation( + log_object_operation( &mut tx, &principal, &cid, @@ -264,7 +263,7 @@ impl CalendarStore for SqliteCalendarStore { match use_trashbin { true => { sqlx::query!( - "UPDATE events SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)", + "UPDATE calendarobjects SET deleted_at = datetime(), updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)", principal, cid, uid @@ -273,12 +272,16 @@ impl CalendarStore for SqliteCalendarStore { .await?; } false => { - sqlx::query!("DELETE FROM events WHERE cid = ? AND uid = ?", cid, uid) - .execute(&mut *tx) - .await?; + sqlx::query!( + "DELETE FROM calendarobjects WHERE cid = ? AND uid = ?", + cid, + uid + ) + .execute(&mut *tx) + .await?; } }; - log_event_operation( + log_object_operation( &mut tx, principal, cid, @@ -294,7 +297,7 @@ impl CalendarStore for SqliteCalendarStore { let mut tx = self.db.begin().await?; sqlx::query!( - r#"UPDATE events SET deleted_at = NULL, updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)"#, + r#"UPDATE calendarobjects SET deleted_at = NULL, updated_at = datetime() WHERE (principal, cid, uid) = (?, ?, ?)"#, principal, cid, uid @@ -302,7 +305,7 @@ impl CalendarStore for SqliteCalendarStore { .execute(&mut *tx) .await?; - log_event_operation( + log_object_operation( &mut tx, principal, cid, @@ -327,7 +330,7 @@ impl CalendarStore for SqliteCalendarStore { let changes = sqlx::query_as!( Row, r#" - SELECT DISTINCT uid, max(0, synctoken) as "synctoken!: i64" from eventchangelog + SELECT DISTINCT uid, max(0, synctoken) as "synctoken!: i64" from calendarobjectchangelog WHERE synctoken > ? ORDER BY synctoken ASC "#, @@ -336,8 +339,8 @@ impl CalendarStore for SqliteCalendarStore { .fetch_all(&self.db) .await?; - let mut events = vec![]; - let mut deleted_events = vec![]; + let mut objects = vec![]; + let mut deleted_objects = vec![]; let new_synctoken = changes .last() @@ -346,13 +349,13 @@ impl CalendarStore for SqliteCalendarStore { for Row { uid, .. } in changes { match self.get_object(principal, cid, &uid).await { - Ok(event) => events.push(event), - Err(Error::NotFound) => deleted_events.push(uid), + Ok(object) => objects.push(object), + Err(Error::NotFound) => deleted_objects.push(uid), Err(err) => return Err(err), } } - Ok((events, deleted_events, new_synctoken)) + Ok((objects, deleted_objects, new_synctoken)) } } diff --git a/crates/store/tests/test_calendar.rs b/crates/store/tests/test_calendar.rs index b664553..7be3088 100644 --- a/crates/store/tests/test_calendar.rs +++ b/crates/store/tests/test_calendar.rs @@ -1,7 +1,7 @@ use rstest::rstest; use rstest_reuse::{self, apply, template}; use rustical_store::sqlite_store::create_test_store; -use rustical_store::store::CalendarStore; +use rustical_store::CalendarStore; const TIMEZONE: &str = include_str!("examples/timezone.ics"); const EVENT: &str = include_str!("examples/event.ics");