From d647e45e5cbdff78e1c4868592f06f6ea0acd013 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sat, 1 Jun 2024 22:00:07 +0200 Subject: [PATCH] Add calendar-order prop --- crates/caldav/src/calendar/methods/mkcalendar.rs | 2 ++ crates/caldav/src/calendar/resource.rs | 6 ++++++ .../{20231006125208_init.sql => 20240601182759_init.sql} | 1 + crates/store/src/calendar.rs | 1 + crates/store/src/sqlite_store.rs | 7 ++++--- 5 files changed, 14 insertions(+), 3 deletions(-) rename crates/store/migrations/{20231006125208_init.sql => 20240601182759_init.sql} (90%) diff --git a/crates/caldav/src/calendar/methods/mkcalendar.rs b/crates/caldav/src/calendar/methods/mkcalendar.rs index 305db73..4db713c 100644 --- a/crates/caldav/src/calendar/methods/mkcalendar.rs +++ b/crates/caldav/src/calendar/methods/mkcalendar.rs @@ -36,6 +36,7 @@ pub struct MkcolCalendarProp { displayname: Option, calendar_description: Option, calendar_color: Option, + order: Option, calendar_timezone: Option, supported_calendar_component_set: Option, } @@ -69,6 +70,7 @@ pub async fn route_mkcol_calendar Ok(CalendarPropResponse::CalendarDescription( TextNode(self.calendar.description.clone()), )), + CalendarProp::CalendarOrder => Ok(CalendarPropResponse::CalendarOrder(TextNode( + format!("{}", self.calendar.order).into(), + ))), CalendarProp::SupportedCalendarComponentSet => { Ok(CalendarPropResponse::SupportedCalendarComponentSet( SupportedCalendarComponentSet { diff --git a/crates/store/migrations/20231006125208_init.sql b/crates/store/migrations/20240601182759_init.sql similarity index 90% rename from crates/store/migrations/20231006125208_init.sql rename to crates/store/migrations/20240601182759_init.sql index 68ae651..92089c1 100644 --- a/crates/store/migrations/20231006125208_init.sql +++ b/crates/store/migrations/20240601182759_init.sql @@ -3,6 +3,7 @@ CREATE TABLE calendars ( owner TEXT NOT NULL, name TEXT, description TEXT, + 'order' INT DEFAULT 0 NOT NULL, color TEXT, timezone TEXT NOT NULL ); diff --git a/crates/store/src/calendar.rs b/crates/store/src/calendar.rs index 5cf9b1f..4bb93d5 100644 --- a/crates/store/src/calendar.rs +++ b/crates/store/src/calendar.rs @@ -5,6 +5,7 @@ pub struct Calendar { pub id: String, pub name: Option, pub owner: String, + pub order: i64, pub description: Option, pub color: Option, pub timezone: Option, diff --git a/crates/store/src/sqlite_store.rs b/crates/store/src/sqlite_store.rs index f6c5dc2..faeb581 100644 --- a/crates/store/src/sqlite_store.rs +++ b/crates/store/src/sqlite_store.rs @@ -35,7 +35,7 @@ impl CalendarStore for SqliteCalendarStore { async fn get_calendar(&self, id: &str) -> Result { let cal = sqlx::query_as!( Calendar, - "SELECT id, name, owner, description, color, timezone FROM calendars WHERE id = ?", + r#"SELECT id, name, owner, "order", description, color, timezone FROM calendars WHERE id = ?"#, id ) .fetch_one(&self.db) @@ -46,7 +46,7 @@ impl CalendarStore for SqliteCalendarStore { async fn get_calendars(&self, _owner: &str) -> Result, Error> { let cals = sqlx::query_as!( Calendar, - "SELECT id, name, owner, description, color, timezone FROM calendars" + r#"SELECT id, name, owner, "order", description, color, timezone FROM calendars"#, ) .fetch_all(&self.db) .await?; @@ -55,11 +55,12 @@ impl CalendarStore for SqliteCalendarStore { async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error> { sqlx::query!( - "INSERT INTO calendars (id, name, description, owner, color, timezone) VALUES (?, ?, ?, ?, ?, ?)", + r#"INSERT INTO calendars (id, name, description, owner, "order", color, timezone) VALUES (?, ?, ?, ?, ?, ?, ?)"#, cid, calendar.name, calendar.description, calendar.owner, + calendar.order, calendar.color, calendar.timezone ).execute(&self.db).await?;