Extend the app state

This commit is contained in:
Lennart
2023-09-05 17:00:32 +02:00
parent a87425f632
commit 6b6788ec98
8 changed files with 94 additions and 23 deletions

View File

@@ -3,7 +3,7 @@ use crate::propfind::{
generate_multistatus, parse_propfind, write_invalid_props_response, write_propstat_response,
write_resourcetype,
};
use crate::Error;
use crate::{Context, Error};
use actix_web::http::header::ContentType;
use actix_web::http::StatusCode;
use actix_web::web::{Data, Path};
@@ -17,7 +17,6 @@ use rustical_store::calendar::{Calendar, CalendarStore, Event};
use std::collections::HashSet;
use std::ops::Deref;
use std::sync::Arc;
use tokio::sync::RwLock;
async fn handle_report_calendar_query(
query_node: Node<'_, '_>,
@@ -71,7 +70,7 @@ async fn handle_report_calendar_query(
}
pub async fn route_report_calendar<C: CalendarStore>(
store: Data<RwLock<C>>,
context: Data<Context<C>>,
body: String,
path: Path<(String, String)>,
request: HttpRequest,
@@ -80,7 +79,7 @@ pub async fn route_report_calendar<C: CalendarStore>(
let doc = roxmltree::Document::parse(&body).map_err(|_e| Error::InternalError)?;
let query_node = doc.root_element();
let events = store.read().await.get_events(&cid).await.unwrap();
let events = context.store.read().await.get_events(&cid).await.unwrap();
// TODO: implement filtering
match query_node.tag_name().name() {
@@ -173,10 +172,11 @@ pub async fn route_propfind_calendar<C: CalendarStore>(
body: String,
request: HttpRequest,
auth: BasicAuth,
store: Data<RwLock<C>>,
context: Data<Context<C>>,
) -> Result<HttpResponse, Error> {
let (_principal, cid) = path.into_inner();
let calendar = store
let calendar = context
.store
.read()
.await
.get_calendar(&cid)

View File

@@ -1,18 +1,18 @@
use crate::Error;
use crate::{Context, Error};
use actix_web::web::{Data, Path};
use actix_web::HttpResponse;
use rustical_store::calendar::CalendarStore;
use tokio::sync::RwLock;
pub async fn delete_event<C: CalendarStore>(
store: Data<RwLock<C>>,
context: Data<Context<C>>,
path: Path<(String, String, String)>,
) -> Result<HttpResponse, Error> {
let (_principal, mut cid, uid) = path.into_inner();
if cid.ends_with(".ics") {
cid.truncate(cid.len() - 4);
}
store
context
.store
.write()
.await
.delete_event(&uid)
@@ -23,14 +23,15 @@ pub async fn delete_event<C: CalendarStore>(
}
pub async fn get_event<C: CalendarStore>(
store: Data<RwLock<C>>,
context: Data<Context<C>>,
path: Path<(String, String, String)>,
) -> Result<HttpResponse, Error> {
let (_principal, mut cid, uid) = path.into_inner();
if cid.ends_with(".ics") {
cid.truncate(cid.len() - 4);
}
let event = store
let event = context
.store
.read()
.await
.get_event(&uid)
@@ -43,7 +44,7 @@ pub async fn get_event<C: CalendarStore>(
}
pub async fn put_event<C: CalendarStore>(
store: Data<RwLock<C>>,
context: Data<Context<C>>,
path: Path<(String, String, String)>,
body: String,
) -> Result<HttpResponse, Error> {
@@ -53,7 +54,8 @@ pub async fn put_event<C: CalendarStore>(
cid.truncate(cid.len() - 4);
}
dbg!(&body);
store
context
.store
.write()
.await
.upsert_event(uid, body)

View File

@@ -6,7 +6,7 @@ use crate::{
generate_multistatus, parse_propfind, write_invalid_props_response,
write_propstat_response, write_resourcetype,
},
Error,
Context, Error,
};
use actix_web::{
http::{header::ContentType, StatusCode},
@@ -20,7 +20,6 @@ use quick_xml::{
Writer,
};
use rustical_store::calendar::CalendarStore;
use tokio::sync::RwLock;
// Executes the PROPFIND request and returns a XML string to be written into a <mulstistatus> object.
pub async fn generate_propfind_principal_response(
@@ -90,7 +89,7 @@ pub async fn route_propfind_principal<C: CalendarStore>(
body: String,
request: HttpRequest,
auth: BasicAuth,
store: Data<RwLock<C>>,
context: Data<Context<C>>,
depth: Depth,
) -> Result<HttpResponse, Error> {
let props = parse_propfind(&body).map_err(|_e| Error::BadRequest)?;
@@ -98,7 +97,8 @@ pub async fn route_propfind_principal<C: CalendarStore>(
let mut responses = Vec::new();
// also get calendars:
if depth != Depth::Zero {
let cals = store
let cals = context
.store
.read()
.await
.get_calendars()