diff --git a/crates/error/src/lib.rs b/crates/error/src/lib.rs index 0e84f5f..18fa23d 100644 --- a/crates/error/src/lib.rs +++ b/crates/error/src/lib.rs @@ -212,12 +212,8 @@ pub enum DatabaseStorageErrorKind { /// This database engine is currently not supported: {0} UnsupportedDatabaseEngine(String), - /// Activity with id {guid} not found: {source} - ActivityNotFound { - guid: String, - #[source] - source: sea_orm::error::SqlErr, - }, + /// Activity with id {guid} not found + ActivityNotFound { guid: String }, /// Failed to create activity: {0} ActivityCreationFailed(String), @@ -284,7 +280,7 @@ pub enum DatabaseStorageErrorKind { ActivityReadFailed { guid: String, #[source] - source: sea_orm::error::SqlErr, + source: sea_orm::error::DbErr, }, /// There is no item contained with id {0} diff --git a/crates/storage/src/entity/activities.rs b/crates/storage/src/entity/activities.rs index bd17106..0dbb2dc 100644 --- a/crates/storage/src/entity/activities.rs +++ b/crates/storage/src/entity/activities.rs @@ -1,5 +1,6 @@ //! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 +use chrono::{DateTime, FixedOffset}; use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] @@ -8,8 +9,8 @@ pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub guid: String, pub description_guid: String, - pub begin: String, - pub end: Option, + pub begin: DateTime, + pub end: Option>, pub duration: Option, pub kind_guid: String, pub status_guid: String, @@ -17,7 +18,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum Activities { +pub enum ActivitiesEnum { Table, Guid, DescriptionGuid, diff --git a/crates/storage/src/entity/activities_categories.rs b/crates/storage/src/entity/activities_categories.rs index e57fe09..acd6f8b 100644 --- a/crates/storage/src/entity/activities_categories.rs +++ b/crates/storage/src/entity/activities_categories.rs @@ -12,7 +12,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum ActivitiesCategories { +pub enum ActivitiesCategoriesEnum { Table, Guid, ActivityGuid, diff --git a/crates/storage/src/entity/activities_tags.rs b/crates/storage/src/entity/activities_tags.rs index 9b16705..0ca6f84 100644 --- a/crates/storage/src/entity/activities_tags.rs +++ b/crates/storage/src/entity/activities_tags.rs @@ -12,7 +12,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum ActivitiesTags { +pub enum ActivitiesTagsEnum { Table, Guid, TagGuid, diff --git a/crates/storage/src/entity/activity_kinds.rs b/crates/storage/src/entity/activity_kinds.rs index 8b3efdb..26222e6 100644 --- a/crates/storage/src/entity/activity_kinds.rs +++ b/crates/storage/src/entity/activity_kinds.rs @@ -11,7 +11,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum ActivityKinds { +pub enum ActivityKindsEnum { Table, Guid, Kind, diff --git a/crates/storage/src/entity/activity_status.rs b/crates/storage/src/entity/activity_status.rs index 71f83fa..b3bf984 100644 --- a/crates/storage/src/entity/activity_status.rs +++ b/crates/storage/src/entity/activity_status.rs @@ -11,7 +11,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum ActivityStatus { +pub enum ActivityStatusEnum { Table, Guid, Status, diff --git a/crates/storage/src/entity/categories.rs b/crates/storage/src/entity/categories.rs index 4121fa1..0d76cee 100644 --- a/crates/storage/src/entity/categories.rs +++ b/crates/storage/src/entity/categories.rs @@ -12,7 +12,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum Categories { +pub enum CategoriesEnum { Table, Guid, Category, diff --git a/crates/storage/src/entity/descriptions.rs b/crates/storage/src/entity/descriptions.rs index 6fc2969..078e74a 100644 --- a/crates/storage/src/entity/descriptions.rs +++ b/crates/storage/src/entity/descriptions.rs @@ -11,7 +11,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum Descriptions { +pub enum DescriptionsEnum { Table, Guid, Description, diff --git a/crates/storage/src/entity/tags.rs b/crates/storage/src/entity/tags.rs index 338b1cd..be6aad5 100644 --- a/crates/storage/src/entity/tags.rs +++ b/crates/storage/src/entity/tags.rs @@ -11,7 +11,7 @@ pub struct Model { } #[derive(DeriveIden)] -pub enum Tags { +pub enum TagsEnum { Table, Guid, Tag, diff --git a/crates/storage/src/migration/m20240325_000001_create_activities.rs b/crates/storage/src/migration/m20240325_000001_create_activities.rs index f687775..1a0c4d7 100644 --- a/crates/storage/src/migration/m20240325_000001_create_activities.rs +++ b/crates/storage/src/migration/m20240325_000001_create_activities.rs @@ -1,9 +1,9 @@ use sea_orm_migration::prelude::*; -use crate::entity::activities::Activities; -use crate::entity::activity_kinds::ActivityKinds; -use crate::entity::activity_status::ActivityStatus; -use crate::entity::descriptions::Descriptions; +use crate::entity::activities::ActivitiesEnum; +use crate::entity::activity_kinds::ActivityKindsEnum; +use crate::entity::activity_status::ActivityStatusEnum; +use crate::entity::descriptions::DescriptionsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -14,56 +14,56 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(Activities::Table) + .table(ActivitiesEnum::Table) .if_not_exists() .col( - ColumnDef::new(Activities::Guid) + ColumnDef::new(ActivitiesEnum::Guid) .text() .not_null() .primary_key(), ) .col( - ColumnDef::new(Activities::DescriptionGuid) + ColumnDef::new(ActivitiesEnum::DescriptionGuid) .text() .not_null(), ) .col( - ColumnDef::new(Activities::Begin) + ColumnDef::new(ActivitiesEnum::Begin) .timestamp_with_time_zone() .not_null(), ) .col( - ColumnDef::new(Activities::End) + ColumnDef::new(ActivitiesEnum::End) .timestamp_with_time_zone() .null(), ) - .col(ColumnDef::new(Activities::Duration).integer().null()) - .col(ColumnDef::new(Activities::KindGuid).text().not_null()) - .col(ColumnDef::new(Activities::StatusGuid).text().not_null()) - .col(ColumnDef::new(Activities::ParentGuid).text().null()) + .col(ColumnDef::new(ActivitiesEnum::Duration).integer().null()) + .col(ColumnDef::new(ActivitiesEnum::KindGuid).text().not_null()) + .col(ColumnDef::new(ActivitiesEnum::StatusGuid).text().not_null()) + .col(ColumnDef::new(ActivitiesEnum::ParentGuid).text().null()) .foreign_key( ForeignKey::create() .name("fk_activities_parent_guid") - .from(Activities::Table, Activities::ParentGuid) - .to(Activities::Table, Activities::Guid), + .from(ActivitiesEnum::Table, ActivitiesEnum::ParentGuid) + .to(ActivitiesEnum::Table, ActivitiesEnum::Guid), ) .foreign_key( ForeignKey::create() .name("fk_activities_kind") - .from(Activities::Table, Activities::KindGuid) - .to(ActivityKinds::Table, ActivityKinds::Guid), + .from(ActivitiesEnum::Table, ActivitiesEnum::KindGuid) + .to(ActivityKindsEnum::Table, ActivityKindsEnum::Guid), ) .foreign_key( ForeignKey::create() .name("fk_activities_status") - .from(Activities::Table, Activities::StatusGuid) - .to(ActivityStatus::Table, ActivityStatus::Guid), + .from(ActivitiesEnum::Table, ActivitiesEnum::StatusGuid) + .to(ActivityStatusEnum::Table, ActivityStatusEnum::Guid), ) .foreign_key( ForeignKey::create() .name("fk_activities_description") - .from(Activities::Table, Activities::DescriptionGuid) - .to(Descriptions::Table, Descriptions::Guid), + .from(ActivitiesEnum::Table, ActivitiesEnum::DescriptionGuid) + .to(DescriptionsEnum::Table, DescriptionsEnum::Guid), ) .to_owned(), ) @@ -74,7 +74,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(Activities::Table) + .table(ActivitiesEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240326_000001_create_tags.rs b/crates/storage/src/migration/m20240326_000001_create_tags.rs index 03b393a..91ba5b9 100644 --- a/crates/storage/src/migration/m20240326_000001_create_tags.rs +++ b/crates/storage/src/migration/m20240326_000001_create_tags.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::entity::tags::Tags; +use crate::entity::tags::TagsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,9 +12,14 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(Tags::Table) - .col(ColumnDef::new(Tags::Guid).text().not_null().primary_key()) - .col(ColumnDef::new(Tags::Tag).text().not_null()) + .table(TagsEnum::Table) + .col( + ColumnDef::new(TagsEnum::Guid) + .text() + .not_null() + .primary_key(), + ) + .col(ColumnDef::new(TagsEnum::Tag).text().not_null()) .to_owned(), ) .await @@ -22,7 +27,7 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .drop_table(Table::drop().table(Tags::Table).if_exists().to_owned()) + .drop_table(Table::drop().table(TagsEnum::Table).if_exists().to_owned()) .await } } diff --git a/crates/storage/src/migration/m20240326_000002_create_categories.rs b/crates/storage/src/migration/m20240326_000002_create_categories.rs index f2fd978..5dd6209 100644 --- a/crates/storage/src/migration/m20240326_000002_create_categories.rs +++ b/crates/storage/src/migration/m20240326_000002_create_categories.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::entity::categories::Categories; +use crate::entity::categories::CategoriesEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,15 +12,15 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(Categories::Table) + .table(CategoriesEnum::Table) .col( - ColumnDef::new(Categories::Guid) + ColumnDef::new(CategoriesEnum::Guid) .text() .not_null() .primary_key(), ) - .col(ColumnDef::new(Categories::Category).text().not_null()) - .col(ColumnDef::new(Categories::Description).text().null()) + .col(ColumnDef::new(CategoriesEnum::Category).text().not_null()) + .col(ColumnDef::new(CategoriesEnum::Description).text().null()) .to_owned(), ) .await @@ -30,7 +30,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(Categories::Table) + .table(CategoriesEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240326_000003_create_activity_status.rs b/crates/storage/src/migration/m20240326_000003_create_activity_status.rs index 3c73ed5..d64f616 100644 --- a/crates/storage/src/migration/m20240326_000003_create_activity_status.rs +++ b/crates/storage/src/migration/m20240326_000003_create_activity_status.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::entity::activity_status::ActivityStatus; +use crate::entity::activity_status::ActivityStatusEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,14 +12,14 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(ActivityStatus::Table) + .table(ActivityStatusEnum::Table) .col( - ColumnDef::new(ActivityStatus::Guid) + ColumnDef::new(ActivityStatusEnum::Guid) .text() .not_null() .primary_key(), ) - .col(ColumnDef::new(ActivityStatus::Status).text().not_null()) + .col(ColumnDef::new(ActivityStatusEnum::Status).text().not_null()) .to_owned(), ) .await @@ -29,7 +29,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(ActivityStatus::Table) + .table(ActivityStatusEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240326_000004_create_activity_kinds.rs b/crates/storage/src/migration/m20240326_000004_create_activity_kinds.rs index cbdfe40..0e445d7 100644 --- a/crates/storage/src/migration/m20240326_000004_create_activity_kinds.rs +++ b/crates/storage/src/migration/m20240326_000004_create_activity_kinds.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::entity::activity_kinds::ActivityKinds; +use crate::entity::activity_kinds::ActivityKindsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,14 +12,14 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(ActivityKinds::Table) + .table(ActivityKindsEnum::Table) .col( - ColumnDef::new(ActivityKinds::Guid) + ColumnDef::new(ActivityKindsEnum::Guid) .text() .not_null() .primary_key(), ) - .col(ColumnDef::new(ActivityKinds::Kind).text().not_null()) + .col(ColumnDef::new(ActivityKindsEnum::Kind).text().not_null()) .to_owned(), ) .await @@ -29,7 +29,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(ActivityKinds::Table) + .table(ActivityKindsEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240326_000005_create_activities_tags.rs b/crates/storage/src/migration/m20240326_000005_create_activities_tags.rs index 1febdc3..c83bf58 100644 --- a/crates/storage/src/migration/m20240326_000005_create_activities_tags.rs +++ b/crates/storage/src/migration/m20240326_000005_create_activities_tags.rs @@ -1,8 +1,8 @@ use sea_orm_migration::prelude::*; -use crate::entity::activities::Activities; -use crate::entity::activities_tags::ActivitiesTags; -use crate::entity::tags::Tags; +use crate::entity::activities::ActivitiesEnum; +use crate::entity::activities_tags::ActivitiesTagsEnum; +use crate::entity::tags::TagsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -14,30 +14,34 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(ActivitiesTags::Table) + .table(ActivitiesTagsEnum::Table) .col( - ColumnDef::new(ActivitiesTags::Guid) + ColumnDef::new(ActivitiesTagsEnum::Guid) .text() .not_null() .primary_key(), ) - .col(ColumnDef::new(ActivitiesTags::TagGuid).text().not_null()) .col( - ColumnDef::new(ActivitiesTags::ActivityGuid) + ColumnDef::new(ActivitiesTagsEnum::TagGuid) + .text() + .not_null(), + ) + .col( + ColumnDef::new(ActivitiesTagsEnum::ActivityGuid) .text() .not_null(), ) .foreign_key( ForeignKey::create() .name("fk_activities_tags_tag_guid") - .from(ActivitiesTags::Table, ActivitiesTags::TagGuid) - .to(Tags::Table, Tags::Guid), + .from(ActivitiesTagsEnum::Table, ActivitiesTagsEnum::TagGuid) + .to(TagsEnum::Table, TagsEnum::Guid), ) .foreign_key( ForeignKey::create() .name("fk_activities_tags_activity_guid") - .from(ActivitiesTags::Table, ActivitiesTags::ActivityGuid) - .to(Activities::Table, Activities::Guid), + .from(ActivitiesTagsEnum::Table, ActivitiesTagsEnum::ActivityGuid) + .to(ActivitiesEnum::Table, ActivitiesEnum::Guid), ) .to_owned(), ) @@ -48,7 +52,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(ActivitiesTags::Table) + .table(ActivitiesTagsEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240326_000006_create_activities_categories.rs b/crates/storage/src/migration/m20240326_000006_create_activities_categories.rs index 0968b8d..01483f8 100644 --- a/crates/storage/src/migration/m20240326_000006_create_activities_categories.rs +++ b/crates/storage/src/migration/m20240326_000006_create_activities_categories.rs @@ -1,8 +1,8 @@ use sea_orm_migration::prelude::*; -use crate::entity::activities::Activities; -use crate::entity::activities_categories::ActivitiesCategories; -use crate::entity::categories::Categories; +use crate::entity::activities::ActivitiesEnum; +use crate::entity::activities_categories::ActivitiesCategoriesEnum; +use crate::entity::categories::CategoriesEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -13,21 +13,21 @@ impl MigrationTrait for Migration { manager .create_table( Table::create() - .table(ActivitiesCategories::Table) + .table(ActivitiesCategoriesEnum::Table) .if_not_exists() .col( - ColumnDef::new(ActivitiesCategories::Guid) + ColumnDef::new(ActivitiesCategoriesEnum::Guid) .text() .not_null() .primary_key(), ) .col( - ColumnDef::new(ActivitiesCategories::ActivityGuid) + ColumnDef::new(ActivitiesCategoriesEnum::ActivityGuid) .text() .not_null(), ) .col( - ColumnDef::new(ActivitiesCategories::CategoryGuid) + ColumnDef::new(ActivitiesCategoriesEnum::CategoryGuid) .text() .not_null(), ) @@ -35,19 +35,19 @@ impl MigrationTrait for Migration { ForeignKey::create() .name("fk_activities_categories_category_guid") .from( - ActivitiesCategories::Table, - ActivitiesCategories::CategoryGuid, + ActivitiesCategoriesEnum::Table, + ActivitiesCategoriesEnum::CategoryGuid, ) - .to(Categories::Table, Categories::Guid), + .to(CategoriesEnum::Table, CategoriesEnum::Guid), ) .foreign_key( ForeignKey::create() .name("fk_activities_categories_activity_guid") .from( - ActivitiesCategories::Table, - ActivitiesCategories::ActivityGuid, + ActivitiesCategoriesEnum::Table, + ActivitiesCategoriesEnum::ActivityGuid, ) - .to(Activities::Table, Activities::Guid), + .to(ActivitiesEnum::Table, ActivitiesEnum::Guid), ) .to_owned(), ) @@ -58,7 +58,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(ActivitiesCategories::Table) + .table(ActivitiesCategoriesEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/migration/m20240327_000001_create_activity_status_values.rs b/crates/storage/src/migration/m20240327_000001_create_activity_status_values.rs index 04744e5..52ab605 100644 --- a/crates/storage/src/migration/m20240327_000001_create_activity_status_values.rs +++ b/crates/storage/src/migration/m20240327_000001_create_activity_status_values.rs @@ -5,7 +5,7 @@ use ulid::Ulid; use sea_orm_migration::prelude::*; -use crate::entity::activity_status::ActivityStatus; +use crate::entity::activity_status::ActivityStatusEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -16,8 +16,8 @@ impl MigrationTrait for Migration { let activity_kinds = ActivityStatusKind::iter() .map(|kind| { Query::insert() - .into_table(ActivityStatus::Table) - .columns([ActivityStatus::Guid, ActivityStatus::Status]) + .into_table(ActivityStatusEnum::Table) + .columns([ActivityStatusEnum::Guid, ActivityStatusEnum::Status]) .values_panic([Ulid::new().to_string().into(), kind.to_string().into()]) .to_owned() }) @@ -32,7 +32,11 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .exec_stmt(Query::delete().from_table(ActivityStatus::Table).to_owned()) + .exec_stmt( + Query::delete() + .from_table(ActivityStatusEnum::Table) + .to_owned(), + ) .await } } diff --git a/crates/storage/src/migration/m20240327_000002_create_activity_kind_values.rs b/crates/storage/src/migration/m20240327_000002_create_activity_kind_values.rs index e71561c..8d64bb1 100644 --- a/crates/storage/src/migration/m20240327_000002_create_activity_kind_values.rs +++ b/crates/storage/src/migration/m20240327_000002_create_activity_kind_values.rs @@ -4,7 +4,7 @@ use sea_orm_migration::prelude::*; use strum::IntoEnumIterator; use ulid::Ulid; -use crate::entity::activity_kinds::ActivityKinds; +use crate::entity::activity_kinds::ActivityKindsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -15,8 +15,8 @@ impl MigrationTrait for Migration { let activity_kinds = ActivityKind::iter() .map(|kind| { Query::insert() - .into_table(ActivityKinds::Table) - .columns([ActivityKinds::Guid, ActivityKinds::Kind]) + .into_table(ActivityKindsEnum::Table) + .columns([ActivityKindsEnum::Guid, ActivityKindsEnum::Kind]) .values_panic([Ulid::new().to_string().into(), kind.to_string().into()]) .to_owned() }) @@ -31,7 +31,11 @@ impl MigrationTrait for Migration { async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager - .exec_stmt(Query::delete().from_table(ActivityKinds::Table).to_owned()) + .exec_stmt( + Query::delete() + .from_table(ActivityKindsEnum::Table) + .to_owned(), + ) .await } } diff --git a/crates/storage/src/migration/m20240329_000001_create_descriptions.rs b/crates/storage/src/migration/m20240329_000001_create_descriptions.rs index ae522d3..29d1bd0 100644 --- a/crates/storage/src/migration/m20240329_000001_create_descriptions.rs +++ b/crates/storage/src/migration/m20240329_000001_create_descriptions.rs @@ -1,6 +1,6 @@ use sea_orm_migration::prelude::*; -use crate::entity::descriptions::Descriptions; +use crate::entity::descriptions::DescriptionsEnum; #[derive(DeriveMigrationName)] pub struct Migration; @@ -12,14 +12,18 @@ impl MigrationTrait for Migration { .create_table( Table::create() .if_not_exists() - .table(Descriptions::Table) + .table(DescriptionsEnum::Table) .col( - ColumnDef::new(Descriptions::Guid) + ColumnDef::new(DescriptionsEnum::Guid) .text() .not_null() .primary_key(), ) - .col(ColumnDef::new(Descriptions::Description).text().not_null()) + .col( + ColumnDef::new(DescriptionsEnum::Description) + .text() + .not_null(), + ) .to_owned(), ) .await @@ -29,7 +33,7 @@ impl MigrationTrait for Migration { manager .drop_table( Table::drop() - .table(Descriptions::Table) + .table(DescriptionsEnum::Table) .if_exists() .to_owned(), ) diff --git a/crates/storage/src/storage/sqlite.rs b/crates/storage/src/storage/sqlite.rs index 619672a..ea82ea4 100644 --- a/crates/storage/src/storage/sqlite.rs +++ b/crates/storage/src/storage/sqlite.rs @@ -1,7 +1,7 @@ use std::{collections::BTreeMap, fs::File, path::PathBuf}; use itertools::Itertools; -use sea_orm::{Database, DatabaseConnection}; +use sea_orm::{Database, DatabaseConnection, EntityTrait, ModelTrait, QueryFilter}; use tokio::runtime::Runtime; use tracing::debug; @@ -20,6 +20,7 @@ use pace_error::{DatabaseStorageErrorKind, PaceOptResult, PaceResult}; use pace_time::{date::PaceDate, duration::PaceDurationRange, time_range::TimeRangeOptions}; use crate::{ + entity::{activities, activity_status, descriptions, prelude::Activities, tags}, migration::{Migrator, MigratorTrait}, runtime, }; @@ -112,17 +113,24 @@ impl SyncStorage for DatabaseActivityStorage { impl ActivityReadOps for DatabaseActivityStorage { #[tracing::instrument] fn read_activity(&self, activity_id: ActivityGuid) -> PaceResult { - // TODO: Now we need to get the rest of the data from the database - // and return the ActivityItem - // - // Missing data: - // Description (1:1) (in extra table for deduplication) - // ActivityStatus (1:N) - // ActivityKind (1:N) - // Categories (M:N) - // Tags (M:N) - - Ok(ActivityItem::default()) + runtime().block_on(async { + let Ok(Some(activity)) = Activities::find_by_id(activity_id.to_string()) + .one(&self.connection) + .await + else { + return Err(DatabaseStorageErrorKind::ActivityNotFound { + guid: activity_id.to_string(), + } + .into()); + }; + + let description = activity + .find_related(descriptions::Entity) + .one(&self.connection) + .await; + + Ok(ActivityItem::default()) + }) } #[tracing::instrument] @@ -260,6 +268,7 @@ impl ActivityStateManagement for DatabaseActivityStorage { todo!() } } + impl ActivityQuerying for DatabaseActivityStorage { fn group_activities_by_duration_range( &self,