Create library item repository.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use std::fs::File;
|
||||
use std::io::{Error, ErrorKind};
|
||||
use uuid::Uuid;
|
||||
use lumiere_domain::video::model::library_item::{LibraryItem, LibraryItemType};
|
||||
|
||||
pub struct TokioVideoFile {
|
||||
pub file: File
|
||||
@@ -10,4 +13,40 @@ impl TokioVideoFile {
|
||||
file: File::open(file_path).expect(format!("Failed to open file {file_path}").as_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct LibraryItemEntity {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub r#type: i8,
|
||||
pub parent_folder_id: Option<Uuid>
|
||||
}
|
||||
|
||||
impl LibraryItemEntity {
|
||||
pub fn from_library_item(library_item: &LibraryItem) -> Result<Self, Error> {
|
||||
Ok(
|
||||
Self {
|
||||
id: library_item.id.clone(),
|
||||
name: library_item.name.clone(),
|
||||
r#type: Self::map_type_to_i8(library_item.r#type)?,
|
||||
parent_folder_id: None
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn map_type_to_i8(item_type: LibraryItemType) -> Result<i8, Error> {
|
||||
match item_type {
|
||||
LibraryItemType::VIDEO => Ok(0),
|
||||
LibraryItemType::FOLDER => Ok(1)
|
||||
}
|
||||
}
|
||||
|
||||
fn map_type_from_i8(item_type_number: i8) -> Result<LibraryItemType, Error> {
|
||||
match item_type_number {
|
||||
0 => Ok(LibraryItemType::VIDEO),
|
||||
1 => Ok(LibraryItemType::FOLDER),
|
||||
unknown_value => Err(Error::new(ErrorKind::InvalidData, format!("Unknown library item type value from database: {unknown_value}")))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user