mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 01:12:24 +00:00
store: Add update_calendar method
This commit is contained in:
@@ -67,6 +67,23 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn update_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error> {
|
||||
let result = sqlx::query!(
|
||||
r#"UPDATE calendars SET name = ?, description = ?, owner = ?, "order" = ?, color = ?, timezone = ? WHERE id = ?"#,
|
||||
calendar.name,
|
||||
calendar.description,
|
||||
calendar.owner,
|
||||
calendar.order,
|
||||
calendar.color,
|
||||
calendar.timezone,
|
||||
cid,
|
||||
).execute(&self.db).await?;
|
||||
if result.rows_affected() == 0 {
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<(), Error> {
|
||||
sqlx::query!("DELETE FROM calendars WHERE id = ?", cid)
|
||||
.execute(&self.db)
|
||||
@@ -97,6 +114,7 @@ impl CalendarStore for SqliteCalendarStore {
|
||||
}
|
||||
|
||||
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<(), Error> {
|
||||
// TODO: This is not actually an upsert
|
||||
// Do this extra step to ensure that the input is actually valid
|
||||
let _ = Event::from_ics(uid.to_owned(), ics.to_owned())?;
|
||||
sqlx::query!(
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::{calendar::Calendar, event::Event};
|
||||
pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendar(&self, id: &str) -> Result<Calendar, Error>;
|
||||
async fn get_calendars(&self, owner: &str) -> Result<Vec<Calendar>, Error>;
|
||||
async fn update_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<(), Error>;
|
||||
|
||||
|
||||
@@ -66,6 +66,15 @@ impl CalendarStore for TomlCalendarStore {
|
||||
}
|
||||
}
|
||||
|
||||
async fn update_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error> {
|
||||
if let None = self.calendars.remove(&cid) {
|
||||
// No old calendar to update, for consistency reasons throw an error
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
self.calendars.insert(cid, calendar);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<(), Error> {
|
||||
self.events.remove(cid);
|
||||
self.save().await.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user