From 26d2f88d1cb4f6e267ad26723ed560c9fc4bbe47 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:05:03 +0200 Subject: [PATCH] Change upsert_event to put_event to match webdav spec --- crates/caldav/src/event/methods.rs | 2 +- crates/store/src/sqlite_store.rs | 6 ++---- crates/store/src/store.rs | 2 +- crates/store/tests/test_calendar.rs | 4 +--- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/caldav/src/event/methods.rs b/crates/caldav/src/event/methods.rs index d277097..5147949 100644 --- a/crates/caldav/src/event/methods.rs +++ b/crates/caldav/src/event/methods.rs @@ -73,7 +73,7 @@ pub async fn put_event( .store .write() .await - .upsert_event(cid, uid, body) + .put_event(cid, uid, body) .await?; Ok(HttpResponse::Ok().body("")) diff --git a/crates/store/src/sqlite_store.rs b/crates/store/src/sqlite_store.rs index 07f8ca2..6675929 100644 --- a/crates/store/src/sqlite_store.rs +++ b/crates/store/src/sqlite_store.rs @@ -113,12 +113,10 @@ impl CalendarStore for SqliteCalendarStore { Ok(event) } - 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 + async fn put_event(&mut self, cid: String, uid: String, ics: String) -> Result<(), Error> { let _ = Event::from_ics(uid.to_owned(), ics.to_owned())?; sqlx::query!( - "INSERT INTO events (cid, uid, ics) VALUES (?, ?, ?)", + "REPLACE INTO events (cid, uid, ics) VALUES (?, ?, ?)", cid, uid, ics, diff --git a/crates/store/src/store.rs b/crates/store/src/store.rs index f1e18ad..52b55e7 100644 --- a/crates/store/src/store.rs +++ b/crates/store/src/store.rs @@ -14,6 +14,6 @@ pub trait CalendarStore: Send + Sync + 'static { async fn get_events(&self, cid: &str) -> Result, Error>; async fn get_event(&self, cid: &str, uid: &str) -> Result; - async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<(), Error>; + async fn put_event(&mut self, cid: String, uid: String, ics: String) -> Result<(), Error>; async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<(), Error>; } diff --git a/crates/store/tests/test_calendar.rs b/crates/store/tests/test_calendar.rs index 63e89b0..6d37a0b 100644 --- a/crates/store/tests/test_calendar.rs +++ b/crates/store/tests/test_calendar.rs @@ -2,14 +2,12 @@ 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::toml_store::TomlCalendarStore; const TIMEZONE: &str = include_str!("examples/timezone.ics"); const EVENT: &str = include_str!("examples/event.ics"); #[template] #[rstest] -#[case::toml(async {TomlCalendarStore::test()})] #[case::sqlite(async {create_test_store().await.unwrap() })] async fn cal_store( #[future(awt)] @@ -43,7 +41,7 @@ async fn test_create_event(store: CS) { .unwrap(); store - .upsert_event("test".to_owned(), "asd".to_owned(), EVENT.to_owned()) + .put_event("test".to_owned(), "asd".to_owned(), EVENT.to_owned()) .await .unwrap();