mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
caldav, carddav: Generate Propname enums with strum
This commit is contained in:
@@ -11,7 +11,7 @@ use rustical_store::auth::User;
|
||||
use rustical_store::AddressbookStore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumString, VariantNames};
|
||||
use strum::{EnumDiscriminants, EnumString, VariantNames};
|
||||
|
||||
pub struct PrincipalResourceService<A: AddressbookStore + ?Sized> {
|
||||
principal: String,
|
||||
@@ -23,11 +23,17 @@ pub struct PrincipalResource {
|
||||
principal: String,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, PartialEq)]
|
||||
#[derive(Default, Deserialize, Serialize, PartialEq, EnumDiscriminants)]
|
||||
#[strum_discriminants(
|
||||
name(PrincipalPropName),
|
||||
derive(EnumString, VariantNames),
|
||||
strum(serialize_all = "kebab-case")
|
||||
)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PrincipalProp {
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
#[serde(rename = "principal-URL")]
|
||||
#[strum_discriminants(strum(serialize = "principal-URL"))]
|
||||
PrincipalUrl(HrefElement),
|
||||
|
||||
// CardDAV (RFC 6352)
|
||||
@@ -41,15 +47,6 @@ pub enum PrincipalProp {
|
||||
Invalid,
|
||||
}
|
||||
|
||||
#[derive(EnumString, VariantNames, Clone)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum PrincipalPropName {
|
||||
#[strum(serialize = "principal-URL")]
|
||||
PrincipalUrl,
|
||||
AddressbookHomeSet,
|
||||
PrincipalAddress,
|
||||
}
|
||||
|
||||
impl PrincipalResource {
|
||||
pub fn get_principal_url(rmap: &ResourceMap, principal: &str) -> String {
|
||||
Self::get_url(rmap, vec![principal]).unwrap()
|
||||
@@ -80,6 +77,9 @@ impl Resource for PrincipalResource {
|
||||
PrincipalProp::AddressbookHomeSet(principal_href)
|
||||
}
|
||||
PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None),
|
||||
PrincipalPropName::Invalid => {
|
||||
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user