use axum::response::Redirect; use axum::routing::any; use axum::{Extension, Router}; use derive_more::Constructor; use principal::PrincipalResourceService; use rustical_dav::resource::{PrincipalUri, ResourceService}; use rustical_dav::resources::RootResourceService; use rustical_store::auth::middleware::AuthenticationLayer; use rustical_store::auth::{AuthenticationProvider, User}; use rustical_store::{AddressbookStore, CalendarStore, ContactBirthdayStore, SubscriptionStore}; use std::sync::Arc; pub mod calendar; pub mod calendar_object; pub mod calendar_set; pub mod error; pub mod principal; // mod subscription; pub use error::Error; #[derive(Debug, Clone, Constructor)] pub struct CalDavPrincipalUri(&'static str); impl PrincipalUri for CalDavPrincipalUri { fn principal_uri(&self, principal: &str) -> String { format!("{}/principal/{}", self.0, principal) } } pub fn caldav_router< AP: AuthenticationProvider, AS: AddressbookStore, C: CalendarStore, S: SubscriptionStore, >( prefix: &'static str, auth_provider: Arc, store: Arc, addr_store: Arc, subscription_store: Arc, ) -> Router { let birthday_store = Arc::new(ContactBirthdayStore::new(addr_store)); let principal_service = PrincipalResourceService { auth_provider: auth_provider.clone(), sub_store: subscription_store.clone(), birthday_store: birthday_store.clone(), cal_store: store.clone(), }; Router::new() .nest( prefix, RootResourceService::<_, User, CalDavPrincipalUri>::new(principal_service.clone()) .axum_router() .layer(AuthenticationLayer::new(auth_provider)) .layer(Extension(CalDavPrincipalUri(prefix))), ) .route( "/.well-known/caldav", any(async || Redirect::permanent(prefix)), ) }