Lots of refactoring around routing

This commit is contained in:
Lennart
2025-06-02 19:41:30 +02:00
parent 08c4bd4289
commit b7c24fe2f0
13 changed files with 245 additions and 212 deletions

View File

@@ -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;
}