feat: Enhance calendar example with Event and Calendar features
- Add EventStatus enum to represent event states (Draft, Published, Cancelled). - Extend Event model with color, category, reminder, timezone, created_by, all_day and is_recurring fields. - Add color and description fields to Calendar model. - Enhance calendar example to demonstrate new features, including event status changes, and detailed calendar information. - Improve example output for clarity and comprehensiveness. - Add owner_id and is_public fields to Calendar model for enhanced management. 2025-05-28 13:09:05,630 - INFO - Commit message copied to clipboard.
This commit is contained in:
@@ -14,6 +14,14 @@ pub enum AttendanceStatus {
|
||||
NoResponse = 3,
|
||||
}
|
||||
|
||||
/// Represents the status of an event
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum EventStatus {
|
||||
Draft = 0,
|
||||
Published = 1,
|
||||
Cancelled = 2,
|
||||
}
|
||||
|
||||
/// Represents an attendee of an event
|
||||
#[model]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
@@ -74,6 +82,22 @@ pub struct Event {
|
||||
pub attendees: Vec<u32>,
|
||||
/// Optional location of the event
|
||||
pub location: Option<String>,
|
||||
/// Color for the event (hex color code)
|
||||
pub color: Option<String>,
|
||||
/// Whether this is an all-day event
|
||||
pub all_day: bool,
|
||||
/// ID of the user who created the event
|
||||
pub created_by: Option<u32>,
|
||||
/// Status of the event
|
||||
pub status: EventStatus,
|
||||
/// Whether this is a recurring event
|
||||
pub is_recurring: bool,
|
||||
/// Optional timezone for display purposes
|
||||
pub timezone: Option<String>,
|
||||
/// Optional category/tag for the event
|
||||
pub category: Option<String>,
|
||||
/// Optional reminder settings (minutes before event)
|
||||
pub reminder_minutes: Option<i32>,
|
||||
}
|
||||
|
||||
impl Event {
|
||||
@@ -87,6 +111,14 @@ impl Event {
|
||||
end_time,
|
||||
attendees: Vec::new(),
|
||||
location: None,
|
||||
color: Some("#4285F4".to_string()), // Default blue color
|
||||
all_day: false,
|
||||
created_by: None,
|
||||
status: EventStatus::Published,
|
||||
is_recurring: false,
|
||||
timezone: None,
|
||||
category: None,
|
||||
reminder_minutes: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +142,14 @@ impl Event {
|
||||
end_time,
|
||||
attendees: Vec::new(),
|
||||
location: None,
|
||||
color: Some("#4285F4".to_string()), // Default blue color
|
||||
all_day: false,
|
||||
created_by: None,
|
||||
status: EventStatus::Published,
|
||||
is_recurring: false,
|
||||
timezone: None,
|
||||
category: None,
|
||||
reminder_minutes: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +171,54 @@ impl Event {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the color for the event
|
||||
pub fn color(mut self, color: impl ToString) -> Self {
|
||||
self.color = Some(color.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether this is an all-day event
|
||||
pub fn all_day(mut self, all_day: bool) -> Self {
|
||||
self.all_day = all_day;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the creator of the event
|
||||
pub fn created_by(mut self, user_id: u32) -> Self {
|
||||
self.created_by = Some(user_id);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the status of the event
|
||||
pub fn status(mut self, status: EventStatus) -> Self {
|
||||
self.status = status;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether this is a recurring event
|
||||
pub fn is_recurring(mut self, is_recurring: bool) -> Self {
|
||||
self.is_recurring = is_recurring;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the timezone for the event
|
||||
pub fn timezone(mut self, timezone: impl ToString) -> Self {
|
||||
self.timezone = Some(timezone.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the category for the event
|
||||
pub fn category(mut self, category: impl ToString) -> Self {
|
||||
self.category = Some(category.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets reminder minutes before the event
|
||||
pub fn reminder_minutes(mut self, minutes: i32) -> Self {
|
||||
self.reminder_minutes = Some(minutes);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an attendee ID to the event
|
||||
pub fn add_attendee(mut self, attendee_id: u32) -> Self {
|
||||
// Prevent duplicate attendees by ID
|
||||
@@ -169,16 +257,18 @@ impl Event {
|
||||
pub struct Calendar {
|
||||
/// Base model data
|
||||
pub base_data: BaseModelData,
|
||||
|
||||
/// Name of the calendar
|
||||
pub name: String,
|
||||
|
||||
/// Optional description of the calendar
|
||||
pub description: Option<String>,
|
||||
|
||||
/// List of events in the calendar
|
||||
// For now, events are embedded. If they become separate models, this would be Vec<[IDType]>.
|
||||
/// List of event IDs in the calendar
|
||||
pub events: Vec<i64>,
|
||||
/// ID of the user who owns this calendar
|
||||
pub owner_id: Option<u32>,
|
||||
/// Whether this calendar is public
|
||||
pub is_public: bool,
|
||||
/// Color theme for the calendar (hex color code)
|
||||
pub color: Option<String>,
|
||||
}
|
||||
|
||||
impl Calendar {
|
||||
@@ -198,6 +288,9 @@ impl Calendar {
|
||||
name: name.to_string(),
|
||||
description: None,
|
||||
events: Vec::new(),
|
||||
owner_id: None,
|
||||
is_public: false,
|
||||
color: Some("#4285F4".to_string()), // Default blue color
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +306,24 @@ impl Calendar {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the owner of the calendar
|
||||
pub fn owner_id(mut self, user_id: u32) -> Self {
|
||||
self.owner_id = Some(user_id);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether the calendar is public
|
||||
pub fn is_public(mut self, is_public: bool) -> Self {
|
||||
self.is_public = is_public;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the color for the calendar
|
||||
pub fn color(mut self, color: impl ToString) -> Self {
|
||||
self.color = Some(color.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an event to the calendar
|
||||
pub fn add_event(mut self, event_id: i64) -> Self {
|
||||
// Prevent duplicate events by id
|
||||
|
@@ -2,6 +2,6 @@
|
||||
pub mod calendar;
|
||||
pub mod rhai;
|
||||
|
||||
// Re-export Calendar, Event, Attendee, and AttendanceStatus from the inner calendar module (calendar.rs) within src/models/calendar/mod.rs
|
||||
pub use self::calendar::{Calendar, Event, Attendee, AttendanceStatus};
|
||||
// Re-export Calendar, Event, Attendee, AttendanceStatus, and EventStatus from the inner calendar module (calendar.rs) within src/models/calendar/mod.rs
|
||||
pub use self::calendar::{AttendanceStatus, Attendee, Calendar, Event, EventStatus};
|
||||
pub use rhai::register_rhai_engine_functions as register_calendar_rhai_module;
|
||||
|
Reference in New Issue
Block a user