use libertas_core::models::{Album, AlbumPermission, AlbumShare, FaceRegion, Media, MediaMetadata, MediaMetadataSource, Person, PersonPermission, Role, Tag, User}; use crate::db_models::{PostgresAlbum, PostgresAlbumPermission, PostgresAlbumShare, PostgresFaceRegion, PostgresMedia, PostgresMediaMetadata, PostgresMediaMetadataSource, PostgresPerson, PostgresPersonPermission, PostgresPersonShared, PostgresRole, PostgresTag, PostgresUser}; impl From for Role { fn from(pg_role: PostgresRole) -> Self { match pg_role { PostgresRole::User => Role::User, PostgresRole::Admin => Role::Admin, } } } impl From for PostgresRole { fn from(role: Role) -> Self { match role { Role::User => PostgresRole::User, Role::Admin => PostgresRole::Admin, } } } impl From for MediaMetadataSource { fn from(pg_source: PostgresMediaMetadataSource) -> Self { match pg_source { PostgresMediaMetadataSource::Exif => MediaMetadataSource::Exif, PostgresMediaMetadataSource::TrackInfo => MediaMetadataSource::TrackInfo, } } } impl From for PostgresMediaMetadataSource { fn from(source: MediaMetadataSource) -> Self { match source { MediaMetadataSource::Exif => PostgresMediaMetadataSource::Exif, MediaMetadataSource::TrackInfo => PostgresMediaMetadataSource::TrackInfo, } } } impl From for User { fn from(pg_user: PostgresUser) -> Self { User { id: pg_user.id, username: pg_user.username, email: pg_user.email, hashed_password: pg_user.hashed_password, created_at: pg_user.created_at, updated_at: pg_user.updated_at, role: Role::from(pg_user.role.as_str()), storage_quota: pg_user.storage_quota, storage_used: pg_user.storage_used, } } } impl From for Album { fn from(pg_album: PostgresAlbum) -> Self { Album { id: pg_album.id, owner_id: pg_album.owner_id, name: pg_album.name, description: pg_album.description, is_public: pg_album.is_public, created_at: pg_album.created_at, updated_at: pg_album.updated_at, } } } impl From for Media { fn from(pg_media: PostgresMedia) -> Self { Media { id: pg_media.id, owner_id: pg_media.owner_id, storage_path: pg_media.storage_path, original_filename: pg_media.original_filename, mime_type: pg_media.mime_type, hash: pg_media.hash, created_at: pg_media.created_at, thumbnail_path: pg_media.thumbnail_path, } } } impl From for MediaMetadata { fn from(pg_metadata: PostgresMediaMetadata) -> Self { MediaMetadata { id: pg_metadata.id, media_id: pg_metadata.media_id, source: MediaMetadataSource::from(pg_metadata.source.as_str()), tag_name: pg_metadata.tag_name, tag_value: pg_metadata.tag_value, } } } impl From for AlbumPermission { fn from(pg_permission: PostgresAlbumPermission) -> Self { match pg_permission { PostgresAlbumPermission::View => AlbumPermission::View, PostgresAlbumPermission::Contribute => AlbumPermission::Contribute, } } } impl From for PostgresAlbumPermission { fn from(permission: AlbumPermission) -> Self { match permission { AlbumPermission::View => PostgresAlbumPermission::View, AlbumPermission::Contribute => PostgresAlbumPermission::Contribute, } } } impl From for AlbumShare { fn from(pg_share: PostgresAlbumShare) -> Self { AlbumShare { album_id: pg_share.album_id, user_id: pg_share.user_id, permission: AlbumPermission::from(pg_share.permission), } } } impl From for Tag { fn from(pg_tag: PostgresTag) -> Self { Tag { id: pg_tag.id, name: pg_tag.name, } } } impl From for Person { fn from(pg_person: PostgresPerson) -> Self { Person { id: pg_person.id, owner_id: pg_person.owner_id, name: pg_person.name, thumbnail_media_id: None, // Not in the DB schema } } } impl From for FaceRegion { fn from(pg_face: PostgresFaceRegion) -> Self { FaceRegion { id: pg_face.id, media_id: pg_face.media_id, person_id: pg_face.person_id, x_min: pg_face.x_min, y_min: pg_face.y_min, x_max: pg_face.x_max, y_max: pg_face.y_max, } } } impl From for PersonPermission { fn from(pg_perm: PostgresPersonPermission) -> Self { match pg_perm { PostgresPersonPermission::View => PersonPermission::View, PostgresPersonPermission::CanUse => PersonPermission::CanUse, } } } impl From for PostgresPersonPermission { fn from(perm: PersonPermission) -> Self { match perm { PersonPermission::View => PostgresPersonPermission::View, PersonPermission::CanUse => PostgresPersonPermission::CanUse, } } } impl From for (Person, PersonPermission) { fn from(pg_shared: PostgresPersonShared) -> Self { let person = Person { id: pg_shared.id, owner_id: pg_shared.owner_id, name: pg_shared.name, thumbnail_media_id: None, }; let permission = PersonPermission::from(pg_shared.permission); (person, permission) } }