...
This commit is contained in:
94
actix_mvc_app/src/models/calendar.rs
Normal file
94
actix_mvc_app/src/models/calendar.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Represents a calendar event
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CalendarEvent {
|
||||
/// Unique identifier for the event
|
||||
pub id: String,
|
||||
/// Title of the event
|
||||
pub title: String,
|
||||
/// Description of the event
|
||||
pub description: String,
|
||||
/// Start time of the event
|
||||
pub start_time: DateTime<Utc>,
|
||||
/// End time of the event
|
||||
pub end_time: DateTime<Utc>,
|
||||
/// Color of the event (hex code)
|
||||
pub color: String,
|
||||
/// Whether the event is an all-day event
|
||||
pub all_day: bool,
|
||||
/// User ID of the event creator
|
||||
pub user_id: Option<String>,
|
||||
}
|
||||
|
||||
impl CalendarEvent {
|
||||
/// Creates a new calendar event
|
||||
pub fn new(
|
||||
title: String,
|
||||
description: String,
|
||||
start_time: DateTime<Utc>,
|
||||
end_time: DateTime<Utc>,
|
||||
color: Option<String>,
|
||||
all_day: bool,
|
||||
user_id: Option<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4().to_string(),
|
||||
title,
|
||||
description,
|
||||
start_time,
|
||||
end_time,
|
||||
color: color.unwrap_or_else(|| "#4285F4".to_string()), // Google Calendar blue
|
||||
all_day,
|
||||
user_id,
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts the event to a JSON string
|
||||
pub fn to_json(&self) -> Result<String, serde_json::Error> {
|
||||
serde_json::to_string(self)
|
||||
}
|
||||
|
||||
/// Creates an event from a JSON string
|
||||
pub fn from_json(json: &str) -> Result<Self, serde_json::Error> {
|
||||
serde_json::from_str(json)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a view mode for the calendar
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CalendarViewMode {
|
||||
/// Year view
|
||||
Year,
|
||||
/// Month view
|
||||
Month,
|
||||
/// Week view
|
||||
Week,
|
||||
/// Day view
|
||||
Day,
|
||||
}
|
||||
|
||||
impl CalendarViewMode {
|
||||
/// Converts a string to a view mode
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"year" => Self::Year,
|
||||
"month" => Self::Month,
|
||||
"week" => Self::Week,
|
||||
"day" => Self::Day,
|
||||
_ => Self::Month, // Default to month view
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts the view mode to a string
|
||||
pub fn to_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Year => "year",
|
||||
Self::Month => "month",
|
||||
Self::Week => "week",
|
||||
Self::Day => "day",
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
// Export models
|
||||
pub mod user;
|
||||
pub mod ticket;
|
||||
pub mod calendar;
|
||||
|
||||
// Re-export models for easier imports
|
||||
pub use user::User;
|
||||
pub use ticket::{Ticket, TicketComment, TicketStatus, TicketPriority, TicketFilter};
|
||||
pub use ticket::{Ticket, TicketComment, TicketStatus, TicketPriority, TicketFilter};
|
||||
pub use calendar::{CalendarEvent, CalendarViewMode};
|
Reference in New Issue
Block a user