Change upsert_event to put_event to match webdav spec

This commit is contained in:
Lennart
2024-06-21 18:05:03 +02:00
parent 029b23154d
commit 26d2f88d1c
4 changed files with 5 additions and 9 deletions

View File

@@ -73,7 +73,7 @@ pub async fn put_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
.store .store
.write() .write()
.await .await
.upsert_event(cid, uid, body) .put_event(cid, uid, body)
.await?; .await?;
Ok(HttpResponse::Ok().body("")) Ok(HttpResponse::Ok().body(""))

View File

@@ -113,12 +113,10 @@ impl CalendarStore for SqliteCalendarStore {
Ok(event) Ok(event)
} }
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> {
// 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())?; let _ = Event::from_ics(uid.to_owned(), ics.to_owned())?;
sqlx::query!( sqlx::query!(
"INSERT INTO events (cid, uid, ics) VALUES (?, ?, ?)", "REPLACE INTO events (cid, uid, ics) VALUES (?, ?, ?)",
cid, cid,
uid, uid,
ics, ics,

View File

@@ -14,6 +14,6 @@ pub trait CalendarStore: Send + Sync + 'static {
async fn get_events(&self, cid: &str) -> Result<Vec<Event>, Error>; async fn get_events(&self, cid: &str) -> Result<Vec<Event>, Error>;
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event, Error>; async fn get_event(&self, cid: &str, uid: &str) -> Result<Event, Error>;
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>; async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<(), Error>;
} }

View File

@@ -2,14 +2,12 @@ use rstest::rstest;
use rstest_reuse::{self, apply, template}; use rstest_reuse::{self, apply, template};
use rustical_store::sqlite_store::create_test_store; use rustical_store::sqlite_store::create_test_store;
use rustical_store::store::CalendarStore; use rustical_store::store::CalendarStore;
use rustical_store::toml_store::TomlCalendarStore;
const TIMEZONE: &str = include_str!("examples/timezone.ics"); const TIMEZONE: &str = include_str!("examples/timezone.ics");
const EVENT: &str = include_str!("examples/event.ics"); const EVENT: &str = include_str!("examples/event.ics");
#[template] #[template]
#[rstest] #[rstest]
#[case::toml(async {TomlCalendarStore::test()})]
#[case::sqlite(async {create_test_store().await.unwrap() })] #[case::sqlite(async {create_test_store().await.unwrap() })]
async fn cal_store<CS: CalendarStore>( async fn cal_store<CS: CalendarStore>(
#[future(awt)] #[future(awt)]
@@ -43,7 +41,7 @@ async fn test_create_event<CS: CalendarStore>(store: CS) {
.unwrap(); .unwrap();
store store
.upsert_event("test".to_owned(), "asd".to_owned(), EVENT.to_owned()) .put_event("test".to_owned(), "asd".to_owned(), EVENT.to_owned())
.await .await
.unwrap(); .unwrap();