use crate::Error; use actix_web::web::{Data, Path}; use actix_web::HttpResponse; use rustical_store::calendar::CalendarStore; use tokio::sync::RwLock; pub async fn delete_event( store: Data>, path: Path<(String, String, String)>, ) -> Result { let (_principal, mut cid, uid) = path.into_inner(); if cid.ends_with(".ics") { cid.truncate(cid.len() - 4); } store .write() .await .delete_event(&uid) .await .map_err(|_e| Error::InternalError)?; Ok(HttpResponse::Ok().body("")) } pub async fn get_event( store: Data>, path: Path<(String, String, String)>, ) -> Result { let (_principal, mut cid, uid) = path.into_inner(); if cid.ends_with(".ics") { cid.truncate(cid.len() - 4); } let event = store .read() .await .get_event(&uid) .await .map_err(|_e| Error::NotFound)?; Ok(HttpResponse::Ok() .insert_header(("ETag", event.get_etag())) .body(event.to_ics().to_string())) } pub async fn put_event( store: Data>, path: Path<(String, String, String)>, body: String, ) -> Result { let (_principal, mut cid, uid) = path.into_inner(); // Incredibly bodged method of normalising the uid but works for a prototype if cid.ends_with(".ics") { cid.truncate(cid.len() - 4); } dbg!(&body); store .write() .await .upsert_event(uid, body) .await .map_err(|_e| Error::InternalError)?; Ok(HttpResponse::Ok().body("")) }