adding card dav and cald dav

This commit is contained in:
DioCrafts
2025-04-13 01:04:04 +02:00
parent f2ecbc1a39
commit 52d8250d51
52 changed files with 8056 additions and 536 deletions
+76
View File
@@ -0,0 +1,76 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::domain::entities::contact::AddressBook;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressBookDto {
pub id: String,
pub name: String,
pub owner_id: String,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Default for AddressBookDto {
fn default() -> Self {
Self {
id: uuid::Uuid::new_v4().to_string(),
name: "Default Address Book".to_string(),
owner_id: "default".to_string(),
description: None,
color: None,
is_public: false,
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}
impl From<AddressBook> for AddressBookDto {
fn from(book: AddressBook) -> Self {
Self {
id: book.id.to_string(),
name: book.name,
owner_id: book.owner_id,
description: book.description,
color: book.color,
is_public: book.is_public,
created_at: book.created_at,
updated_at: book.updated_at,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateAddressBookDto {
pub name: String,
pub owner_id: String,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateAddressBookDto {
pub name: Option<String>,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: Option<bool>,
pub user_id: String, // Current user making the update
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShareAddressBookDto {
pub address_book_id: String,
pub user_id: String,
pub can_write: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UnshareAddressBookDto {
pub address_book_id: String,
pub user_id: String,
}
+182
View File
@@ -0,0 +1,182 @@
use serde::{Serialize, Deserialize};
use chrono::{DateTime, Utc};
use uuid::Uuid;
use std::collections::HashMap;
use crate::domain::entities::calendar::Calendar;
use crate::domain::entities::calendar_event::CalendarEvent;
/// DTO for calendar data transfer
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CalendarDto {
pub id: String,
pub name: String,
pub owner_id: String,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub custom_properties: HashMap<String, String>,
}
impl Default for CalendarDto {
fn default() -> Self {
Self {
id: String::new(),
name: String::new(),
owner_id: String::new(),
description: None,
color: None,
is_public: false,
created_at: Utc::now(),
updated_at: Utc::now(),
custom_properties: HashMap::new(),
}
}
}
impl From<Calendar> for CalendarDto {
fn from(calendar: Calendar) -> Self {
Self {
id: calendar.id().to_string(),
name: calendar.name().to_string(),
owner_id: calendar.owner_id().to_string(),
description: calendar.description().map(|s| s.to_string()),
color: calendar.color().map(|s| s.to_string()),
is_public: false, // This needs to be set separately as it's not part of the domain entity
created_at: *calendar.created_at(),
updated_at: *calendar.updated_at(),
custom_properties: calendar.custom_properties().clone(),
}
}
}
/// DTO for calendar creation
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateCalendarDto {
pub name: String,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: Option<bool>,
}
/// DTO for calendar update
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateCalendarDto {
pub name: Option<String>,
pub description: Option<String>,
pub color: Option<String>,
pub is_public: Option<bool>,
}
/// DTO for calendar sharing
#[derive(Debug, Serialize, Deserialize)]
pub struct CalendarShareDto {
pub calendar_id: String,
pub user_id: String,
pub access_level: String, // 'read', 'write', 'owner'
}
/// DTO for calendar event data transfer
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CalendarEventDto {
pub id: String,
pub calendar_id: String,
pub summary: String,
pub description: Option<String>,
pub location: Option<String>,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
pub all_day: bool,
pub rrule: Option<String>,
pub ical_uid: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Default for CalendarEventDto {
fn default() -> Self {
Self {
id: String::new(),
calendar_id: String::new(),
summary: String::new(),
description: None,
location: None,
start_time: Utc::now(),
end_time: Utc::now(),
all_day: false,
rrule: None,
ical_uid: String::new(),
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}
impl From<CalendarEvent> for CalendarEventDto {
fn from(event: CalendarEvent) -> Self {
Self {
id: event.id().to_string(),
calendar_id: event.calendar_id().to_string(),
summary: event.summary().to_string(),
description: event.description().map(|s| s.to_string()),
location: event.location().map(|s| s.to_string()),
start_time: *event.start_time(),
end_time: *event.end_time(),
all_day: event.all_day(),
rrule: event.rrule().map(|s| s.to_string()),
ical_uid: event.ical_uid().to_string(),
created_at: *event.created_at(),
updated_at: *event.updated_at(),
}
}
}
/// DTO for calendar event creation using iCalendar data
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateEventICalDto {
pub calendar_id: String,
pub ical_data: String,
}
/// DTO for calendar event creation with structured data
#[derive(Debug, Serialize, Deserialize)]
pub struct CreateEventDto {
pub calendar_id: String,
pub summary: String,
pub description: Option<String>,
pub location: Option<String>,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
pub all_day: Option<bool>,
pub rrule: Option<String>,
pub user_id: String, // Added for authorization
}
/// DTO for updating a calendar event
#[derive(Debug, Serialize, Deserialize)]
pub struct UpdateEventDto {
pub summary: Option<String>,
pub description: Option<String>,
pub location: Option<String>,
pub start_time: Option<DateTime<Utc>>,
pub end_time: Option<DateTime<Utc>>,
pub all_day: Option<bool>,
pub rrule: Option<String>,
pub user_id: String, // Added for authorization
}
/// DTO for querying events in a time range
#[derive(Debug, Serialize, Deserialize)]
pub struct EventQueryDto {
pub calendar_id: String,
pub start: DateTime<Utc>,
pub end: DateTime<Utc>,
}
/// DTO for pagination
#[derive(Debug, Serialize, Deserialize)]
pub struct PaginationDto {
pub limit: Option<i64>,
pub offset: Option<i64>,
}
+223
View File
@@ -0,0 +1,223 @@
use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use crate::domain::entities::contact::{Contact, Email, Phone, Address, ContactGroup};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmailDto {
pub email: String,
pub r#type: String,
pub is_primary: bool,
}
impl From<Email> for EmailDto {
fn from(email: Email) -> Self {
Self {
email: email.email,
r#type: email.r#type,
is_primary: email.is_primary,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PhoneDto {
pub number: String,
pub r#type: String,
pub is_primary: bool,
}
impl From<Phone> for PhoneDto {
fn from(phone: Phone) -> Self {
Self {
number: phone.number,
r#type: phone.r#type,
is_primary: phone.is_primary,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressDto {
pub street: Option<String>,
pub city: Option<String>,
pub state: Option<String>,
pub postal_code: Option<String>,
pub country: Option<String>,
pub r#type: String,
pub is_primary: bool,
}
impl From<Address> for AddressDto {
fn from(address: Address) -> Self {
Self {
street: address.street,
city: address.city,
state: address.state,
postal_code: address.postal_code,
country: address.country,
r#type: address.r#type,
is_primary: address.is_primary,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContactDto {
pub id: String,
pub address_book_id: String,
pub uid: String,
pub full_name: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub nickname: Option<String>,
pub email: Vec<EmailDto>,
pub phone: Vec<PhoneDto>,
pub address: Vec<AddressDto>,
pub organization: Option<String>,
pub title: Option<String>,
pub notes: Option<String>,
pub photo_url: Option<String>,
pub birthday: Option<NaiveDate>,
pub anniversary: Option<NaiveDate>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub etag: String,
}
impl Default for ContactDto {
fn default() -> Self {
Self {
id: uuid::Uuid::new_v4().to_string(),
address_book_id: uuid::Uuid::new_v4().to_string(),
uid: format!("{}@oxicloud", uuid::Uuid::new_v4()),
full_name: None,
first_name: None,
last_name: None,
nickname: None,
email: Vec::new(),
phone: Vec::new(),
address: Vec::new(),
organization: None,
title: None,
notes: None,
photo_url: None,
birthday: None,
anniversary: None,
created_at: Utc::now(),
updated_at: Utc::now(),
etag: uuid::Uuid::new_v4().to_string(),
}
}
}
impl From<Contact> for ContactDto {
fn from(contact: Contact) -> Self {
Self {
id: contact.id.to_string(),
address_book_id: contact.address_book_id.to_string(),
uid: contact.uid,
full_name: contact.full_name,
first_name: contact.first_name,
last_name: contact.last_name,
nickname: contact.nickname,
email: contact.email.into_iter().map(EmailDto::from).collect(),
phone: contact.phone.into_iter().map(PhoneDto::from).collect(),
address: contact.address.into_iter().map(AddressDto::from).collect(),
organization: contact.organization,
title: contact.title,
notes: contact.notes,
photo_url: contact.photo_url,
birthday: contact.birthday,
anniversary: contact.anniversary,
created_at: contact.created_at,
updated_at: contact.updated_at,
etag: contact.etag,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateContactDto {
pub address_book_id: String,
pub full_name: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub nickname: Option<String>,
pub email: Vec<EmailDto>,
pub phone: Vec<PhoneDto>,
pub address: Vec<AddressDto>,
pub organization: Option<String>,
pub title: Option<String>,
pub notes: Option<String>,
pub photo_url: Option<String>,
pub birthday: Option<NaiveDate>,
pub anniversary: Option<NaiveDate>,
pub user_id: String, // User creating the contact
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateContactDto {
pub full_name: Option<String>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub nickname: Option<String>,
pub email: Option<Vec<EmailDto>>,
pub phone: Option<Vec<PhoneDto>>,
pub address: Option<Vec<AddressDto>>,
pub organization: Option<String>,
pub title: Option<String>,
pub notes: Option<String>,
pub photo_url: Option<String>,
pub birthday: Option<NaiveDate>,
pub anniversary: Option<NaiveDate>,
pub user_id: String, // User updating the contact
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateContactVCardDto {
pub address_book_id: String,
pub vcard: String,
pub user_id: String, // User creating the contact
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContactGroupDto {
pub id: String,
pub address_book_id: String,
pub name: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub members_count: Option<i32>,
}
impl From<ContactGroup> for ContactGroupDto {
fn from(group: ContactGroup) -> Self {
Self {
id: group.id.to_string(),
address_book_id: group.address_book_id.to_string(),
name: group.name,
created_at: group.created_at,
updated_at: group.updated_at,
members_count: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateContactGroupDto {
pub address_book_id: String,
pub name: String,
pub user_id: String, // User creating the group
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateContactGroupDto {
pub name: String,
pub user_id: String, // User updating the group
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GroupMembershipDto {
pub group_id: String,
pub contact_id: String,
}
+7 -4
View File
@@ -1,11 +1,14 @@
pub mod address_book_dto;
pub mod calendar_dto;
pub mod contact_dto;
pub mod favorites_dto;
pub mod file_dto;
pub mod folder_dto;
pub mod i18n_dto;
pub mod pagination;
pub mod user_dto;
pub mod trash_dto;
pub mod recent_dto;
pub mod search_dto;
pub mod share_dto;
pub mod favorites_dto;
pub mod recent_dto;
pub mod trash_dto;
pub mod user_dto;