mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
birthday calendar store: Support manual birthday calendar creation
This commit is contained in:
@@ -115,11 +115,8 @@ impl SqliteAddressbookStore {
|
|||||||
.map_err(crate::Error::from).map(|cals| cals.into_iter().map(BirthdayCalendarJoinRow::into).collect())?)
|
.map_err(crate::Error::from).map(|cals| cals.into_iter().map(BirthdayCalendarJoinRow::into).collect())?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[must_use]
|
||||||
pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
pub fn default_birthday_calendar(addressbook: Addressbook) -> Calendar {
|
||||||
executor: E,
|
|
||||||
addressbook: &Addressbook,
|
|
||||||
) -> Result<(), rustical_store::Error> {
|
|
||||||
let birthday_name = addressbook
|
let birthday_name = addressbook
|
||||||
.displayname
|
.displayname
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -130,14 +127,44 @@ impl SqliteAddressbookStore {
|
|||||||
hasher.update(&addressbook.push_topic);
|
hasher.update(&addressbook.push_topic);
|
||||||
format!("{:x}", hasher.finalize())
|
format!("{:x}", hasher.finalize())
|
||||||
};
|
};
|
||||||
|
Calendar {
|
||||||
|
principal: addressbook.principal,
|
||||||
|
meta: CalendarMetadata {
|
||||||
|
displayname: birthday_name,
|
||||||
|
order: 0,
|
||||||
|
description: None,
|
||||||
|
color: None,
|
||||||
|
},
|
||||||
|
id: format!("{}{}", Self::PREFIX, addressbook.id),
|
||||||
|
components: vec![CalendarObjectType::Event],
|
||||||
|
timezone_id: None,
|
||||||
|
deleted_at: None,
|
||||||
|
synctoken: Default::default(),
|
||||||
|
subscription_url: None,
|
||||||
|
push_topic: birthday_push_topic,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
pub async fn _insert_birthday_calendar<'e, E: Executor<'e, Database = Sqlite>>(
|
||||||
|
executor: E,
|
||||||
|
calendar: &Calendar,
|
||||||
|
) -> Result<(), rustical_store::Error> {
|
||||||
|
let id = calendar
|
||||||
|
.id
|
||||||
|
.strip_prefix(BIRTHDAYS_PREFIX)
|
||||||
|
.ok_or(Error::NotFound)?;
|
||||||
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
r#"INSERT INTO birthday_calendars (principal, id, displayname, push_topic)
|
r#"INSERT INTO birthday_calendars (principal, id, displayname, description, "order", color, push_topic)
|
||||||
VALUES (?, ?, ?, ?)"#,
|
VALUES (?, ?, ?, ?, ?, ?, ?)"#,
|
||||||
addressbook.principal,
|
calendar.principal,
|
||||||
addressbook.id,
|
id,
|
||||||
birthday_name,
|
calendar.meta.displayname,
|
||||||
birthday_push_topic,
|
calendar.meta.description,
|
||||||
|
calendar.meta.order,
|
||||||
|
calendar.meta.color,
|
||||||
|
calendar.push_topic,
|
||||||
)
|
)
|
||||||
.execute(executor)
|
.execute(executor)
|
||||||
.await
|
.await
|
||||||
@@ -256,8 +283,8 @@ impl CalendarStore for SqliteAddressbookStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn insert_calendar(&self, _calendar: Calendar) -> Result<(), Error> {
|
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> {
|
||||||
Err(Error::ReadOnly)
|
Self::_insert_birthday_calendar(&self.db, &calendar).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
|
|||||||
@@ -467,7 +467,8 @@ impl AddressbookStore for SqliteAddressbookStore {
|
|||||||
.await
|
.await
|
||||||
.map_err(crate::Error::from)?;
|
.map_err(crate::Error::from)?;
|
||||||
Self::_insert_addressbook(&mut *tx, &addressbook).await?;
|
Self::_insert_addressbook(&mut *tx, &addressbook).await?;
|
||||||
Self::_insert_birthday_calendar(&mut *tx, &addressbook).await?;
|
let birthday_cal = Self::default_birthday_calendar(addressbook);
|
||||||
|
Self::_insert_birthday_calendar(&mut *tx, &birthday_cal).await?;
|
||||||
tx.commit().await.map_err(crate::Error::from)?;
|
tx.commit().await.map_err(crate::Error::from)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user