Refactoring to remove CalDavContext

This commit is contained in:
Lennart
2024-10-27 01:20:27 +02:00
parent ea4281babd
commit 61aef8d52b
3 changed files with 19 additions and 41 deletions

View File

@@ -1,4 +1,3 @@
use crate::CalDavContext;
use crate::Error;
use actix_web::web::{Data, Path};
use actix_web::HttpResponse;
@@ -6,6 +5,7 @@ use rustical_store::auth::User;
use rustical_store::model::Calendar;
use rustical_store::CalendarStore;
use serde::{Deserialize, Serialize};
use tokio::sync::RwLock;
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "kebab-case")]
@@ -57,7 +57,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
path: Path<(String, String)>,
body: String,
user: User,
context: Data<CalDavContext<C>>,
store: Data<RwLock<C>>,
) -> Result<HttpResponse, Error> {
let (principal, cal_id) = path.into_inner();
if principal != user.id {
@@ -79,13 +79,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
synctoken: 0,
};
match context
.store
.read()
.await
.get_calendar(&principal, &cal_id)
.await
{
match store.read().await.get_calendar(&principal, &cal_id).await {
Err(rustical_store::Error::NotFound) => {
// No conflict, no worries
}
@@ -99,7 +93,7 @@ pub async fn route_mkcalendar<C: CalendarStore + ?Sized>(
}
}
match context.store.write().await.insert_calendar(calendar).await {
match store.write().await.insert_calendar(calendar).await {
// The spec says we should return a mkcalendar-response but I don't know what goes into it.
// However, it works without one but breaks on iPadOS when using an empty one :)
Ok(()) => Ok(HttpResponse::Created()