use super::{PrincipalUri, Resource}; use crate::Principal; use crate::resource::{AxumMethods, AxumService}; use async_trait::async_trait; use axum::Router; use axum::extract::FromRequestParts; use axum::response::IntoResponse; use serde::Deserialize; #[async_trait] pub trait ResourceService: Clone + Sized + Send + Sync + AxumMethods + 'static { type PathComponents: std::fmt::Debug + for<'de> Deserialize<'de> + Sized + Send + Sync + Clone + 'static; // defines how the resource URI maps to parameters, i.e. /{principal}/{calendar} -> (String, String) type MemberType: Resource + super::ResourceName; type Resource: Resource; type Error: From + Send + Sync + IntoResponse + 'static; type Principal: Principal + FromRequestParts; type PrincipalUri: PrincipalUri; const DAV_HEADER: &'static str; async fn get_members( &self, _path: &Self::PathComponents, ) -> Result, Self::Error> { Ok(vec![]) } async fn get_resource( &self, path: &Self::PathComponents, show_deleted: bool, ) -> Result; async fn save_resource( &self, _path: &Self::PathComponents, _file: Self::Resource, ) -> Result<(), Self::Error> { Err(crate::Error::Unauthorized.into()) } async fn delete_resource( &self, _path: &Self::PathComponents, _use_trashbin: bool, ) -> Result<(), Self::Error> { Err(crate::Error::Unauthorized.into()) } // Returns whether an existing resource was overwritten async fn copy_resource( &self, _path: &Self::PathComponents, _destination: &Self::PathComponents, _user: &Self::Principal, _overwrite: bool, ) -> Result { Err(crate::Error::Forbidden.into()) } // Returns whether an existing resource was overwritten async fn move_resource( &self, _path: &Self::PathComponents, _destination: &Self::PathComponents, _user: &Self::Principal, _overwrite: bool, ) -> Result { Err(crate::Error::Forbidden.into()) } fn axum_service(self) -> AxumService where Self: AxumMethods, { AxumService::new(self) } fn axum_router(self) -> Router { Router::new().route_service("/", self.axum_service()) } }