Refactored modules
This commit is contained in:
parent
65a7670a1b
commit
7e3bccb5ad
9 changed files with 37 additions and 23 deletions
|
@ -1,3 +0,0 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
1
src/cache.rs
Normal file
1
src/cache.rs
Normal file
|
@ -0,0 +1 @@
|
|||
//! This module provides a local cache for CalDAV data
|
|
@ -3,8 +3,8 @@ use std::error::Error;
|
|||
|
||||
use url::Url;
|
||||
|
||||
use crate::data::Task;
|
||||
use crate::data::task::TaskId;
|
||||
use crate::task::Task;
|
||||
use crate::task::TaskId;
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
//! Code to connect to a Caldav server
|
||||
//!
|
||||
//! Some of it comes from https://github.com/marshalshi/caldav-client-rust.git
|
||||
//! This module provides a client to connect to a CalDAV server
|
||||
|
||||
use std::error::Error;
|
||||
use std::convert::TryFrom;
|
||||
|
@ -11,7 +9,7 @@ use minidom::Element;
|
|||
use url::Url;
|
||||
|
||||
use crate::utils::{find_elem, find_elems};
|
||||
use crate::data::Calendar;
|
||||
use crate::calendar::Calendar;
|
||||
|
||||
static DAVCLIENT_BODY: &str = r#"
|
||||
<d:propfind xmlns:d="DAV:">
|
||||
|
@ -200,7 +198,7 @@ impl Client {
|
|||
let mut this_calendar_url = self.url.clone();
|
||||
this_calendar_url.set_path(&calendar_href);
|
||||
|
||||
let supported_components = match crate::data::calendar::SupportedComponents::try_from(el_supported_comps.clone()) {
|
||||
let supported_components = match crate::calendar::SupportedComponents::try_from(el_supported_comps.clone()) {
|
||||
Err(err) => {
|
||||
log::warn!("Calendar {} has invalid supported components ({})! Ignoring it.", display_name, err);
|
||||
continue;
|
20
src/lib.rs
20
src/lib.rs
|
@ -1,3 +1,21 @@
|
|||
pub mod data;
|
||||
//! This crate provides a way to manage CalDAV data.
|
||||
//!
|
||||
//! It provides a CalDAV client in the [`client`] module, that can be used as a stand-alone module.
|
||||
//!
|
||||
//! Because the connection to the server may be slow, and a user-frendly app may want to quicky display cached data on startup, this crate also provides a local cache for CalDAV data in the [`cache`] module.
|
||||
//!
|
||||
//! These two "data sources" (actual client and local cache) can be used together in a [`Provider`](provider::Provider). \
|
||||
//! A `Provider` abstracts these two sources by merging them together into one virtual source. \
|
||||
//! It also handles synchronisation between the local cache and the server.
|
||||
|
||||
mod calendar;
|
||||
pub use calendar::Calendar;
|
||||
mod task;
|
||||
pub use task::Task;
|
||||
|
||||
pub mod client;
|
||||
pub mod provider;
|
||||
pub mod cache;
|
||||
|
||||
pub mod settings;
|
||||
pub mod utils;
|
||||
|
|
3
src/provider.rs
Normal file
3
src/provider.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
//! This modules abstracts data sources and merges them in a single virtual one
|
||||
|
||||
pub struct Provider {}
|
|
@ -1,17 +1,9 @@
|
|||
//! This module is the data source of the Caldav items
|
||||
//!
|
||||
//! This gives access to data from both the server and a local database for quick retrieval when the app starts
|
||||
//! This module provides CalDAV data sources and utilities
|
||||
|
||||
use std::sync::Arc;
|
||||
/*
|
||||
use std::error::Error;
|
||||
|
||||
pub mod calendar;
|
||||
mod task;
|
||||
pub mod client;
|
||||
|
||||
pub use calendar::Calendar;
|
||||
pub use task::Task;
|
||||
use client::Client;
|
||||
|
||||
/// A Caldav data source
|
||||
pub struct DataSource {
|
||||
|
@ -37,16 +29,21 @@ impl DataSource {
|
|||
|
||||
/// Update the local database with info from the Client
|
||||
pub fn fetch_from_server(&mut self) {
|
||||
|
||||
// TODO: how to handle conflicts?
|
||||
}
|
||||
|
||||
pub fn update_changes_to_server(&self) {
|
||||
|
||||
}
|
||||
|
||||
// TODO: the API should force calling fetch_from_server before
|
||||
pub fn calendars(&self) -> Vec<&Calendar> {
|
||||
// TODO: what happens when a user has a reference, which is modified/updated from the server? Conflict mut/not mut?
|
||||
// TODO: how can the user modify Tasks from a non-mut reference?
|
||||
self.calendars
|
||||
.iter()
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
|
@ -9,7 +9,7 @@ use reqwest::header::CONTENT_TYPE;
|
|||
use minidom::Element;
|
||||
use url::Url;
|
||||
|
||||
use my_tasks::data::client::Client;
|
||||
use my_tasks::client::Client;
|
||||
use my_tasks::settings::URL;
|
||||
use my_tasks::settings::USERNAME;
|
||||
use my_tasks::settings::PASSWORD;
|
||||
|
|
Loading…
Add table
Reference in a new issue