Initial API structre

This commit is contained in:
daladim 2021-02-18 12:02:04 +01:00
commit 58b96a89b0
9 changed files with 133 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

14
Cargo.lock generated Normal file
View file

@ -0,0 +1,14 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "my-tasks"
version = "0.1.0"
dependencies = [
"uuid",
]
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "my-tasks"
version = "0.1.0"
authors = ["Jérôme"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
uuid = "0.8"

3
src/bin/my-tasks.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

24
src/data/calendar.rs Normal file
View file

@ -0,0 +1,24 @@
use crate::data::TaskView;
/// A Caldav Calendar
pub struct Calendar {
name: String,
tasks: Vec<TaskView>,
}
impl Calendar {
pub fn name() -> String {
self.name
}
pub fn tasks() -> Vec<TaskView> {
self.tasks
}
}
impl Drop for Calendar {
fn drop(&mut self) {
// TODO: display a warning in case some TaskViews still have a refcount > 0
}
}

7
src/data/client.rs Normal file
View file

@ -0,0 +1,7 @@
pub struct Client {}
impl Client {
pub fn new(&mut self, url: String, username: String, password: String) -> Self {
Self{}
}
}

55
src/data/mod.rs Normal file
View file

@ -0,0 +1,55 @@
//! 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
use std::sync::Arc;
mod calendar;
mod tasks;
mod client;
pub use calendar::Calendar;
pub use tasks::Task;
use client::Client;
// TODO: consider using references here
// (there will be no issue with still-borrowed-data when the DataSource is destroyed, but will it play well with sync stuff?)
type CalendarView = Arc<Calendar>;
type TaskView = Arc<Task>;
/// A Caldav data source
pub struct DataSource {
client: Option<Client>,
calendars: Vec<CalendarView>
}
impl DataSource {
/// Create a new data source
pub fn new() -> Self {
Self{
client: None,
calendars: Vec::new(),
}
}
/// Tell this data source what the source server is
pub fn set_server(&mut self, url: String, username: String, password: String) {
self.client = Client::new(url, username, password);
}
/// Update the local database with info from the Client
pub fn fetch_from_server(&self) {
// TODO: how to handle conflicts?
}
pub fn calendars(&self) -> Vec<CalendarView> {
self.calendars
}
}
impl Drop for DataSource {
fn drop(&mut self) {
// TODO: display a warning in case some CalendarViews still have a refcount > 0
}
}

18
src/data/tasks.rs Normal file
View file

@ -0,0 +1,18 @@
use uuid::Uuid;
/// A to-do task
pub struct Task {
id: Uuid,
name: String,
}
impl Task {
pub fn id(&self) -> Uuid { self.id }
pub fn name(&self) -> String { self.name }
pub fn completed(&self) -> bool { self.completed }
pub fn set_completed(&mut self) {
// TODO: either require a reference to the DataSource, so that it is aware
// or change a flag here, and the DataSource will be able to check the flags of all its content (but then the Calendar should only give a reference/Arc, not a clone)
}
}

1
src/lib.rs Normal file
View file

@ -0,0 +1 @@
pub mod data;