Add calendar-order prop

This commit is contained in:
Lennart
2024-06-01 22:00:07 +02:00
parent 22b6f63d3b
commit d647e45e5c
5 changed files with 14 additions and 3 deletions

View File

@@ -36,6 +36,7 @@ pub struct MkcolCalendarProp {
displayname: Option<String>, displayname: Option<String>,
calendar_description: Option<String>, calendar_description: Option<String>,
calendar_color: Option<String>, calendar_color: Option<String>,
order: Option<i64>,
calendar_timezone: Option<String>, calendar_timezone: Option<String>,
supported_calendar_component_set: Option<SupportedCalendarComponentSetElement>, supported_calendar_component_set: Option<SupportedCalendarComponentSetElement>,
} }
@@ -69,6 +70,7 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
let calendar = Calendar { let calendar = Calendar {
id: cid.to_owned(), id: cid.to_owned(),
owner: principal, owner: principal,
order: request.order.unwrap_or(0),
name: request.displayname, name: request.displayname,
timezone: request.calendar_timezone, timezone: request.calendar_timezone,
color: request.calendar_color, color: request.calendar_color,

View File

@@ -124,6 +124,7 @@ pub enum CalendarProp {
Displayname, Displayname,
CalendarColor, CalendarColor,
CalendarDescription, CalendarDescription,
CalendarOrder,
SupportedCalendarComponentSet, SupportedCalendarComponentSet,
SupportedCalendarData, SupportedCalendarData,
Getcontenttype, Getcontenttype,
@@ -142,6 +143,8 @@ pub enum CalendarPropResponse {
CalendarColor(TextNode), CalendarColor(TextNode),
#[serde(rename = "C:calendar-description", alias = "calendar-description")] #[serde(rename = "C:calendar-description", alias = "calendar-description")]
CalendarDescription(TextNode), CalendarDescription(TextNode),
#[serde(rename = "IC:calendar-description", alias = "calendar-description")]
CalendarOrder(TextNode),
#[serde( #[serde(
rename = "C:supported-calendar-component-set", rename = "C:supported-calendar-component-set",
alias = "supported-calendar-component-set" alias = "supported-calendar-component-set"
@@ -193,6 +196,9 @@ impl Resource for CalendarFile {
CalendarProp::CalendarDescription => Ok(CalendarPropResponse::CalendarDescription( CalendarProp::CalendarDescription => Ok(CalendarPropResponse::CalendarDescription(
TextNode(self.calendar.description.clone()), TextNode(self.calendar.description.clone()),
)), )),
CalendarProp::CalendarOrder => Ok(CalendarPropResponse::CalendarOrder(TextNode(
format!("{}", self.calendar.order).into(),
))),
CalendarProp::SupportedCalendarComponentSet => { CalendarProp::SupportedCalendarComponentSet => {
Ok(CalendarPropResponse::SupportedCalendarComponentSet( Ok(CalendarPropResponse::SupportedCalendarComponentSet(
SupportedCalendarComponentSet { SupportedCalendarComponentSet {

View File

@@ -3,6 +3,7 @@ CREATE TABLE calendars (
owner TEXT NOT NULL, owner TEXT NOT NULL,
name TEXT, name TEXT,
description TEXT, description TEXT,
'order' INT DEFAULT 0 NOT NULL,
color TEXT, color TEXT,
timezone TEXT NOT NULL timezone TEXT NOT NULL
); );

View File

@@ -5,6 +5,7 @@ pub struct Calendar {
pub id: String, pub id: String,
pub name: Option<String>, pub name: Option<String>,
pub owner: String, pub owner: String,
pub order: i64,
pub description: Option<String>, pub description: Option<String>,
pub color: Option<String>, pub color: Option<String>,
pub timezone: Option<String>, pub timezone: Option<String>,

View File

@@ -35,7 +35,7 @@ impl CalendarStore for SqliteCalendarStore {
async fn get_calendar(&self, id: &str) -> Result<Calendar, Error> { async fn get_calendar(&self, id: &str) -> Result<Calendar, Error> {
let cal = sqlx::query_as!( let cal = sqlx::query_as!(
Calendar, 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 id
) )
.fetch_one(&self.db) .fetch_one(&self.db)
@@ -46,7 +46,7 @@ impl CalendarStore for SqliteCalendarStore {
async fn get_calendars(&self, _owner: &str) -> Result<Vec<Calendar>, Error> { async fn get_calendars(&self, _owner: &str) -> Result<Vec<Calendar>, Error> {
let cals = sqlx::query_as!( let cals = sqlx::query_as!(
Calendar, 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) .fetch_all(&self.db)
.await?; .await?;
@@ -55,11 +55,12 @@ impl CalendarStore for SqliteCalendarStore {
async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error> { async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error> {
sqlx::query!( 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, cid,
calendar.name, calendar.name,
calendar.description, calendar.description,
calendar.owner, calendar.owner,
calendar.order,
calendar.color, calendar.color,
calendar.timezone calendar.timezone
).execute(&self.db).await?; ).execute(&self.db).await?;