44
crates/domain/src/dimension/composed_entry.rs
Normal file
44
crates/domain/src/dimension/composed_entry.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::activity::ActivityId;
|
||||
use crate::attachment::{PhotoId, VoiceMemoId};
|
||||
use crate::entry::{Content, MoodEntry};
|
||||
use crate::location::Coordinates;
|
||||
use crate::song::Song;
|
||||
use crate::weather::Weather;
|
||||
|
||||
use super::DimensionValue;
|
||||
use super::lookup;
|
||||
|
||||
pub struct ComposedEntry {
|
||||
pub entry: MoodEntry,
|
||||
pub dimensions: Vec<DimensionValue>,
|
||||
}
|
||||
|
||||
impl ComposedEntry {
|
||||
pub fn content(&self) -> Option<&Content> {
|
||||
lookup::content_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn activities(&self) -> &[ActivityId] {
|
||||
lookup::activities_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn photos(&self) -> &[PhotoId] {
|
||||
lookup::photos_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn voice_memos(&self) -> &[VoiceMemoId] {
|
||||
lookup::voice_memos_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn location(&self) -> Option<&Coordinates> {
|
||||
lookup::location_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn song(&self) -> Option<&Song> {
|
||||
lookup::song_in(&self.dimensions)
|
||||
}
|
||||
|
||||
pub fn weather(&self) -> Option<&Weather> {
|
||||
lookup::weather_in(&self.dimensions)
|
||||
}
|
||||
}
|
||||
10
crates/domain/src/dimension/dimension_kind.rs
Normal file
10
crates/domain/src/dimension/dimension_kind.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum DimensionKind {
|
||||
Content,
|
||||
Activities,
|
||||
Photos,
|
||||
VoiceMemos,
|
||||
Location,
|
||||
Song,
|
||||
Weather,
|
||||
}
|
||||
39
crates/domain/src/dimension/dimension_value.rs
Normal file
39
crates/domain/src/dimension/dimension_value.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use crate::activity::ActivityId;
|
||||
use crate::attachment::{PhotoId, VoiceMemoId};
|
||||
use crate::entry::Content;
|
||||
use crate::location::Coordinates;
|
||||
use crate::song::Song;
|
||||
use crate::weather::Weather;
|
||||
|
||||
use super::DimensionKind;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DimensionValue {
|
||||
Content(Content),
|
||||
Activities(Vec<ActivityId>),
|
||||
Photos(Vec<PhotoId>),
|
||||
VoiceMemos(Vec<VoiceMemoId>),
|
||||
Location(Coordinates),
|
||||
Song(Song),
|
||||
Weather(Weather),
|
||||
}
|
||||
|
||||
impl DimensionValue {
|
||||
pub fn activities(mut ids: Vec<ActivityId>) -> Self {
|
||||
ids.sort();
|
||||
ids.dedup();
|
||||
Self::Activities(ids)
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> DimensionKind {
|
||||
match self {
|
||||
Self::Content(_) => DimensionKind::Content,
|
||||
Self::Activities(_) => DimensionKind::Activities,
|
||||
Self::Photos(_) => DimensionKind::Photos,
|
||||
Self::VoiceMemos(_) => DimensionKind::VoiceMemos,
|
||||
Self::Location(_) => DimensionKind::Location,
|
||||
Self::Song(_) => DimensionKind::Song,
|
||||
Self::Weather(_) => DimensionKind::Weather,
|
||||
}
|
||||
}
|
||||
}
|
||||
61
crates/domain/src/dimension/lookup.rs
Normal file
61
crates/domain/src/dimension/lookup.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use crate::activity::ActivityId;
|
||||
use crate::attachment::{PhotoId, VoiceMemoId};
|
||||
use crate::entry::Content;
|
||||
use crate::location::Coordinates;
|
||||
use crate::song::Song;
|
||||
use crate::weather::Weather;
|
||||
|
||||
use super::{DimensionKind, DimensionValue};
|
||||
|
||||
pub fn content_in(values: &[DimensionValue]) -> Option<&Content> {
|
||||
match find(values, DimensionKind::Content) {
|
||||
Some(DimensionValue::Content(content)) => Some(content),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activities_in(values: &[DimensionValue]) -> &[ActivityId] {
|
||||
match find(values, DimensionKind::Activities) {
|
||||
Some(DimensionValue::Activities(ids)) => ids,
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn photos_in(values: &[DimensionValue]) -> &[PhotoId] {
|
||||
match find(values, DimensionKind::Photos) {
|
||||
Some(DimensionValue::Photos(ids)) => ids,
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn voice_memos_in(values: &[DimensionValue]) -> &[VoiceMemoId] {
|
||||
match find(values, DimensionKind::VoiceMemos) {
|
||||
Some(DimensionValue::VoiceMemos(ids)) => ids,
|
||||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn location_in(values: &[DimensionValue]) -> Option<&Coordinates> {
|
||||
match find(values, DimensionKind::Location) {
|
||||
Some(DimensionValue::Location(coordinates)) => Some(coordinates),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn song_in(values: &[DimensionValue]) -> Option<&Song> {
|
||||
match find(values, DimensionKind::Song) {
|
||||
Some(DimensionValue::Song(song)) => Some(song),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn weather_in(values: &[DimensionValue]) -> Option<&Weather> {
|
||||
match find(values, DimensionKind::Weather) {
|
||||
Some(DimensionValue::Weather(weather)) => Some(weather),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn find(values: &[DimensionValue], kind: DimensionKind) -> Option<&DimensionValue> {
|
||||
values.iter().find(|value| value.kind() == kind)
|
||||
}
|
||||
8
crates/domain/src/dimension/mod.rs
Normal file
8
crates/domain/src/dimension/mod.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
mod composed_entry;
|
||||
mod dimension_kind;
|
||||
mod dimension_value;
|
||||
pub mod lookup;
|
||||
|
||||
pub use composed_entry::ComposedEntry;
|
||||
pub use dimension_kind::DimensionKind;
|
||||
pub use dimension_value::DimensionValue;
|
||||
Reference in New Issue
Block a user