aboutsummaryrefslogtreecommitdiff
path: root/src/domain/calendar.rs
diff options
context:
space:
mode:
authorMikkel Thestrup <mikkel@mithe.dk>2026-01-26 21:27:59 +0100
committerMikkel Thestrup <mikkel@mithe.dk>2026-01-27 15:37:03 +0100
commit4e78fd83349c95711cdee5acc56f248f81ebd25c (patch)
tree6a380da4c3651f73a806cafc9222012af9564f56 /src/domain/calendar.rs
parent4b1074193991a510fd2129513d5fcb7c6da933d2 (diff)
downloadkal-4e78fd83349c95711cdee5acc56f248f81ebd25c.tar.gz
kal-4e78fd83349c95711cdee5acc56f248f81ebd25c.zip
feat(domain): add core domain models for calendar application
Implement domain-driven design layer with entities, value objects, and repository traits for calendar management system. Domain Entities: - Calendar: manages calendar lifecycle and archival state - Event: handles single occurrence events with cancellation support - RecurringEvent: supports recurring events with exception handling - RecurrenceException: manages modifications to specific occurrences Value Objects: - TimeRange: enforces valid start/end time constraints - EventColor: type-safe color representation - Frequency: recurrence frequency enumeration (daily/weekly/monthly/yearly) - RecurrenceRule: encapsulates recurrence pattern logic - CalendarId & EventId: essentially just a wrapper Repository Traits: - CalendarRepository: calendar persistence interface - EventRepository: event querying and persistence with overlap detection - RecurrenceRepository: recurring event management Key Design Decisions: - Use Uuid for entity IDs (type safety, performance) - Encapsulate business logic within entities - Immutable value objects with validation - Repository pattern for infrastructure abstraction - Clear separation of concerns between domain and persistence layers All entities include timestamp tracking and follow builder pattern for construction with validation at domain boundaries.
Diffstat (limited to 'src/domain/calendar.rs')
-rw-r--r--src/domain/calendar.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/domain/calendar.rs b/src/domain/calendar.rs
new file mode 100644
index 0000000..21216b5
--- /dev/null
+++ b/src/domain/calendar.rs
@@ -0,0 +1,76 @@
+use chrono::{DateTime, Utc};
+use getset::Getters;
+
+use crate::domain::value_objects::CalendarId;
+
+#[derive(Debug, Clone, Getters)]
+pub struct Calendar {
+ #[getset(get = "pub")]
+ id: CalendarId,
+ #[getset(get = "pub")]
+ name: String,
+ #[getset(get = "pub")]
+ description: Option<String>,
+ #[getset(get = "pub")]
+ is_archived: bool,
+ #[getset(get = "pub")]
+ created_at: DateTime<Utc>,
+ #[getset(get = "pub")]
+ updated_at: DateTime<Utc>,
+}
+
+impl Calendar {
+ pub fn new(name: String, description: Option<String>) -> Self {
+ let now = Utc::now();
+ Self {
+ id: CalendarId::new(),
+ name,
+ description,
+ is_archived: false,
+ created_at: now,
+ updated_at: now,
+ }
+ }
+
+ pub fn with_id(
+ id: CalendarId,
+ name: String,
+ description: Option<String>,
+ is_archived: bool,
+ created_at: DateTime<Utc>,
+ updated_at: DateTime<Utc>,
+ ) -> Self {
+ Self {
+ id,
+ name,
+ description,
+ is_archived,
+ created_at,
+ updated_at,
+ }
+ }
+
+ pub fn archive(&mut self) {
+ self.is_archived = true;
+ self.touch();
+ }
+
+ pub fn unarchive(&mut self) {
+ self.is_archived = false;
+ self.touch();
+ }
+
+ pub fn update_name(&mut self, name: String) {
+ self.name = name;
+ self.touch();
+ }
+
+ pub fn update_description(&mut self, description: Option<String>) {
+ self.description = description;
+ self.touch();
+ }
+
+ pub fn touch(&mut self) {
+ self.updated_at = Utc::now();
+ }
+}