mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
Initial commit
This commit is contained in:
64
crates/dav/src/routes/event.rs
Normal file
64
crates/dav/src/routes/event.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
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<C: CalendarStore>(
|
||||
store: Data<RwLock<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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<C: CalendarStore>(
|
||||
store: Data<RwLock<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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<C: CalendarStore>(
|
||||
store: Data<RwLock<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
body: String,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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(""))
|
||||
}
|
||||
Reference in New Issue
Block a user