mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
Lots of refactoring around routing
This commit is contained in:
@@ -44,8 +44,6 @@ pub(crate) async fn route_propfind<R: ResourceService>(
|
||||
}
|
||||
};
|
||||
|
||||
dbg!(&propfind);
|
||||
|
||||
// TODO: respect namespaces?
|
||||
let props = match &propfind.prop {
|
||||
PropfindType::Allprop => vec!["allprop"],
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use super::methods::{route_delete, route_propfind, route_proppatch};
|
||||
use super::{PrincipalUri, Resource};
|
||||
use crate::Principal;
|
||||
use actix_web::dev::{AppService, HttpServiceFactory};
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{ResponseError, http::Method, web};
|
||||
use async_trait::async_trait;
|
||||
@@ -47,30 +46,12 @@ pub trait ResourceService: Sized + 'static {
|
||||
|
||||
#[inline]
|
||||
fn actix_resource(self) -> actix_web::Resource {
|
||||
Self::actix_additional_routes(
|
||||
web::resource("")
|
||||
.app_data(Data::new(self))
|
||||
.route(
|
||||
web::method(Method::from_str("PROPFIND").unwrap()).to(route_propfind::<Self>),
|
||||
)
|
||||
.route(
|
||||
web::method(Method::from_str("PROPPATCH").unwrap()).to(route_proppatch::<Self>),
|
||||
)
|
||||
.delete(route_delete::<Self>),
|
||||
)
|
||||
web::resource("")
|
||||
.app_data(Data::new(self))
|
||||
.route(web::method(Method::from_str("PROPFIND").unwrap()).to(route_propfind::<Self>))
|
||||
.route(web::method(Method::from_str("PROPPATCH").unwrap()).to(route_proppatch::<Self>))
|
||||
.delete(route_delete::<Self>)
|
||||
}
|
||||
|
||||
/// Hook for other resources to insert their additional methods (i.e. REPORT, MKCALENDAR)
|
||||
#[inline]
|
||||
fn actix_additional_routes(res: actix_web::Resource) -> actix_web::Resource {
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ResourceServiceRoute<RS: ResourceService>(pub RS);
|
||||
|
||||
impl<RS: ResourceService> HttpServiceFactory for ResourceServiceRoute<RS> {
|
||||
fn register(self, config: &mut AppService) {
|
||||
self.0.actix_resource().register(config);
|
||||
}
|
||||
fn actix_scope(self) -> actix_web::Scope;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::extensions::{
|
||||
use crate::privileges::UserPrivilegeSet;
|
||||
use crate::resource::{PrincipalUri, Resource, ResourceService};
|
||||
use crate::xml::{Resourcetype, ResourcetypeInner};
|
||||
use actix_web::web;
|
||||
use async_trait::async_trait;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
@@ -44,30 +45,38 @@ impl<PR: Resource, P: Principal> Resource for RootResource<PR, P> {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RootResourceService<PR: Resource, P: Principal, PURI: PrincipalUri>(
|
||||
PhantomData<PR>,
|
||||
pub struct RootResourceService<PRS: ResourceService + Clone, P: Principal, PURI: PrincipalUri>(
|
||||
PRS,
|
||||
PhantomData<P>,
|
||||
PhantomData<PURI>,
|
||||
);
|
||||
|
||||
impl<PR: Resource, P: Principal, PURI: PrincipalUri> Default for RootResourceService<PR, P, PURI> {
|
||||
fn default() -> Self {
|
||||
Self(PhantomData, PhantomData, PhantomData)
|
||||
impl<PRS: ResourceService + Clone, P: Principal, PURI: PrincipalUri>
|
||||
RootResourceService<PRS, P, PURI>
|
||||
{
|
||||
pub fn new(principal_resource_service: PRS) -> Self {
|
||||
Self(principal_resource_service, PhantomData, PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl<PR: Resource<Principal = P>, P: Principal, PURI: PrincipalUri> ResourceService
|
||||
for RootResourceService<PR, P, PURI>
|
||||
impl<PRS: ResourceService<Principal = P> + Clone, P: Principal, PURI: PrincipalUri> ResourceService
|
||||
for RootResourceService<PRS, P, PURI>
|
||||
{
|
||||
type PathComponents = ();
|
||||
type MemberType = PR;
|
||||
type Resource = RootResource<PR, P>;
|
||||
type Error = PR::Error;
|
||||
type MemberType = PRS::Resource;
|
||||
type Resource = RootResource<PRS::Resource, P>;
|
||||
type Error = PRS::Error;
|
||||
type Principal = P;
|
||||
type PrincipalUri = PURI;
|
||||
|
||||
async fn get_resource(&self, _: &()) -> Result<Self::Resource, Self::Error> {
|
||||
Ok(RootResource::<PR, P>::default())
|
||||
Ok(RootResource::<PRS::Resource, P>::default())
|
||||
}
|
||||
|
||||
fn actix_scope(self) -> actix_web::Scope {
|
||||
web::scope("")
|
||||
.service(self.0.clone().actix_scope())
|
||||
.service(self.actix_resource())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user