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

@@ -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())
}