mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 05:52:19 +00:00
move CalendarStore to separate file
This commit is contained in:
@@ -5,7 +5,7 @@ use actix_web::{
|
||||
HttpResponse,
|
||||
};
|
||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::store::CalendarStore;
|
||||
|
||||
pub async fn route_delete_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
||||
context: Data<CalDavContext<C>>,
|
||||
|
||||
@@ -4,8 +4,8 @@ use actix_web::web::{Data, Path};
|
||||
use actix_web::HttpResponse;
|
||||
use anyhow::Result;
|
||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||
use rustical_dav::xml::tag_list::TagList;
|
||||
use rustical_store::calendar::{Calendar, CalendarStore};
|
||||
use rustical_store::calendar::Calendar;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Clone, Debug)]
|
||||
|
||||
@@ -9,7 +9,8 @@ use rustical_dav::{
|
||||
propfind::{MultistatusElement, PropElement, PropfindType, ServicePrefix},
|
||||
resource::HandlePropfind,
|
||||
};
|
||||
use rustical_store::{calendar::CalendarStore, event::Event};
|
||||
use rustical_store::event::Event;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ use rustical_auth::AuthInfo;
|
||||
use rustical_dav::error::Error;
|
||||
use rustical_dav::resource::{Resource, ResourceService};
|
||||
use rustical_dav::xml_snippets::{HrefElement, TextNode};
|
||||
use rustical_store::calendar::{Calendar, CalendarStore};
|
||||
use rustical_store::calendar::Calendar;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumString, IntoStaticStr, VariantNames};
|
||||
|
||||
@@ -3,7 +3,7 @@ use actix_web::http::StatusCode;
|
||||
use actix_web::web::{Data, Path};
|
||||
use actix_web::{HttpResponse, ResponseError};
|
||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
||||
@@ -5,8 +5,8 @@ use rustical_auth::AuthInfo;
|
||||
use rustical_dav::error::Error;
|
||||
use rustical_dav::resource::{Resource, ResourceService};
|
||||
use rustical_dav::xml_snippets::TextNode;
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::event::Event;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use serde::Serialize;
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumString, IntoStaticStr, VariantNames};
|
||||
|
||||
@@ -8,7 +8,7 @@ use root::RootResource;
|
||||
use rustical_auth::CheckAuthentication;
|
||||
use rustical_dav::error::Error;
|
||||
use rustical_dav::propfind::{route_propfind, ServicePrefix};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
@@ -7,7 +7,7 @@ use async_trait::async_trait;
|
||||
use rustical_auth::AuthInfo;
|
||||
use rustical_dav::resource::{Resource, ResourceService};
|
||||
use rustical_dav::xml_snippets::HrefElement;
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use serde::Serialize;
|
||||
use strum::{EnumString, IntoStaticStr, VariantNames};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
use crate::event::Event;
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
|
||||
@@ -12,16 +9,3 @@ pub struct Calendar {
|
||||
pub color: Option<String>,
|
||||
pub timezone: Option<String>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendar(&self, id: &str) -> Result<Calendar>;
|
||||
async fn get_calendars(&self, owner: &str) -> Result<Vec<Calendar>>;
|
||||
async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<()>;
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<()>;
|
||||
|
||||
async fn get_events(&self, cid: &str) -> Result<Vec<Event>>;
|
||||
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event>;
|
||||
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()>;
|
||||
async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod calendar;
|
||||
pub mod event;
|
||||
pub mod sqlite_store;
|
||||
pub mod store;
|
||||
pub mod timestamps;
|
||||
pub mod toml_store;
|
||||
|
||||
@@ -2,10 +2,7 @@ use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
|
||||
|
||||
use crate::{
|
||||
calendar::{Calendar, CalendarStore},
|
||||
event::Event,
|
||||
};
|
||||
use crate::{calendar::Calendar, event::Event, store::CalendarStore};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SqliteCalendarStore {
|
||||
|
||||
17
crates/store/src/store.rs
Normal file
17
crates/store/src/store.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use anyhow::Result;
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{calendar::Calendar, event::Event};
|
||||
|
||||
#[async_trait]
|
||||
pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendar(&self, id: &str) -> Result<Calendar>;
|
||||
async fn get_calendars(&self, owner: &str) -> Result<Vec<Calendar>>;
|
||||
async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<()>;
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<()>;
|
||||
|
||||
async fn get_events(&self, cid: &str) -> Result<Vec<Event>>;
|
||||
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event>;
|
||||
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()>;
|
||||
async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()>;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::calendar::{Calendar, CalendarStore};
|
||||
use crate::calendar::Calendar;
|
||||
use crate::event::Event;
|
||||
use crate::store::CalendarStore;
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use rstest::rstest;
|
||||
use rstest_reuse::{self, apply, template};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::sqlite_store::create_test_store;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use rustical_store::toml_store::TomlCalendarStore;
|
||||
|
||||
const TIMEZONE: &str = include_str!("examples/timezone.ics");
|
||||
|
||||
@@ -5,7 +5,7 @@ use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse};
|
||||
use actix_web::middleware::{Logger, NormalizePath};
|
||||
use actix_web::{web, App};
|
||||
use rustical_auth::CheckAuthentication;
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::store::CalendarStore;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub fn make_app<CS: CalendarStore + ?Sized, A: CheckAuthentication>(
|
||||
|
||||
@@ -5,8 +5,8 @@ use app::make_app;
|
||||
use clap::Parser;
|
||||
use config::{CalendarStoreConfig, SqliteCalendarStoreConfig, TomlCalendarStoreConfig};
|
||||
use rustical_auth::AuthProvider;
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::sqlite_store::{create_db_pool, SqliteCalendarStore};
|
||||
use rustical_store::store::CalendarStore;
|
||||
use rustical_store::toml_store::TomlCalendarStore;
|
||||
use std::fs;
|
||||
use std::sync::Arc;
|
||||
|
||||
Reference in New Issue
Block a user