dav: Make the get_members function more ergonomic

This commit is contained in:
Lennart
2025-06-09 20:35:25 +02:00
parent 0feaaaaca1
commit 0595920809
14 changed files with 121 additions and 96 deletions

View File

@@ -6,7 +6,7 @@ use futures_util::future::BoxFuture;
use rustical_dav::{
extensions::{CommonPropertiesExtension, CommonPropertiesProp},
privileges::UserPrivilegeSet,
resource::{AxumMethods, PrincipalUri, Resource, ResourceService},
resource::{AxumMethods, PrincipalUri, Resource, ResourceName, ResourceService},
xml::Resourcetype,
};
use rustical_ical::AddressObject;
@@ -58,6 +58,12 @@ pub struct AddressObjectResource {
pub principal: String,
}
impl ResourceName for AddressObjectResource {
fn get_name(&self) -> String {
format!("{}.vcf", self.object.get_id())
}
}
impl Resource for AddressObjectResource {
type Prop = AddressObjectPropWrapper;
type Error = Error;

View File

@@ -14,7 +14,7 @@ use rustical_dav::extensions::{
CommonPropertiesExtension, CommonPropertiesProp, SyncTokenExtension, SyncTokenExtensionProp,
};
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{AxumMethods, PrincipalUri, Resource, ResourceService};
use rustical_dav::resource::{AxumMethods, PrincipalUri, Resource, ResourceName, ResourceService};
use rustical_dav::xml::{Resourcetype, ResourcetypeInner};
use rustical_dav_push::{DavPushExtension, DavPushExtensionProp};
use rustical_store::auth::User;
@@ -77,6 +77,12 @@ pub enum AddressbookPropWrapper {
#[derive(Clone, Debug, From, Into)]
pub struct AddressbookResource(pub(crate) Addressbook);
impl ResourceName for AddressbookResource {
fn get_name(&self) -> String {
self.0.id.to_owned()
}
}
impl SyncTokenExtension for AddressbookResource {
fn get_synctoken(&self) -> String {
self.0.format_synctoken()
@@ -228,20 +234,15 @@ impl<AS: AddressbookStore, S: SubscriptionStore> ResourceService
async fn get_members(
&self,
(principal, addressbook_id): &Self::PathComponents,
) -> Result<Vec<(String, Self::MemberType)>, Self::Error> {
) -> Result<Vec<Self::MemberType>, Self::Error> {
Ok(self
.addr_store
.get_objects(principal, addressbook_id)
.await?
.into_iter()
.map(|object| {
(
format!("{}.vcf", object.get_id()),
AddressObjectResource {
object,
principal: principal.to_owned(),
},
)
.map(|object| AddressObjectResource {
object,
principal: principal.to_owned(),
})
.collect())
}

View File

@@ -4,7 +4,7 @@ use async_trait::async_trait;
use axum::Router;
use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{AxumMethods, PrincipalUri, Resource, ResourceService};
use rustical_dav::resource::{AxumMethods, PrincipalUri, Resource, ResourceName, ResourceService};
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner};
use rustical_store::auth::{AuthenticationProvider, User};
use rustical_store::{AddressbookStore, SubscriptionStore};
@@ -50,6 +50,12 @@ pub struct PrincipalResource {
principal: User,
}
impl ResourceName for PrincipalResource {
fn get_name(&self) -> String {
self.principal.id.to_owned()
}
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
pub struct AddressbookHomeSet(#[xml(ty = "untagged", flatten)] Vec<HrefElement>);
@@ -168,11 +174,11 @@ impl<A: AddressbookStore, AP: AuthenticationProvider, S: SubscriptionStore> Reso
async fn get_members(
&self,
(principal,): &Self::PathComponents,
) -> Result<Vec<(String, Self::MemberType)>, Self::Error> {
) -> Result<Vec<Self::MemberType>, Self::Error> {
let addressbooks = self.addr_store.get_addressbooks(principal).await?;
Ok(addressbooks
.into_iter()
.map(|addressbook| (addressbook.id.to_owned(), addressbook.into()))
.map(AddressbookResource::from)
.collect())
}