mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-20 09:39:28 +00:00
Extend the app state
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user