mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
use actix_web::{
|
|
http::{header, StatusCode},
|
|
web::{self, Data, Path},
|
|
HttpRequest, HttpResponse, Responder,
|
|
};
|
|
use askama::Template;
|
|
use rustical_store::{auth::User, Calendar, CalendarStore};
|
|
|
|
#[derive(Template)]
|
|
#[template(path = "pages/calendar.html")]
|
|
struct CalendarPage {
|
|
owner: String,
|
|
calendar: Calendar,
|
|
}
|
|
|
|
pub async fn route_calendar<C: CalendarStore + ?Sized>(
|
|
path: Path<(String, String)>,
|
|
store: Data<C>,
|
|
_user: User,
|
|
) -> Result<impl Responder, rustical_store::Error> {
|
|
let (owner, cal_id) = path.into_inner();
|
|
Ok(CalendarPage {
|
|
owner: owner.to_owned(),
|
|
calendar: store.get_calendar(&owner, &cal_id).await?,
|
|
})
|
|
}
|
|
|
|
pub async fn route_calendar_restore<CS: CalendarStore + ?Sized>(
|
|
path: Path<(String, String)>,
|
|
req: HttpRequest,
|
|
store: Data<CS>,
|
|
_user: User,
|
|
) -> Result<impl Responder, rustical_store::Error> {
|
|
let (owner, cal_id) = path.into_inner();
|
|
store.restore_calendar(&owner, &cal_id).await?;
|
|
Ok(match req.headers().get(header::REFERER) {
|
|
Some(referer) => web::Redirect::to(referer.to_str().unwrap().to_owned())
|
|
.using_status_code(StatusCode::FOUND)
|
|
.respond_to(&req)
|
|
.map_into_boxed_body(),
|
|
None => HttpResponse::Ok().body("Restored"),
|
|
})
|
|
}
|