Skip to content

Commit

Permalink
factor out pace_service
Browse files Browse the repository at this point in the history
Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
  • Loading branch information
simonsan committed Mar 29, 2024
1 parent 8760f14 commit 09d260d
Show file tree
Hide file tree
Showing 60 changed files with 632 additions and 341 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ logs/*

# Database
db/activities.pace.sqlite3
/sea-orm
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"crates/core",
"crates/error",
"crates/server",
"crates/service",
"crates/storage",
"crates/time",
]
Expand Down Expand Up @@ -47,6 +48,7 @@ open = "5.1.2"
pace_cli = { path = "crates/cli", version = "0" }
pace_core = { path = "crates/core", version = "0" }
pace_error = { path = "crates/error", version = "0" }
pace_service = { path = "crates/service", version = "0" }
pace_storage = { path = "crates/storage", version = "0" }
pace_time = { path = "crates/time", version = "0" }
parking_lot = "0.12.1"
Expand Down Expand Up @@ -113,6 +115,7 @@ human-panic = { workspace = true }
pace_cli = { workspace = true }
pace_core = { workspace = true, features = ["cli"] }
pace_error = { workspace = true }
pace_service = { workspace = true }
pace_storage = { workspace = true }
pace_time = { workspace = true, features = ["cli", "db"] }
serde = { workspace = true }
Expand Down
13 changes: 13 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ include = [
"src/**/*",
"Cargo.toml",
]
[features]
default = ["cli"]
cli = ["clap"]
clap = ["dep:clap"]

[dependencies]
chrono = { workspace = true }
chrono-tz = { workspace = true }
clap = { workspace = true, optional = true, features = ["env", "wrap_help", "derive"] }
dialoguer = { workspace = true, features = ["fuzzy-select"] }
eyre = { workspace = true }
getset = { workspace = true }
open = { workspace = true }
pace_core = { workspace = true }
pace_error = { workspace = true }
pace_service = { workspace = true }
pace_time = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }
tera = { workspace = true }
tracing = { workspace = true }
typed-builder = { workspace = true }

Expand Down
8 changes: 8 additions & 0 deletions crates/cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod adjust;
pub mod begin;
pub mod docs;
pub mod end;
pub mod hold;
pub mod now;
pub mod reflect;
pub mod resume;
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ use chrono_tz::Tz;
#[cfg(feature = "clap")]
use clap::Parser;
use getset::Getters;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};
use tracing::debug;
use typed_builder::TypedBuilder;

use pace_error::{ActivityLogErrorKind, PaceResult, UserMessage};

use crate::{
commands::UpdateOptions,
use pace_core::{
config::PaceConfig,
domain::{category::PaceCategory, description::PaceDescription},
prelude::PaceTagCollection,
service::activity_store::ActivityStore,
domain::{category::PaceCategory, description::PaceDescription, tag::PaceTagCollection},
options::UpdateOptions,
storage::{ActivityQuerying, ActivityStorage, ActivityWriteOps, SyncStorage},
};
use pace_error::{ActivityLogErrorKind, PaceResult, UserMessage};
use pace_service::activity_store::ActivityStore;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};

/// `adjust` subcommand options
#[derive(Debug, Clone, PartialEq, TypedBuilder, Eq, Hash, Default, Getters)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ use chrono_tz::Tz;
#[cfg(feature = "clap")]
use clap::Parser;
use getset::Getters;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};
use tracing::debug;

use crate::{
use pace_core::{
config::PaceConfig,
domain::{
activity::{Activity, ActivityKind},
category::PaceCategory,
description::PaceDescription,
tag::PaceTagCollection,
},
prelude::PaceTagCollection,
service::activity_store::ActivityStore,
storage::{ActivityStateManagement, ActivityStorage, SyncStorage},
};

use pace_error::{PaceResult, UserMessage};
use pace_service::activity_store::ActivityStore;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};

/// `begin` subcommand options
#[derive(Debug, Clone, PartialEq, Eq, Getters)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "clap")]
use clap::Parser;

use crate::{
use pace_core::{
constants::PACE_DOCS_URL,
constants::{PACE_CONFIG_DOCS_URL, PACE_DEV_DOCS_URL},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ use chrono_tz::Tz;
#[cfg(feature = "clap")]
use clap::Parser;
use getset::Getters;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};
use tracing::debug;
use typed_builder::TypedBuilder;

use crate::{
commands::EndOptions,
use pace_core::{
config::PaceConfig,
service::activity_store::ActivityStore,
options::EndOptions,
storage::{ActivityStateManagement, ActivityStorage, SyncStorage},
};

use pace_error::{PaceResult, UserMessage};
use pace_service::activity_store::ActivityStore;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};

/// `end` subcommand options
#[derive(Debug, Clone, PartialEq, TypedBuilder, Eq, Hash, Default, Getters)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ use chrono::{FixedOffset, NaiveTime};
use chrono_tz::Tz;
#[cfg(feature = "clap")]
use clap::Parser;

use getset::Getters;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};
use tracing::debug;
use typed_builder::TypedBuilder;

