first commit

This commit is contained in:
Timur Gordon
2025-10-20 22:24:25 +02:00
commit 097360ad12
48 changed files with 6712 additions and 0 deletions

139
src/objects/event/mod.rs Normal file
View File

@@ -0,0 +1,139 @@
use crate::store::BaseData;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
#[cfg(feature = "rhai-support")]
pub mod rhai;
/// Event status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub enum EventStatus {
#[default]
Draft,
Published,
Cancelled,
}
/// A calendar event object
#[derive(Debug, Clone, Serialize, Deserialize, crate::DeriveObject)]
pub struct Event {
/// Base data
pub base_data: BaseData,
/// Title of the event
#[index]
pub title: String,
/// Optional description
pub description: Option<String>,
/// Start time
#[index]
#[serde(with = "time::serde::timestamp")]
pub start_time: OffsetDateTime,
/// End time
#[serde(with = "time::serde::timestamp")]
pub end_time: OffsetDateTime,
/// Optional location
#[index]
pub location: Option<String>,
/// Event status
#[index]
pub status: EventStatus,
/// Whether this is an all-day event
pub all_day: bool,
/// Optional category
#[index]
pub category: Option<String>,
}
impl Event {
/// Create a new event
pub fn new(ns: String, title: impl ToString) -> Self {
let now = OffsetDateTime::now_utc();
Self {
base_data: BaseData::new(ns),
title: title.to_string(),
description: None,
start_time: now,
end_time: now,
location: None,
status: EventStatus::default(),
all_day: false,
category: None,
}
}
/// Create an event with specific ID
pub fn with_id(id: String, ns: String, title: impl ToString) -> Self {
let now = OffsetDateTime::now_utc();
Self {
base_data: BaseData::with_id(id, ns),
title: title.to_string(),
description: None,
start_time: now,
end_time: now,
location: None,
status: EventStatus::default(),
all_day: false,
category: None,
}
}
/// Set the description
pub fn set_description(mut self, description: impl ToString) -> Self {
self.description = Some(description.to_string());
self.base_data.update_modified();
self
}
/// Set the start time
pub fn set_start_time(mut self, start_time: OffsetDateTime) -> Self {
self.start_time = start_time;
self.base_data.update_modified();
self
}
/// Set the end time
pub fn set_end_time(mut self, end_time: OffsetDateTime) -> Self {
self.end_time = end_time;
self.base_data.update_modified();
self
}
/// Set the location
pub fn set_location(mut self, location: impl ToString) -> Self {
self.location = Some(location.to_string());
self.base_data.update_modified();
self
}
/// Set the status
pub fn set_status(mut self, status: EventStatus) -> Self {
self.status = status;
self.base_data.update_modified();
self
}
/// Set as all-day event
pub fn set_all_day(mut self, all_day: bool) -> Self {
self.all_day = all_day;
self.base_data.update_modified();
self
}
/// Set the category
pub fn set_category(mut self, category: impl ToString) -> Self {
self.category = Some(category.to_string());
self.base_data.update_modified();
self
}
}
// Object trait implementation is auto-generated by #[derive(DeriveObject)]
// The derive macro generates: object_type(), base_data(), base_data_mut(), index_keys(), indexed_fields()