mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 18:12:27 +00:00
slightly more refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::Error;
|
use crate::Error;
|
||||||
use crate::calendar::resource::CalendarResource;
|
use crate::calendar::resource::{CalendarResource, CalendarResourceService};
|
||||||
use actix_web::http::header;
|
use actix_web::http::header;
|
||||||
use actix_web::web::{Data, Path};
|
use actix_web::web::{Data, Path};
|
||||||
use actix_web::{HttpRequest, HttpResponse};
|
use actix_web::{HttpRequest, HttpResponse};
|
||||||
@@ -12,13 +12,12 @@ use rustical_xml::XmlDocument;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use tracing_actix_web::RootSpan;
|
use tracing_actix_web::RootSpan;
|
||||||
|
|
||||||
#[instrument(parent = root_span.id(), skip(store, subscription_store, root_span, req))]
|
#[instrument(parent = root_span.id(), skip(resource_service, root_span, req))]
|
||||||
pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
||||||
path: Path<(String, String)>,
|
path: Path<(String, String)>,
|
||||||
body: String,
|
body: String,
|
||||||
user: User,
|
user: User,
|
||||||
store: Data<C>,
|
resource_service: Data<CalendarResourceService<C, S>>,
|
||||||
subscription_store: Data<S>,
|
|
||||||
root_span: RootSpan,
|
root_span: RootSpan,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
@@ -27,7 +26,10 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
return Err(Error::Unauthorized);
|
return Err(Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let calendar = store.get_calendar(&principal, &cal_id).await?;
|
let calendar = resource_service
|
||||||
|
.cal_store
|
||||||
|
.get_calendar(&principal, &cal_id)
|
||||||
|
.await?;
|
||||||
let calendar_resource = CalendarResource {
|
let calendar_resource = CalendarResource {
|
||||||
cal: calendar,
|
cal: calendar,
|
||||||
read_only: true,
|
read_only: true,
|
||||||
@@ -70,7 +72,10 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
|
|||||||
.ty,
|
.ty,
|
||||||
auth_secret: request.subscription.web_push_subscription.auth_secret,
|
auth_secret: request.subscription.web_push_subscription.auth_secret,
|
||||||
};
|
};
|
||||||
subscription_store.upsert_subscription(subscription).await?;
|
resource_service
|
||||||
|
.sub_store
|
||||||
|
.upsert_subscription(subscription)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let location = req
|
let location = req
|
||||||
.resource_map()
|
.resource_map()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use super::prop::{SupportedCalendarComponentSet, SupportedCalendarData, Supporte
|
|||||||
use crate::calendar_object::resource::{CalendarObjectResource, CalendarObjectResourceService};
|
use crate::calendar_object::resource::{CalendarObjectResource, CalendarObjectResourceService};
|
||||||
use crate::{CalDavPrincipalUri, Error};
|
use crate::{CalDavPrincipalUri, Error};
|
||||||
use actix_web::http::Method;
|
use actix_web::http::Method;
|
||||||
use actix_web::web::{self, Data};
|
use actix_web::web::{self};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
@@ -309,8 +309,8 @@ impl Resource for CalendarResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> {
|
pub struct CalendarResourceService<C: CalendarStore, S: SubscriptionStore> {
|
||||||
cal_store: Arc<C>,
|
pub(crate) cal_store: Arc<C>,
|
||||||
sub_store: Arc<S>,
|
pub(crate) sub_store: Arc<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
impl<C: CalendarStore, S: SubscriptionStore> CalendarResourceService<C, S> {
|
||||||
@@ -389,7 +389,6 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
|||||||
let report_method = web::method(Method::from_str("REPORT").unwrap());
|
let report_method = web::method(Method::from_str("REPORT").unwrap());
|
||||||
let mkcalendar_method = web::method(Method::from_str("MKCALENDAR").unwrap());
|
let mkcalendar_method = web::method(Method::from_str("MKCALENDAR").unwrap());
|
||||||
web::scope("/{calendar_id}")
|
web::scope("/{calendar_id}")
|
||||||
.app_data(Data::from(self.sub_store.clone()))
|
|
||||||
.service(CalendarObjectResourceService::new(self.cal_store.clone()).actix_scope())
|
.service(CalendarObjectResourceService::new(self.cal_store.clone()).actix_scope())
|
||||||
.service(
|
.service(
|
||||||
self.actix_resource()
|
self.actix_resource()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
use crate::addressbook::resource::AddressbookResourceService;
|
||||||
use actix_web::http::header;
|
use actix_web::http::header;
|
||||||
use actix_web::web::{Data, Path};
|
use actix_web::web::{Data, Path};
|
||||||
use actix_web::{HttpRequest, HttpResponse};
|
use actix_web::{HttpRequest, HttpResponse};
|
||||||
@@ -9,13 +10,12 @@ use rustical_xml::XmlDocument;
|
|||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use tracing_actix_web::RootSpan;
|
use tracing_actix_web::RootSpan;
|
||||||
|
|
||||||
#[instrument(parent = root_span.id(), skip(store, subscription_store, root_span, req))]
|
#[instrument(parent = root_span.id(), skip(resource_service, root_span, req))]
|
||||||
pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
||||||
path: Path<(String, String)>,
|
path: Path<(String, String)>,
|
||||||
body: String,
|
body: String,
|
||||||
user: User,
|
user: User,
|
||||||
store: Data<A>,
|
resource_service: Data<AddressbookResourceService<A, S>>,
|
||||||
subscription_store: Data<S>,
|
|
||||||
root_span: RootSpan,
|
root_span: RootSpan,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
@@ -24,7 +24,8 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
|||||||
return Err(Error::Unauthorized);
|
return Err(Error::Unauthorized);
|
||||||
}
|
}
|
||||||
|
|
||||||
let addressbook = store
|
let addressbook = resource_service
|
||||||
|
.addr_store
|
||||||
.get_addressbook(&principal, &addressbook_id, false)
|
.get_addressbook(&principal, &addressbook_id, false)
|
||||||
.await?;
|
.await?;
|
||||||
let request = PushRegister::parse_str(&body)?;
|
let request = PushRegister::parse_str(&body)?;
|
||||||
@@ -57,7 +58,10 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
|||||||
.ty,
|
.ty,
|
||||||
auth_secret: request.subscription.web_push_subscription.auth_secret,
|
auth_secret: request.subscription.web_push_subscription.auth_secret,
|
||||||
};
|
};
|
||||||
subscription_store.upsert_subscription(subscription).await?;
|
resource_service
|
||||||
|
.sub_store
|
||||||
|
.upsert_subscription(subscription)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let location = req
|
let location = req
|
||||||
.resource_map()
|
.resource_map()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use super::prop::{SupportedAddressData, SupportedReportSet};
|
|||||||
use crate::address_object::resource::{AddressObjectResource, AddressObjectResourceService};
|
use crate::address_object::resource::{AddressObjectResource, AddressObjectResourceService};
|
||||||
use crate::{CardDavPrincipalUri, Error};
|
use crate::{CardDavPrincipalUri, Error};
|
||||||
use actix_web::http::Method;
|
use actix_web::http::Method;
|
||||||
use actix_web::web::{self, Data};
|
use actix_web::web;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use derive_more::derive::{From, Into};
|
use derive_more::derive::{From, Into};
|
||||||
use rustical_dav::extensions::{
|
use rustical_dav::extensions::{
|
||||||
@@ -22,8 +22,8 @@ use std::str::FromStr;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub struct AddressbookResourceService<AS: AddressbookStore, S: SubscriptionStore> {
|
pub struct AddressbookResourceService<AS: AddressbookStore, S: SubscriptionStore> {
|
||||||
addr_store: Arc<AS>,
|
pub(crate) addr_store: Arc<AS>,
|
||||||
sub_store: Arc<S>,
|
pub(crate) sub_store: Arc<S>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: AddressbookStore, S: SubscriptionStore> AddressbookResourceService<A, S> {
|
impl<A: AddressbookStore, S: SubscriptionStore> AddressbookResourceService<A, S> {
|
||||||
@@ -259,7 +259,6 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
|
|||||||
let mkcol_method = web::method(Method::from_str("MKCOL").unwrap());
|
let mkcol_method = web::method(Method::from_str("MKCOL").unwrap());
|
||||||
let report_method = web::method(Method::from_str("REPORT").unwrap());
|
let report_method = web::method(Method::from_str("REPORT").unwrap());
|
||||||
web::scope("/{addressbook_id}")
|
web::scope("/{addressbook_id}")
|
||||||
.app_data(Data::from(self.sub_store.clone()))
|
|
||||||
.service(AddressObjectResourceService::<AS>::new(self.addr_store.clone()).actix_scope())
|
.service(AddressObjectResourceService::<AS>::new(self.addr_store.clone()).actix_scope())
|
||||||
.service(
|
.service(
|
||||||
self.actix_resource()
|
self.actix_resource()
|
||||||
|
|||||||
Reference in New Issue
Block a user