mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-15 08:02:29 +00:00
Reorganise resource methods
This commit is contained in:
@@ -8,11 +8,15 @@ use actix_web::HttpResponse;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::model::CalendarObject;
|
||||
use rustical_store::CalendarStore;
|
||||
use tracing::instrument;
|
||||
use tracing_actix_web::RootSpan;
|
||||
|
||||
#[instrument(parent = root_span.id(), skip(context, path, root_span))]
|
||||
pub async fn get_event<C: CalendarStore + ?Sized>(
|
||||
context: Data<CalDavContext<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
user: User,
|
||||
root_span: RootSpan,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, cid, mut uid) = path.into_inner();
|
||||
|
||||
@@ -46,12 +50,14 @@ pub async fn get_event<C: CalendarStore + ?Sized>(
|
||||
.body(event.get_ics().to_owned()))
|
||||
}
|
||||
|
||||
#[instrument(parent = root_span.id(), skip(context, path, req, root_span))]
|
||||
pub async fn put_event<C: CalendarStore + ?Sized>(
|
||||
context: Data<CalDavContext<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
body: String,
|
||||
user: User,
|
||||
req: HttpRequest,
|
||||
root_span: RootSpan,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, cid, mut uid) = path.into_inner();
|
||||
if user.id != principal {
|
||||
|
||||
@@ -10,6 +10,8 @@ use std::sync::Arc;
|
||||
use strum::{EnumString, VariantNames};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use super::methods::{get_event, put_event};
|
||||
|
||||
pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
||||
pub cal_store: Arc<RwLock<C>>,
|
||||
pub path: String,
|
||||
@@ -130,4 +132,9 @@ impl<C: CalendarStore + ?Sized> ResourceService for CalendarObjectResourceServic
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn actix_additional_routes(res: actix_web::Resource) -> actix_web::Resource {
|
||||
res.get(get_event::<C>).put(put_event::<C>)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user