From a6da2b9e1e3ab30c9c33942db34e426780673ab9 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 19 Jan 2022 20:33:10 +0100 Subject: [PATCH] Add dto objects Signed-off-by: trivernis --- .../mediarepo-logic/src/dto/file.rs | 37 +++++++++++++++++ .../mediarepo-logic/src/dto/file_metadata.rs | 41 +++++++++++++++++++ .../mediarepo-logic/src/dto/mod.rs | 11 +++++ .../mediarepo-logic/src/dto/namespace.rs | 20 +++++++++ .../mediarepo-logic/src/dto/tag.rs | 30 ++++++++++++++ .../mediarepo-logic/src/dto/thumbnail.rs | 26 ++++++++++++ mediarepo-daemon/mediarepo-logic/src/lib.rs | 1 + 7 files changed, 166 insertions(+) create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/file.rs create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/mod.rs create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/namespace.rs create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/tag.rs create mode 100644 mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/file.rs b/mediarepo-daemon/mediarepo-logic/src/dto/file.rs new file mode 100644 index 0000000..4832511 --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/file.rs @@ -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, +} + +impl FileDto { + pub(crate) fn new(model: file::Model, content_descriptor: content_descriptor::Model, metadata: Option) -> 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() + } +} \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs b/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs new file mode 100644 index 0000000..651d209 --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/file_metadata.rs @@ -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 + } +} \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs new file mode 100644 index 0000000..e14493c --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/mod.rs @@ -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::*; \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/namespace.rs b/mediarepo-daemon/mediarepo-logic/src/dto/namespace.rs new file mode 100644 index 0000000..2729ecc --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/namespace.rs @@ -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 + } +} \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs b/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs new file mode 100644 index 0000000..9a37e8a --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/tag.rs @@ -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, +} + +impl TagDto { + pub(crate) fn new(model: tag::Model, namespace_model: Option) -> 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() + } +} \ No newline at end of file diff --git a/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs b/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs new file mode 100644 index 0000000..224d739 --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dto/thumbnail.rs @@ -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 + } +} diff --git a/mediarepo-daemon/mediarepo-logic/src/lib.rs b/mediarepo-daemon/mediarepo-logic/src/lib.rs index 7706ef2..c10ebac 100644 --- a/mediarepo-daemon/mediarepo-logic/src/lib.rs +++ b/mediarepo-daemon/mediarepo-logic/src/lib.rs @@ -6,3 +6,4 @@ pub mod repo; pub mod tag; pub mod thumbnail; pub mod type_keys; +pub mod dto;