use crate::{
use pace_core::{
config::PaceConfig,
domain::{description::PaceDescription, intermission::IntermissionAction},
service::activity_store::ActivityStore,
options::HoldOptions,
storage::{ActivityStateManagement, ActivityStorage, SyncStorage},
};

use pace_error::{PaceResult, UserMessage};
use pace_service::activity_store::ActivityStore;
use pace_time::{date_time::PaceDateTime, time_zone::PaceTimeZoneKind, Validate};

/// `hold` subcommand options
#[derive(Debug)]
Expand Down Expand Up @@ -135,21 +132,3 @@ impl HoldCommandOptions {
Ok(UserMessage::new(user_message))
}
}

/// Options for holding an activity
#[derive(Debug, Clone, PartialEq, TypedBuilder, Eq, Hash, Default, Getters)]
#[getset(get = "pub")]
#[non_exhaustive]
pub struct HoldOptions {
/// The action to take on the intermission
#[builder(default)]
action: IntermissionAction,

/// The start time of the intermission
#[builder(default, setter(into))]
begin_time: PaceDateTime,

/// The reason for holding the activity
#[builder(default, setter(into))]
reason: Option<PaceDescription>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::sync::Arc;
use clap::Parser;
use tracing::debug;

use crate::{
use pace_core::{
config::PaceConfig,
domain::{activity::ActivityItem, filter::ActivityFilterKind},
service::activity_store::ActivityStore,
storage::{ActivityQuerying, ActivityReadOps, ActivityStorage},
};

use pace_error::{PaceResult, UserMessage};
use pace_service::activity_store::ActivityStore;

/// `now` subcommand options
#[derive(Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#[cfg(feature = "clap")]
use clap::Parser;
use getset::{Getters, MutGetters, Setters};
use pace_time::{
flags::{DateFlags, TimeFlags},
time_frame::PaceTimeFrame,
time_zone::PaceTimeZoneKind,
};
use serde_derive::Serialize;
use std::{path::PathBuf, sync::Arc};
use tracing::debug;
use typed_builder::TypedBuilder;

use crate::{
use pace_core::{
config::PaceConfig,
domain::{
activity::ActivityKind, category::PaceCategory, filter::FilterOptions,
reflection::ReflectionsFormatKind,
},
prelude::ActivityStorage,
service::{activity_store::ActivityStore, activity_tracker::ActivityTracker},
domain::{activity::ActivityKind, category::PaceCategory, reflection::ReflectionsFormatKind},
options::FilterOptions,
storage::ActivityStorage,
template::{PaceReflectionTemplate, TEMPLATES},
};

use pace_error::{PaceResult, TemplatingErrorKind, UserMessage};
use pace_service::{activity_store::ActivityStore, activity_tracker::ActivityTracker};
use pace_time::{
flags::{DateFlags, TimeFlags},
time_frame::PaceTimeFrame,
time_zone::PaceTimeZoneKind,
};

/// `reflect` subcommand options
#[derive(Debug, Getters)]
Expand Down Expand Up @@ -138,6 +135,8 @@ impl ReflectCommandOptions {
date_flags,
template_file,
output_format,
category,
case_sensitive,
// time_zone,
// time_zone_offset,
.. // TODO: ignore the rest of the fields for now,
Expand All @@ -157,8 +156,12 @@ impl ReflectCommandOptions {

debug!("Displaying reflection for time frame: {}", time_frame);

let Some(reflection) =
activity_tracker.generate_reflection(FilterOptions::from(self), time_frame)?
let filter_opts = FilterOptions::builder()
.category(category.clone())
.case_sensitive(*case_sensitive)
.build();

let Some(reflection) = activity_tracker.generate_reflection(filter_opts, time_frame)?
else {
return Ok(UserMessage::new(
"No activities found for the specified time frame",
Expand Down Expand Up @@ -186,7 +189,6 @@ impl ReflectCommandOptions {

return Ok(UserMessage::new(json));
}

Some(ReflectionsFormatKind::Template) => {
let context = PaceReflectionTemplate::from(reflection).into_context();

Expand Down Expand Up @@ -221,6 +223,7 @@ impl ReflectCommandOptions {
return Ok(UserMessage::new(templated));
}
Some(ReflectionsFormatKind::Csv) => unimplemented!("CSV format not yet supported"),
_ => unimplemented!("Unsupported output format"),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use chrono_tz::Tz;
#[cfg(feature = "clap")]
use clap::Parser;
use getset::Getters;
use pace_time::date_time::PaceDateTime;
use typed_builder::TypedBuilder;

/// `resume` subcommand options
Expand Down Expand Up @@ -56,13 +55,3 @@ impl ResumeCommandOptions {
// FIXME: Inner run implementation for the resume command kept in pace-rs crate for now
// FIXME: due to the dependency on pace-cli
}

/// Options for resuming an activity
#[derive(Debug, Clone, PartialEq, TypedBuilder, Eq, Hash, Default, Getters)]
#[getset(get = "pub")]
#[non_exhaustive]
pub struct ResumeOptions {
/// The resume time of the intermission
#[builder(default, setter(into))]
resume_time: Option<PaceDateTime>,
}
Loading

0 comments on commit 09d260d

Please sign in to comment.