From 2a347f0616e90a0433b32643bb84475a4b5a60fd Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sun, 29 Sep 2024 14:00:06 +0200 Subject: [PATCH] caldav: Refactoring to for consistent terminology between resources and resource services --- .../methods/report/calendar_multiget.rs | 4 +- .../calendar/methods/report/calendar_query.rs | 4 +- .../methods/report/sync_collection.rs | 4 +- crates/caldav/src/calendar/resource.rs | 14 +++---- crates/caldav/src/event/resource.rs | 12 +++--- crates/caldav/src/lib.rs | 38 ++++++++++++------- crates/caldav/src/principal/mod.rs | 16 ++++---- crates/caldav/src/root/mod.rs | 14 +++---- 8 files changed, 58 insertions(+), 48 deletions(-) diff --git a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs index bd3e077..8aa775d 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_multiget.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_multiget.rs @@ -1,5 +1,5 @@ use crate::{ - event::resource::{EventFile, EventProp}, + event::resource::{EventProp, EventResource}, Error, }; use actix_web::{ @@ -87,7 +87,7 @@ pub async fn handle_calendar_multiget( for event in events { let path = format!("{}/{}", req.path(), event.get_uid()); responses.push( - EventFile::from(event) + EventResource::from(event) .propfind(prefix, path, props.clone()) .await?, ); diff --git a/crates/caldav/src/calendar/methods/report/calendar_query.rs b/crates/caldav/src/calendar/methods/report/calendar_query.rs index a85bcce..fc40934 100644 --- a/crates/caldav/src/calendar/methods/report/calendar_query.rs +++ b/crates/caldav/src/calendar/methods/report/calendar_query.rs @@ -9,7 +9,7 @@ use serde::Deserialize; use tokio::sync::RwLock; use crate::{ - event::resource::{EventFile, EventProp}, + event::resource::{EventProp, EventResource}, Error, }; @@ -126,7 +126,7 @@ pub async fn handle_calendar_query( for event in events { let path = format!("{}/{}", req.path(), event.get_uid()); responses.push( - EventFile::from(event) + EventResource::from(event) .propfind(prefix, path, props.clone()) .await?, ); diff --git a/crates/caldav/src/calendar/methods/report/sync_collection.rs b/crates/caldav/src/calendar/methods/report/sync_collection.rs index b13f84e..e3bfab8 100644 --- a/crates/caldav/src/calendar/methods/report/sync_collection.rs +++ b/crates/caldav/src/calendar/methods/report/sync_collection.rs @@ -15,7 +15,7 @@ use serde::Deserialize; use tokio::sync::RwLock; use crate::{ - event::resource::{EventFile, EventProp}, + event::resource::{EventProp, EventResource}, Error, }; @@ -73,7 +73,7 @@ pub async fn handle_sync_collection( for event in new_events { let path = format!("{}/{}", req.path(), event.get_uid()); responses.push( - EventFile::from(event) + EventResource::from(event) .propfind(prefix, path, props.clone()) .await?, ); diff --git a/crates/caldav/src/calendar/resource.rs b/crates/caldav/src/calendar/resource.rs index d562109..3890f73 100644 --- a/crates/caldav/src/calendar/resource.rs +++ b/crates/caldav/src/calendar/resource.rs @@ -1,4 +1,4 @@ -use crate::event::resource::EventFile; +use crate::event::resource::EventResource; use crate::Error; use actix_web::{web::Data, HttpRequest}; use anyhow::anyhow; @@ -19,7 +19,7 @@ use super::prop::{ SupportedReportSet, UserPrivilegeSet, }; -pub struct CalendarResource { +pub struct CalendarResourceService { pub cal_store: Arc>, pub path: String, pub principal: String, @@ -89,9 +89,9 @@ impl InvalidProperty for CalendarProp { } #[derive(Clone, Debug, From, Into)] -pub struct CalendarFile(Calendar); +pub struct CalendarResource(Calendar); -impl Resource for CalendarFile { +impl Resource for CalendarResource { type PropName = CalendarPropName; type Prop = CalendarProp; type Error = Error; @@ -226,10 +226,10 @@ impl Resource for CalendarFile { } #[async_trait(?Send)] -impl ResourceService for CalendarResource { - type MemberType = EventFile; +impl ResourceService for CalendarResourceService { + type MemberType = EventResource; type PathComponents = (String, String); // principal, calendar_id - type File = CalendarFile; + type File = CalendarResource; type Error = Error; async fn get_file(&self) -> Result { diff --git a/crates/caldav/src/event/resource.rs b/crates/caldav/src/event/resource.rs index af7ec2a..0fb3a68 100644 --- a/crates/caldav/src/event/resource.rs +++ b/crates/caldav/src/event/resource.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use strum::{EnumString, VariantNames}; use tokio::sync::RwLock; -pub struct EventResource { +pub struct EventResourceService { pub cal_store: Arc>, pub path: String, pub principal: String, @@ -45,9 +45,9 @@ impl InvalidProperty for EventProp { } #[derive(Clone, From, Into)] -pub struct EventFile(Event); +pub struct EventResource(Event); -impl Resource for EventFile { +impl Resource for EventResource { type PropName = EventPropName; type Prop = EventProp; type Error = Error; @@ -64,10 +64,10 @@ impl Resource for EventFile { } #[async_trait(?Send)] -impl ResourceService for EventResource { +impl ResourceService for EventResourceService { type PathComponents = (String, String, String); // principal, calendar, event - type File = EventFile; - type MemberType = EventFile; + type File = EventResource; + type MemberType = EventResource; type Error = Error; async fn new( diff --git a/crates/caldav/src/lib.rs b/crates/caldav/src/lib.rs index d35021e..a55dbf7 100644 --- a/crates/caldav/src/lib.rs +++ b/crates/caldav/src/lib.rs @@ -1,10 +1,10 @@ use actix_web::http::Method; use actix_web::web::{self, Data}; use actix_web::{guard, HttpResponse, Responder}; -use calendar::resource::CalendarResource; -use event::resource::EventResource; -use principal::PrincipalResource; -use root::RootResource; +use calendar::resource::CalendarResourceService; +use event::resource::EventResourceService; +use principal::PrincipalResourceService; +use root::RootResourceService; use rustical_auth::CheckAuthentication; use rustical_dav::methods::{ propfind::ServicePrefix, route_delete, route_propfind, route_proppatch, @@ -55,16 +55,21 @@ pub fn configure_dav( ) .service( web::resource("") - .route(propfind_method().to(route_propfind::)) - .route(proppatch_method().to(route_proppatch::)), + .route(propfind_method().to(route_propfind::)) + .route(proppatch_method().to(route_proppatch::)), ) .service( web::scope("/user").service( web::scope("/{principal}") .service( web::resource("") - .route(propfind_method().to(route_propfind::>)) - .route(proppatch_method().to(route_proppatch::>)), + .route( + propfind_method().to(route_propfind::>), + ) + .route( + proppatch_method() + .to(route_proppatch::>), + ), ) .service( web::scope("/{calendar}") @@ -76,15 +81,16 @@ pub fn configure_dav( ), ) .route( - propfind_method().to(route_propfind::>), + propfind_method() + .to(route_propfind::>), ) .route( proppatch_method() - .to(route_proppatch::>), + .to(route_proppatch::>), ) .route( web::method(Method::DELETE) - .to(route_delete::>), + .to(route_delete::>), ) .route( mkcalendar_method().to( @@ -94,13 +100,17 @@ pub fn configure_dav( ) .service( web::resource("/{event}") - .route(propfind_method().to(route_propfind::>)) .route( - proppatch_method().to(route_proppatch::>), + propfind_method() + .to(route_propfind::>), + ) + .route( + proppatch_method() + .to(route_proppatch::>), ) .route( web::method(Method::DELETE) - .to(route_delete::>), + .to(route_delete::>), ) .route( web::method(Method::GET).to(event::methods::get_event::), diff --git a/crates/caldav/src/principal/mod.rs b/crates/caldav/src/principal/mod.rs index 4a458a5..1e6fd94 100644 --- a/crates/caldav/src/principal/mod.rs +++ b/crates/caldav/src/principal/mod.rs @@ -11,16 +11,16 @@ use std::sync::Arc; use strum::{EnumString, VariantNames}; use tokio::sync::RwLock; -use crate::calendar::resource::CalendarFile; +use crate::calendar::resource::CalendarResource; -pub struct PrincipalResource { +pub struct PrincipalResourceService { principal: String, path: String, cal_store: Arc>, } #[derive(Clone)] -pub struct PrincipalFile { +pub struct PrincipalResource { principal: String, } @@ -63,7 +63,7 @@ pub enum PrincipalPropName { CalendarUserAddressSet, } -impl Resource for PrincipalFile { +impl Resource for PrincipalResource { type PropName = PrincipalPropName; type Prop = PrincipalProp; type Error = Error; @@ -85,10 +85,10 @@ impl Resource for PrincipalFile { } #[async_trait(?Send)] -impl ResourceService for PrincipalResource { +impl ResourceService for PrincipalResourceService { type PathComponents = (String,); - type MemberType = CalendarFile; - type File = PrincipalFile; + type MemberType = CalendarResource; + type File = PrincipalResource; type Error = Error; async fn new( @@ -113,7 +113,7 @@ impl ResourceService for PrincipalResource { } async fn get_file(&self) -> Result { - Ok(PrincipalFile { + Ok(PrincipalResource { principal: self.principal.to_owned(), }) } diff --git a/crates/caldav/src/root/mod.rs b/crates/caldav/src/root/mod.rs index 7597a6b..4c8ebc9 100644 --- a/crates/caldav/src/root/mod.rs +++ b/crates/caldav/src/root/mod.rs @@ -7,7 +7,7 @@ use rustical_dav::xml::HrefElement; use serde::{Deserialize, Serialize}; use strum::{EnumString, VariantNames}; -pub struct RootResource { +pub struct RootResourceService { principal: String, } @@ -41,11 +41,11 @@ impl InvalidProperty for RootProp { } #[derive(Clone)] -pub struct RootFile { +pub struct RootResource { pub principal: String, } -impl Resource for RootFile { +impl Resource for RootResource { type PropName = RootPropName; type Prop = RootProp; type Error = Error; @@ -61,10 +61,10 @@ impl Resource for RootFile { } #[async_trait(?Send)] -impl ResourceService for RootResource { +impl ResourceService for RootResourceService { type PathComponents = (); - type MemberType = RootFile; - type File = RootFile; + type MemberType = RootResource; + type File = RootResource; type Error = Error; async fn new( @@ -78,7 +78,7 @@ impl ResourceService for RootResource { } async fn get_file(&self) -> Result { - Ok(RootFile { + Ok(RootResource { principal: self.principal.to_owned(), }) }