Add dto objects

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/5/head
trivernis 2 years ago
parent 1dedd8b327
commit a6da2b9e1e
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -0,0 +1,37 @@
use mediarepo_database::entities::file;
use mediarepo_database::entities::file_metadata;
use mediarepo_database::entities::content_descriptor;
use crate::dto::FileMetadataDto;
#[derive(Clone, Debug)]
pub struct FileDto {
model: file::Model,
content_descriptor: content_descriptor::Model,
metadata: Option<FileMetadataDto>,
}
impl FileDto {
pub(crate) fn new(model: file::Model, content_descriptor: content_descriptor::Model, metadata: Option<file_metadata::Model>) -> Self {
Self {
model,
content_descriptor,
metadata: metadata.map(FileMetadataDto::new)
}
}
pub fn id(&self) -> i64 {
self.model.id
}
pub fn cd_id(&self) -> i64 {
self.model.cd_id
}
pub fn cd(&self) -> &[u8] {
&self.content_descriptor.descriptor
}
pub fn metadata(&self) -> Option<&FileMetadataDto> {
self.metadata.as_ref()
}
}

@ -0,0 +1,41 @@
use chrono::NaiveDateTime;
use mediarepo_database::entities::file_metadata;
#[derive(Clone, Debug)]
pub struct FileMetadataDto {
model: file_metadata::Model,
}
impl FileMetadataDto {
pub(crate) fn new(model: file_metadata::Model) -> Self {
Self {model}
}
pub fn file_id(&self) -> i64 {
self.model.file_id
}
pub fn name(&self) -> Option<&String> {
self.model.name.as_ref()
}
pub fn comment(&self) -> Option<&String> {
self.model.comment.as_ref()
}
pub fn size(&self) -> i64 {
self.model.size
}
pub fn import_time(&self) -> NaiveDateTime {
self.model.import_time
}
pub fn creation_time(&self) -> NaiveDateTime {
self.model.creation_time
}
pub fn change_time(&self) -> NaiveDateTime {
self.model.change_time
}
}

@ -0,0 +1,11 @@
mod file;
mod file_metadata;
mod tag;
mod namespace;
mod thumbnail;
pub use file::*;
pub use file_metadata::*;
pub use tag::*;
pub use namespace::*;
pub use thumbnail::*;

@ -0,0 +1,20 @@
use mediarepo_database::entities::namespace;
#[derive(Clone, Debug)]
pub struct NamespaceDto {
model: namespace::Model,
}
impl NamespaceDto {
pub(crate) fn new(model: namespace::Model) -> Self {
Self {model}
}
pub fn id(&self) -> i64 {
self.model.id
}
pub fn name(&self) -> &String {
&self.model.name
}
}

@ -0,0 +1,30 @@
pub use mediarepo_database::entities::tag;
pub use mediarepo_database::entities::namespace;
use crate::dto::NamespaceDto;
#[derive(Clone, Debug)]
pub struct TagDto {
model: tag::Model,
namespace: Option<NamespaceDto>,
}
impl TagDto {
pub(crate) fn new(model: tag::Model, namespace_model: Option<namespace::Model>) -> Self {
Self {
model,
namespace: namespace_model.map(NamespaceDto::new)
}
}
pub fn id(&self) -> i64 {
self.model.id
}
pub fn name(&self) -> &String {
&self.model.name
}
pub fn namespace(&self) -> Option<&NamespaceDto> {
self.namespace.as_ref()
}
}

@ -0,0 +1,26 @@
use mediarepo_core::fs::thumbnail_store::Dimensions;
#[derive(Clone, Debug)]
pub struct ThumbnailDto {
parent_cd: String,
size: Dimensions,
mime_type: String,
}
impl ThumbnailDto {
pub fn new(parent_cd: String, size: Dimensions, mime_type: String) -> Self {
Self {parent_cd, size, mime_type}
}
pub fn parent_cd(&self) -> &String {
&self.parent_cd
}
pub fn size(&self) -> &Dimensions {
&self.size
}
pub fn mime_type(&self) -> &String {
&self.mime_type
}
}

@ -6,3 +6,4 @@ pub mod repo;
pub mod tag;
pub mod thumbnail;
pub mod type_keys;
pub mod dto;

Loading…
Cancel
Save