feat: Add JSON serialization/deserialization to Event struct

- Added `to_json` method to serialize Event to JSON string.
- Added `from_json` method to deserialize Event from JSON string.
- This allows for easier data exchange and persistence.
This commit is contained in:
Mahmoud-Emad 2025-06-03 15:32:28 +03:00
parent 8e2354df43
commit 20c075ec51

View File

@ -101,6 +101,16 @@ pub struct Event {
}
impl Event {
/// 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)
}
/// Creates a new event with auto-generated ID
pub fn new(title: impl ToString, start_time: DateTime<Utc>, end_time: DateTime<Utc>) -> Self {
Self {