mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-27 04:09:27 +00:00
Add birthday calendar creation to frontend
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
use axum::{Extension, extract::Path, response::IntoResponse};
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Addressbook, AddressbookStore, CollectionMetadata, auth::Principal};
|
||||
use rustical_store::{
|
||||
Addressbook, AddressbookStore, Calendar, CollectionMetadata, PrefixedCalendarStore,
|
||||
auth::Principal,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::pages::user::{Section, UserPage};
|
||||
|
||||
@@ -18,11 +20,11 @@ impl Section for AddressbooksSection {
|
||||
#[template(path = "components/sections/addressbooks_section.html")]
|
||||
pub struct AddressbooksSection {
|
||||
pub user: Principal,
|
||||
pub addressbooks: Vec<(CollectionMetadata, Addressbook)>,
|
||||
pub deleted_addressbooks: Vec<(CollectionMetadata, Addressbook)>,
|
||||
pub addressbooks: Vec<(CollectionMetadata, Option<Calendar>, Addressbook)>,
|
||||
pub deleted_addressbooks: Vec<(CollectionMetadata, Option<Calendar>, Addressbook)>,
|
||||
}
|
||||
|
||||
pub async fn route_addressbooks<AS: AddressbookStore>(
|
||||
pub async fn route_addressbooks<AS: AddressbookStore + PrefixedCalendarStore>(
|
||||
Path(user_id): Path<String>,
|
||||
Extension(addr_store): Extension<Arc<AS>>,
|
||||
user: Principal,
|
||||
@@ -43,22 +45,42 @@ pub async fn route_addressbooks<AS: AddressbookStore>(
|
||||
|
||||
let mut addressbook_infos = vec![];
|
||||
for addressbook in addressbooks {
|
||||
let birthday_id = format!("{}{}", AS::PREFIX, &addressbook.id);
|
||||
let birthday_cal = match addr_store
|
||||
.get_calendar(&addressbook.principal, &birthday_id, true)
|
||||
.await
|
||||
{
|
||||
Ok(cal) => Some(cal),
|
||||
Err(rustical_store::Error::NotFound) => None,
|
||||
err => Some(err.unwrap()),
|
||||
};
|
||||
addressbook_infos.push((
|
||||
addr_store
|
||||
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
||||
.await
|
||||
.unwrap(),
|
||||
birthday_cal,
|
||||
addressbook,
|
||||
));
|
||||
}
|
||||
|
||||
let mut deleted_addressbook_infos = vec![];
|
||||
for addressbook in deleted_addressbooks {
|
||||
let birthday_id = format!("{}{}", AS::PREFIX, &addressbook.id);
|
||||
let birthday_cal = match addr_store
|
||||
.get_calendar(&addressbook.principal, &birthday_id, true)
|
||||
.await
|
||||
{
|
||||
Ok(cal) => Some(cal),
|
||||
Err(rustical_store::Error::NotFound) => None,
|
||||
err => Some(err.unwrap()),
|
||||
};
|
||||
deleted_addressbook_infos.push((
|
||||
addr_store
|
||||
.addressbook_metadata(&addressbook.principal, &addressbook.id)
|
||||
.await
|
||||
.unwrap(),
|
||||
birthday_cal,
|
||||
addressbook,
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user