mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
store: Add get_deleted_(addressbooks/calendars)
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
use crate::synctoken::format_synctoken;
|
use crate::synctoken::format_synctoken;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct Addressbook {
|
pub struct Addressbook {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use async_trait::async_trait;
|
|||||||
pub trait AddressbookStore: Send + Sync + 'static {
|
pub trait AddressbookStore: Send + Sync + 'static {
|
||||||
async fn get_addressbook(&self, principal: &str, id: &str) -> Result<Addressbook, Error>;
|
async fn get_addressbook(&self, principal: &str, id: &str) -> Result<Addressbook, Error>;
|
||||||
async fn get_addressbooks(&self, principal: &str) -> Result<Vec<Addressbook>, Error>;
|
async fn get_addressbooks(&self, principal: &str) -> Result<Vec<Addressbook>, Error>;
|
||||||
|
async fn get_deleted_addressbooks(&self, principal: &str) -> Result<Vec<Addressbook>, Error>;
|
||||||
|
|
||||||
async fn update_addressbook(
|
async fn update_addressbook(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::synctoken::format_synctoken;
|
use crate::synctoken::format_synctoken;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
|
#[derive(Debug, Default, Clone, Serialize)]
|
||||||
pub struct Calendar {
|
pub struct Calendar {
|
||||||
pub principal: String,
|
pub principal: String,
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use async_trait::async_trait;
|
|||||||
pub trait CalendarStore: Send + Sync + 'static {
|
pub trait CalendarStore: Send + Sync + 'static {
|
||||||
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error>;
|
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error>;
|
||||||
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
||||||
|
async fn get_deleted_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error>;
|
||||||
|
|
||||||
async fn update_calendar(
|
async fn update_calendar(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -93,6 +93,24 @@ impl AddressbookStore for SqliteStore {
|
|||||||
Ok(addressbooks)
|
Ok(addressbooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
async fn get_deleted_addressbooks(
|
||||||
|
&self,
|
||||||
|
principal: &str,
|
||||||
|
) -> Result<Vec<Addressbook>, rustical_store::Error> {
|
||||||
|
let addressbooks = sqlx::query_as!(
|
||||||
|
Addressbook,
|
||||||
|
r#"SELECT principal, id, synctoken, displayname, description, deleted_at
|
||||||
|
FROM addressbooks
|
||||||
|
WHERE principal = ? AND deleted_at IS NOT NULL"#,
|
||||||
|
principal
|
||||||
|
)
|
||||||
|
.fetch_all(&self.db)
|
||||||
|
.await
|
||||||
|
.map_err(crate::Error::from)?;
|
||||||
|
Ok(addressbooks)
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn update_addressbook(
|
async fn update_addressbook(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -87,6 +87,20 @@ impl CalendarStore for SqliteStore {
|
|||||||
Ok(cals)
|
Ok(cals)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument]
|
||||||
|
async fn get_deleted_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error> {
|
||||||
|
let cals = sqlx::query_as!(
|
||||||
|
Calendar,
|
||||||
|
r#"SELECT principal, id, synctoken, displayname, "order", description, color, timezone, deleted_at
|
||||||
|
FROM calendars
|
||||||
|
WHERE principal = ? AND deleted_at IS NOT NULL"#,
|
||||||
|
principal
|
||||||
|
)
|
||||||
|
.fetch_all(&self.db)
|
||||||
|
.await.map_err(crate::Error::from)?;
|
||||||
|
Ok(cals)
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> {
|
async fn insert_calendar(&self, calendar: Calendar) -> Result<(), Error> {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
|
|||||||
Reference in New Issue
Block a user