slightly more refactoring

This commit is contained in:
Lennart
2025-06-02 20:18:59 +02:00
parent b7c24fe2f0
commit 3c9c1c7abf
4 changed files with 26 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
use crate::Error;
use crate::addressbook::resource::AddressbookResourceService;
use actix_web::http::header;
use actix_web::web::{Data, Path};
use actix_web::{HttpRequest, HttpResponse};
@@ -9,13 +10,12 @@ use rustical_xml::XmlDocument;
use tracing::instrument;
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>(
path: Path<(String, String)>,
body: String,
user: User,
store: Data<A>,
subscription_store: Data<S>,
resource_service: Data<AddressbookResourceService<A, S>>,
root_span: RootSpan,
req: HttpRequest,
) -> Result<HttpResponse, Error> {
@@ -24,7 +24,8 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
return Err(Error::Unauthorized);
}
let addressbook = store
let addressbook = resource_service
.addr_store
.get_addressbook(&principal, &addressbook_id, false)
.await?;
let request = PushRegister::parse_str(&body)?;
@@ -57,7 +58,10 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
.ty,
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
.resource_map()

View File

@@ -5,7 +5,7 @@ use super::prop::{SupportedAddressData, SupportedReportSet};
use crate::address_object::resource::{AddressObjectResource, AddressObjectResourceService};
use crate::{CardDavPrincipalUri, Error};
use actix_web::http::Method;
use actix_web::web::{self, Data};
use actix_web::web;
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::extensions::{
@@ -22,8 +22,8 @@ use std::str::FromStr;
use std::sync::Arc;
pub struct AddressbookResourceService<AS: AddressbookStore, S: SubscriptionStore> {
addr_store: Arc<AS>,
sub_store: Arc<S>,
pub(crate) addr_store: Arc<AS>,
pub(crate) sub_store: Arc<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 report_method = web::method(Method::from_str("REPORT").unwrap());
web::scope("/{addressbook_id}")
.app_data(Data::from(self.sub_store.clone()))
.service(AddressObjectResourceService::<AS>::new(self.addr_store.clone()).actix_scope())
.service(
self.actix_resource()