Add tracing and restructure the Cargo.tomls

This commit is contained in:
Lennart
2024-10-04 16:30:59 +02:00
parent 12e4e42c7c
commit c14eddb0b6
12 changed files with 892 additions and 123 deletions

View File

@@ -1,30 +1,24 @@
[package]
name = "rustical_store"
version = "0.1.0"
edition = "2021"
version.workspace = true
edition.workspace = true
[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
async-trait = "0.1"
serde = { version = "1.0", features = ["derive", "rc"] }
sha2 = "0.10"
sqlx = { version = "0.8", features = [
"sqlx-sqlite",
"uuid",
"chrono",
"sqlite",
"runtime-tokio",
"migrate",
] }
tokio = { version = "1.40", features = ["sync", "full"] }
toml = "0.8"
ical = { version = "0.11", features = ["generator", "serde"] }
chrono = { version = "0.4", features = ["serde"] }
regex = "1.10"
lazy_static = "1.5"
rstest = "0.23"
rstest_reuse = "0.7"
thiserror = "1.0"
password-auth = "1.0"
actix-web = "4.9"
actix-web-httpauth = "0.8"
anyhow = { workspace = true }
async-trait = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
sqlx = { workspace = true }
tokio = { workspace = true }
toml = { workspace = true }
ical = { workspace = true }
chrono = { workspace = true }
regex = { workspace = true }
lazy_static = { workspace = true }
rstest = { workspace = true }
rstest_reuse = { workspace = true }
thiserror = { workspace = true }
password-auth = { workspace = true }
actix-web = { workspace = true }
actix-web-httpauth = { workspace = true }
tracing = { workspace = true }

View File

@@ -6,6 +6,7 @@ use async_trait::async_trait;
use serde::Serialize;
use sqlx::Transaction;
use sqlx::{sqlite::SqliteConnectOptions, Pool, Sqlite, SqlitePool};
use tracing::instrument;
#[derive(Debug)]
pub struct SqliteCalendarStore {
@@ -77,6 +78,7 @@ async fn log_object_operation(
#[async_trait]
impl CalendarStore for SqliteCalendarStore {
#[instrument]
async fn get_calendar(&self, principal: &str, id: &str) -> Result<Calendar, Error> {
let cal = sqlx::query_as!(
Calendar,
@@ -91,6 +93,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(cal)
}
#[instrument]
async fn get_calendars(&self, principal: &str) -> Result<Vec<Calendar>, Error> {
let cals = sqlx::query_as!(
Calendar,
@@ -104,6 +107,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(cals)
}
#[instrument]
async fn insert_calendar(&mut self, calendar: Calendar) -> Result<(), Error> {
sqlx::query!(
r#"INSERT INTO calendars (principal, id, displayname, description, "order", color, timezone)
@@ -121,6 +125,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn update_calendar(
&mut self,
principal: String,
@@ -147,6 +152,7 @@ impl CalendarStore for SqliteCalendarStore {
}
// Does not actually delete the calendar but just disables it
#[instrument]
async fn delete_calendar(
&mut self,
principal: &str,
@@ -175,6 +181,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn restore_calendar(&mut self, principal: &str, id: &str) -> Result<(), Error> {
sqlx::query!(
r"UPDATE calendars SET deleted_at = NULL WHERE (principal, id) = (?, ?)",
@@ -186,6 +193,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn get_objects(&self, principal: &str, cid: &str) -> Result<Vec<CalendarObject>, Error> {
sqlx::query_as!(
CalendarObjectRow,
@@ -200,6 +208,7 @@ impl CalendarStore for SqliteCalendarStore {
.collect()
}
#[instrument]
async fn get_object(
&self,
principal: &str,
@@ -218,6 +227,7 @@ impl CalendarStore for SqliteCalendarStore {
.try_into()?)
}
#[instrument]
async fn put_object(
&mut self,
principal: String,
@@ -244,6 +254,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn delete_object(
&mut self,
principal: &str,
@@ -286,6 +297,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn restore_object(&mut self, principal: &str, cid: &str, uid: &str) -> Result<(), Error> {
let mut tx = self.db.begin().await?;
@@ -310,6 +322,7 @@ impl CalendarStore for SqliteCalendarStore {
Ok(())
}
#[instrument]
async fn sync_changes(
&self,
principal: &str,