Refactoring that will hopefully make life easier

This commit is contained in:
Lennart
2024-07-28 20:54:31 +02:00
parent 33539e8c7a
commit 99ac654448
8 changed files with 338 additions and 139 deletions

View File

@@ -4,13 +4,12 @@ use crate::namespace::Namespace;
use crate::resource::InvalidProperty;
use crate::resource::Resource;
use crate::resource::ResourceService;
use crate::resource::{PropstatElement, PropstatResponseElement, PropstatType};
use crate::xml::multistatus::{PropstatElement, PropstatWrapper, ResponseElement};
use crate::xml::MultistatusElement;
use crate::xml::TagList;
use crate::xml::TagName;
use crate::Error;
use actix_web::http::StatusCode;
use actix_web::Responder;
use actix_web::{web::Path, HttpRequest};
use log::debug;
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
@@ -55,7 +54,7 @@ pub async fn route_proppatch<A: CheckAuthentication, R: ResourceService + ?Sized
body: String,
req: HttpRequest,
auth: AuthInfoExtractor<A>,
) -> Result<impl Responder, R::Error> {
) -> Result<MultistatusElement<PropstatWrapper<String>, PropstatWrapper<String>>, R::Error> {
let auth_info = auth.inner;
let path_components = path.into_inner();
let href = req.path().to_owned();
@@ -138,25 +137,25 @@ pub async fn route_proppatch<A: CheckAuthentication, R: ResourceService + ?Sized
}
Ok(MultistatusElement {
responses: vec![PropstatResponseElement {
responses: vec![ResponseElement {
href,
propstat: vec![
PropstatType::Normal(PropstatElement {
PropstatWrapper::TagList(PropstatElement {
prop: TagList::from(props_ok),
status: format!("HTTP/1.1 {}", StatusCode::OK),
}),
PropstatType::NotFound(PropstatElement {
PropstatWrapper::TagList(PropstatElement {
prop: TagList::from(props_not_found),
status: format!("HTTP/1.1 {}", StatusCode::NOT_FOUND),
}),
PropstatType::Conflict(PropstatElement {
PropstatWrapper::TagList(PropstatElement {
prop: TagList::from(props_conflict),
status: format!("HTTP/1.1 {}", StatusCode::CONFLICT),
}),
],
}],
// Dummy just for typing
member_responses: Vec::<String>::new(),
member_responses: vec![],
ns_dav: Namespace::Dav.as_str(),
ns_caldav: Namespace::CalDAV.as_str(),
ns_ical: Namespace::ICal.as_str(),