mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 02:22:21 +00:00
birthday calendar, lots of refactoring
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use actix_web::dev::{AppService, HttpServiceFactory};
|
||||
use actix_web::error::UrlGenerationError;
|
||||
use actix_web::test::TestRequest;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{dev::ResourceMap, http::Method, web, ResponseError};
|
||||
use async_trait::async_trait;
|
||||
use serde::Deserialize;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::methods::{route_delete, route_propfind, route_proppatch};
|
||||
use super::Resource;
|
||||
@@ -17,8 +19,7 @@ pub trait ResourceService: Sized + 'static {
|
||||
|
||||
async fn get_members(
|
||||
&self,
|
||||
_path: &Self::PathComponents,
|
||||
_rmap: &ResourceMap,
|
||||
_path_components: &Self::PathComponents,
|
||||
) -> Result<Vec<(String, Self::MemberType)>, Self::Error> {
|
||||
Ok(vec![])
|
||||
}
|
||||
@@ -42,17 +43,11 @@ pub trait ResourceService: Sized + 'static {
|
||||
Err(crate::Error::Unauthorized.into())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn resource_name() -> &'static str {
|
||||
Self::Resource::resource_name()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn actix_resource(self) -> actix_web::Resource {
|
||||
Self::actix_additional_routes(
|
||||
web::resource("")
|
||||
.app_data(Data::new(self))
|
||||
.name(Self::resource_name())
|
||||
.route(
|
||||
web::method(Method::from_str("PROPFIND").unwrap()).to(route_propfind::<Self>),
|
||||
)
|
||||
@@ -69,3 +64,30 @@ pub trait ResourceService: Sized + 'static {
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
pub trait NamedRoute {
|
||||
fn route_name() -> &'static str;
|
||||
|
||||
fn get_url<U, I>(rmap: &ResourceMap, elements: U) -> Result<String, UrlGenerationError>
|
||||
where
|
||||
U: IntoIterator<Item = I>,
|
||||
I: AsRef<str>,
|
||||
{
|
||||
Ok(rmap
|
||||
.url_for(
|
||||
&TestRequest::default().to_http_request(),
|
||||
Self::route_name(),
|
||||
elements,
|
||||
)?
|
||||
.path()
|
||||
.to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user