refactoring hexagonal and clean architecture
This commit is contained in:
@@ -32,14 +32,14 @@ impl Default for AddressBookDto {
|
||||
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,
|
||||
id: book.id().to_string(),
|
||||
name: book.name().to_string(),
|
||||
owner_id: book.owner_id().to_string(),
|
||||
description: book.description().map(|s| s.to_string()),
|
||||
color: book.color().map(|s| s.to_string()),
|
||||
is_public: book.is_public(),
|
||||
created_at: *book.created_at(),
|
||||
updated_at: *book.updated_at(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,26 +112,27 @@ impl Default for ContactDto {
|
||||
|
||||
impl From<Contact> for ContactDto {
|
||||
fn from(contact: Contact) -> Self {
|
||||
let parts = contact.into_parts();
|
||||
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,
|
||||
id: parts.id.to_string(),
|
||||
address_book_id: parts.address_book_id.to_string(),
|
||||
uid: parts.uid,
|
||||
full_name: parts.full_name,
|
||||
first_name: parts.first_name,
|
||||
last_name: parts.last_name,
|
||||
nickname: parts.nickname,
|
||||
email: parts.email.into_iter().map(EmailDto::from).collect(),
|
||||
phone: parts.phone.into_iter().map(PhoneDto::from).collect(),
|
||||
address: parts.address.into_iter().map(AddressDto::from).collect(),
|
||||
organization: parts.organization,
|
||||
title: parts.title,
|
||||
notes: parts.notes,
|
||||
photo_url: parts.photo_url,
|
||||
birthday: parts.birthday,
|
||||
anniversary: parts.anniversary,
|
||||
created_at: parts.created_at,
|
||||
updated_at: parts.updated_at,
|
||||
etag: parts.etag,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,11 +194,11 @@ pub struct ContactGroupDto {
|
||||
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,
|
||||
id: group.id().to_string(),
|
||||
address_book_id: group.address_book_id().to_string(),
|
||||
name: group.name().to_string(),
|
||||
created_at: *group.created_at(),
|
||||
updated_at: *group.updated_at(),
|
||||
members_count: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,20 +43,20 @@ pub struct UpdateShareDto {
|
||||
/// Extension methods to convert between DTOs and domain entities
|
||||
impl ShareDto {
|
||||
pub fn from_entity(share: &Share, base_url: &str) -> Self {
|
||||
let url = format!("{}/s/{}", base_url, share.token);
|
||||
let url = format!("{}/s/{}", base_url, share.token());
|
||||
|
||||
Self {
|
||||
id: share.id.clone(),
|
||||
item_id: share.item_id.clone(),
|
||||
item_type: share.item_type.to_string(),
|
||||
token: share.token.clone(),
|
||||
id: share.id().to_string(),
|
||||
item_id: share.item_id().to_string(),
|
||||
item_type: share.item_type().to_string(),
|
||||
token: share.token().to_string(),
|
||||
url,
|
||||
has_password: share.password_hash.is_some(),
|
||||
expires_at: share.expires_at,
|
||||
permissions: SharePermissionsDto::from_entity(&share.permissions),
|
||||
created_at: share.created_at,
|
||||
created_by: share.created_by.clone(),
|
||||
access_count: share.access_count,
|
||||
has_password: share.has_password(),
|
||||
expires_at: share.expires_at(),
|
||||
permissions: SharePermissionsDto::from_entity(share.permissions()),
|
||||
created_at: share.created_at(),
|
||||
created_by: share.created_by().to_string(),
|
||||
access_count: share.access_count(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,9 +64,9 @@ impl ShareDto {
|
||||
impl SharePermissionsDto {
|
||||
pub fn from_entity(permissions: &SharePermissions) -> Self {
|
||||
Self {
|
||||
read: permissions.read,
|
||||
write: permissions.write,
|
||||
reshare: permissions.reshare,
|
||||
read: permissions.read(),
|
||||
write: permissions.write(),
|
||||
reshare: permissions.reshare(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user