mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 14:02:29 +00:00
caldav: Refactoring to for consistent terminology between resources and resource services
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
event::resource::{EventFile, EventProp},
|
event::resource::{EventProp, EventResource},
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
@@ -87,7 +87,7 @@ pub async fn handle_calendar_multiget<C: CalendarStore + ?Sized>(
|
|||||||
for event in events {
|
for event in events {
|
||||||
let path = format!("{}/{}", req.path(), event.get_uid());
|
let path = format!("{}/{}", req.path(), event.get_uid());
|
||||||
responses.push(
|
responses.push(
|
||||||
EventFile::from(event)
|
EventResource::from(event)
|
||||||
.propfind(prefix, path, props.clone())
|
.propfind(prefix, path, props.clone())
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use serde::Deserialize;
|
|||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event::resource::{EventFile, EventProp},
|
event::resource::{EventProp, EventResource},
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ pub async fn handle_calendar_query<C: CalendarStore + ?Sized>(
|
|||||||
for event in events {
|
for event in events {
|
||||||
let path = format!("{}/{}", req.path(), event.get_uid());
|
let path = format!("{}/{}", req.path(), event.get_uid());
|
||||||
responses.push(
|
responses.push(
|
||||||
EventFile::from(event)
|
EventResource::from(event)
|
||||||
.propfind(prefix, path, props.clone())
|
.propfind(prefix, path, props.clone())
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use serde::Deserialize;
|
|||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event::resource::{EventFile, EventProp},
|
event::resource::{EventProp, EventResource},
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ pub async fn handle_sync_collection<C: CalendarStore + ?Sized>(
|
|||||||
for event in new_events {
|
for event in new_events {
|
||||||
let path = format!("{}/{}", req.path(), event.get_uid());
|
let path = format!("{}/{}", req.path(), event.get_uid());
|
||||||
responses.push(
|
responses.push(
|
||||||
EventFile::from(event)
|
EventResource::from(event)
|
||||||
.propfind(prefix, path, props.clone())
|
.propfind(prefix, path, props.clone())
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::event::resource::EventFile;
|
use crate::event::resource::EventResource;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
use actix_web::{web::Data, HttpRequest};
|
use actix_web::{web::Data, HttpRequest};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
@@ -19,7 +19,7 @@ use super::prop::{
|
|||||||
SupportedReportSet, UserPrivilegeSet,
|
SupportedReportSet, UserPrivilegeSet,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct CalendarResource<C: CalendarStore + ?Sized> {
|
pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
|
||||||
pub cal_store: Arc<RwLock<C>>,
|
pub cal_store: Arc<RwLock<C>>,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
@@ -89,9 +89,9 @@ impl InvalidProperty for CalendarProp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, From, Into)]
|
#[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 PropName = CalendarPropName;
|
||||||
type Prop = CalendarProp;
|
type Prop = CalendarProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@@ -226,10 +226,10 @@ impl Resource for CalendarFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<C: CalendarStore + ?Sized> ResourceService for CalendarResource<C> {
|
impl<C: CalendarStore + ?Sized> ResourceService for CalendarResourceService<C> {
|
||||||
type MemberType = EventFile;
|
type MemberType = EventResource;
|
||||||
type PathComponents = (String, String); // principal, calendar_id
|
type PathComponents = (String, String); // principal, calendar_id
|
||||||
type File = CalendarFile;
|
type File = CalendarResource;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn get_file(&self) -> Result<Self::File, Error> {
|
async fn get_file(&self) -> Result<Self::File, Error> {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use std::sync::Arc;
|
|||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub struct EventResource<C: CalendarStore + ?Sized> {
|
pub struct EventResourceService<C: CalendarStore + ?Sized> {
|
||||||
pub cal_store: Arc<RwLock<C>>,
|
pub cal_store: Arc<RwLock<C>>,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
@@ -45,9 +45,9 @@ impl InvalidProperty for EventProp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, From, Into)]
|
#[derive(Clone, From, Into)]
|
||||||
pub struct EventFile(Event);
|
pub struct EventResource(Event);
|
||||||
|
|
||||||
impl Resource for EventFile {
|
impl Resource for EventResource {
|
||||||
type PropName = EventPropName;
|
type PropName = EventPropName;
|
||||||
type Prop = EventProp;
|
type Prop = EventProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@@ -64,10 +64,10 @@ impl Resource for EventFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<C: CalendarStore + ?Sized> ResourceService for EventResource<C> {
|
impl<C: CalendarStore + ?Sized> ResourceService for EventResourceService<C> {
|
||||||
type PathComponents = (String, String, String); // principal, calendar, event
|
type PathComponents = (String, String, String); // principal, calendar, event
|
||||||
type File = EventFile;
|
type File = EventResource;
|
||||||
type MemberType = EventFile;
|
type MemberType = EventResource;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn new(
|
async fn new(
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use actix_web::http::Method;
|
use actix_web::http::Method;
|
||||||
use actix_web::web::{self, Data};
|
use actix_web::web::{self, Data};
|
||||||
use actix_web::{guard, HttpResponse, Responder};
|
use actix_web::{guard, HttpResponse, Responder};
|
||||||
use calendar::resource::CalendarResource;
|
use calendar::resource::CalendarResourceService;
|
||||||
use event::resource::EventResource;
|
use event::resource::EventResourceService;
|
||||||
use principal::PrincipalResource;
|
use principal::PrincipalResourceService;
|
||||||
use root::RootResource;
|
use root::RootResourceService;
|
||||||
use rustical_auth::CheckAuthentication;
|
use rustical_auth::CheckAuthentication;
|
||||||
use rustical_dav::methods::{
|
use rustical_dav::methods::{
|
||||||
propfind::ServicePrefix, route_delete, route_propfind, route_proppatch,
|
propfind::ServicePrefix, route_delete, route_propfind, route_proppatch,
|
||||||
@@ -55,16 +55,21 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
|||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("")
|
web::resource("")
|
||||||
.route(propfind_method().to(route_propfind::<A, RootResource>))
|
.route(propfind_method().to(route_propfind::<A, RootResourceService>))
|
||||||
.route(proppatch_method().to(route_proppatch::<A, RootResource>)),
|
.route(proppatch_method().to(route_proppatch::<A, RootResourceService>)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/user").service(
|
web::scope("/user").service(
|
||||||
web::scope("/{principal}")
|
web::scope("/{principal}")
|
||||||
.service(
|
.service(
|
||||||
web::resource("")
|
web::resource("")
|
||||||
.route(propfind_method().to(route_propfind::<A, PrincipalResource<C>>))
|
.route(
|
||||||
.route(proppatch_method().to(route_proppatch::<A, PrincipalResource<C>>)),
|
propfind_method().to(route_propfind::<A, PrincipalResourceService<C>>),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
proppatch_method()
|
||||||
|
.to(route_proppatch::<A, PrincipalResourceService<C>>),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/{calendar}")
|
web::scope("/{calendar}")
|
||||||
@@ -76,15 +81,16 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
propfind_method().to(route_propfind::<A, CalendarResource<C>>),
|
propfind_method()
|
||||||
|
.to(route_propfind::<A, CalendarResourceService<C>>),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
proppatch_method()
|
proppatch_method()
|
||||||
.to(route_proppatch::<A, CalendarResource<C>>),
|
.to(route_proppatch::<A, CalendarResourceService<C>>),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
web::method(Method::DELETE)
|
web::method(Method::DELETE)
|
||||||
.to(route_delete::<A, CalendarResource<C>>),
|
.to(route_delete::<A, CalendarResourceService<C>>),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
mkcalendar_method().to(
|
mkcalendar_method().to(
|
||||||
@@ -94,13 +100,17 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
|||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/{event}")
|
web::resource("/{event}")
|
||||||
.route(propfind_method().to(route_propfind::<A, EventResource<C>>))
|
|
||||||
.route(
|
.route(
|
||||||
proppatch_method().to(route_proppatch::<A, EventResource<C>>),
|
propfind_method()
|
||||||
|
.to(route_propfind::<A, EventResourceService<C>>),
|
||||||
|
)
|
||||||
|
.route(
|
||||||
|
proppatch_method()
|
||||||
|
.to(route_proppatch::<A, EventResourceService<C>>),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
web::method(Method::DELETE)
|
web::method(Method::DELETE)
|
||||||
.to(route_delete::<A, EventResource<C>>),
|
.to(route_delete::<A, EventResourceService<C>>),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
web::method(Method::GET).to(event::methods::get_event::<A, C>),
|
web::method(Method::GET).to(event::methods::get_event::<A, C>),
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ use std::sync::Arc;
|
|||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::calendar::resource::CalendarFile;
|
use crate::calendar::resource::CalendarResource;
|
||||||
|
|
||||||
pub struct PrincipalResource<C: CalendarStore + ?Sized> {
|
pub struct PrincipalResourceService<C: CalendarStore + ?Sized> {
|
||||||
principal: String,
|
principal: String,
|
||||||
path: String,
|
path: String,
|
||||||
cal_store: Arc<RwLock<C>>,
|
cal_store: Arc<RwLock<C>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct PrincipalFile {
|
pub struct PrincipalResource {
|
||||||
principal: String,
|
principal: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ pub enum PrincipalPropName {
|
|||||||
CalendarUserAddressSet,
|
CalendarUserAddressSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resource for PrincipalFile {
|
impl Resource for PrincipalResource {
|
||||||
type PropName = PrincipalPropName;
|
type PropName = PrincipalPropName;
|
||||||
type Prop = PrincipalProp;
|
type Prop = PrincipalProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@@ -85,10 +85,10 @@ impl Resource for PrincipalFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
|
impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResourceService<C> {
|
||||||
type PathComponents = (String,);
|
type PathComponents = (String,);
|
||||||
type MemberType = CalendarFile;
|
type MemberType = CalendarResource;
|
||||||
type File = PrincipalFile;
|
type File = PrincipalResource;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn new(
|
async fn new(
|
||||||
@@ -113,7 +113,7 @@ impl<C: CalendarStore + ?Sized> ResourceService for PrincipalResource<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_file(&self) -> Result<Self::File, Self::Error> {
|
async fn get_file(&self) -> Result<Self::File, Self::Error> {
|
||||||
Ok(PrincipalFile {
|
Ok(PrincipalResource {
|
||||||
principal: self.principal.to_owned(),
|
principal: self.principal.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use rustical_dav::xml::HrefElement;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
|
|
||||||
pub struct RootResource {
|
pub struct RootResourceService {
|
||||||
principal: String,
|
principal: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,11 +41,11 @@ impl InvalidProperty for RootProp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct RootFile {
|
pub struct RootResource {
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resource for RootFile {
|
impl Resource for RootResource {
|
||||||
type PropName = RootPropName;
|
type PropName = RootPropName;
|
||||||
type Prop = RootProp;
|
type Prop = RootProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
@@ -61,10 +61,10 @@ impl Resource for RootFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
impl ResourceService for RootResource {
|
impl ResourceService for RootResourceService {
|
||||||
type PathComponents = ();
|
type PathComponents = ();
|
||||||
type MemberType = RootFile;
|
type MemberType = RootResource;
|
||||||
type File = RootFile;
|
type File = RootResource;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn new(
|
async fn new(
|
||||||
@@ -78,7 +78,7 @@ impl ResourceService for RootResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_file(&self) -> Result<Self::File, Self::Error> {
|
async fn get_file(&self) -> Result<Self::File, Self::Error> {
|
||||||
Ok(RootFile {
|
Ok(RootResource {
|
||||||
principal: self.principal.to_owned(),
|
principal: self.principal.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user