From 4490afb1bfef7af4afe8ada9c99f9bf7925ad40e Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 1 Mar 2024 18:20:51 +0100 Subject: Implement propertyupdate --- src/dav/encoder.rs | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/dav/encoder.rs b/src/dav/encoder.rs index 4a9bcf4..41e93f3 100644 --- a/src/dav/encoder.rs +++ b/src/dav/encoder.rs @@ -81,7 +81,14 @@ impl QuickWritable for PropFind { /// PROPPATCH REQUEST impl QuickWritable for PropertyUpdate { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { - unimplemented!(); + let start = ctx.create_dav_element("propertyupdate"); + let end = start.to_end(); + + xml.write_event_async(Event::Start(start.clone())).await?; + for update in self.0.iter() { + update.write(xml, ctx.child()).await?; + } + xml.write_event_async(Event::End(end)).await } } @@ -137,6 +144,36 @@ impl QuickWritable for PropValue { } // --- XML inner elements +impl QuickWritable for PropertyUpdateItem { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + match self { + Self::Set(set) => set.write(xml, ctx).await, + Self::Remove(rm) => rm.write(xml, ctx).await, + } + } +} + +impl QuickWritable for Set { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let start = ctx.create_dav_element("set"); + let end = start.to_end(); + xml.write_event_async(Event::Start(start.clone())).await?; + self.0.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await + } +} + +impl QuickWritable for Remove { + async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { + let start = ctx.create_dav_element("remove"); + let end = start.to_end(); + xml.write_event_async(Event::Start(start.clone())).await?; + self.0.write(xml, ctx.child()).await?; + xml.write_event_async(Event::End(end)).await + } +} + + impl QuickWritable for AnyProp { async fn write(&self, xml: &mut Writer, ctx: C) -> Result<(), QError> { match self { @@ -998,8 +1035,12 @@ mod tests { let got = serialize( NoExtension { root: true }, &PropertyUpdate(vec![ - PropertyUpdateItem::Set(Set(PropValue(vec![ ]))), - PropertyUpdateItem::Remove(Remove(PropName(vec![]))), + PropertyUpdateItem::Set(Set(PropValue(vec![ + Property::GetContentLanguage("fr-FR".into()), + ]))), + PropertyUpdateItem::Remove(Remove(PropName(vec![ + PropertyRequest::DisplayName, + ]))), ]), ).await; -- cgit v1.2.3