96
libertas_infra/src/mappers.rs
Normal file
96
libertas_infra/src/mappers.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
use libertas_core::models::{Album, AlbumPermission, AlbumShare, Media, Role, User};
|
||||
|
||||
use crate::db_models::{PostgresAlbum, PostgresAlbumPermission, PostgresAlbumShare, PostgresMedia, PostgresRole, PostgresUser};
|
||||
|
||||
impl From<PostgresRole> for Role {
|
||||
fn from(pg_role: PostgresRole) -> Self {
|
||||
match pg_role {
|
||||
PostgresRole::User => Role::User,
|
||||
PostgresRole::Admin => Role::Admin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Role> for PostgresRole {
|
||||
fn from(role: Role) -> Self {
|
||||
match role {
|
||||
Role::User => PostgresRole::User,
|
||||
Role::Admin => PostgresRole::Admin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PostgresUser> 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<PostgresAlbum> 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<PostgresMedia> 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,
|
||||
extracted_location: pg_media.extracted_location,
|
||||
width: pg_media.width,
|
||||
height: pg_media.height,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PostgresAlbumPermission> for AlbumPermission {
|
||||
fn from(pg_permission: PostgresAlbumPermission) -> Self {
|
||||
match pg_permission {
|
||||
PostgresAlbumPermission::View => AlbumPermission::View,
|
||||
PostgresAlbumPermission::Contribute => AlbumPermission::Contribute,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AlbumPermission> for PostgresAlbumPermission {
|
||||
fn from(permission: AlbumPermission) -> Self {
|
||||
match permission {
|
||||
AlbumPermission::View => PostgresAlbumPermission::View,
|
||||
AlbumPermission::Contribute => PostgresAlbumPermission::Contribute,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PostgresAlbumShare> 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user