diff --git a/backend/application/src/video/service.rs b/backend/application/src/video/service.rs index 4ccebc9..8f5c200 100644 --- a/backend/application/src/video/service.rs +++ b/backend/application/src/video/service.rs @@ -5,7 +5,7 @@ use std::io::{BufRead, BufReader}; use std::path::Path; use std::io::Read; use lumiere_domain::video::error::VideoError; -use lumiere_domain::video::model::library_item::LibraryItem; +use lumiere_domain::video::model::library_item::{LibraryItem, ReadLibraryItem}; use lumiere_domain::video::port::VideoPort; #[derive(Clone)] @@ -19,15 +19,12 @@ impl VideoService { } pub fn list_root_folder(self) -> Result, VideoError> { - let library_items = self.video_port.list_root_folder()?; - - let items_without_id = library_items.iter().filter(|item| item.id == None); - // generate a new Uuid for each item without id - // assign this new Uuid to the item - // save the item by using the method video_port.save - // replace the items_without_id by modified items_without_id - - Ok(vec!()) + let read_items_with_possibly_no_id = self.video_port.list_root_folder()?; + let items_with_id = read_items_with_possibly_no_id.iter() + .map(ReadLibraryItem::map_to_library_item) + .collect(); + self.video_port.save_all(items_with_id); + Ok(items_with_id) } } diff --git a/backend/domain/src/video/model/library_item.rs b/backend/domain/src/video/model/library_item.rs index 63f4ddb..b272393 100644 --- a/backend/domain/src/video/model/library_item.rs +++ b/backend/domain/src/video/model/library_item.rs @@ -1,3 +1,4 @@ +use std::io::Read; use uuid::Uuid; pub enum LibraryItemType { @@ -15,4 +16,13 @@ pub struct ReadLibraryItem { pub id: Option, pub name: String, pub r#type: LibraryItemType, +} +impl ReadLibraryItem { + pub fn map_to_library_item(&self) -> LibraryItem { + LibraryItem { + id: self.id.unwrap_or(Uuid::new_v4()), + name: self.name, + r#type: self.r#type, + } + } } \ No newline at end of file diff --git a/backend/domain/src/video/port.rs b/backend/domain/src/video/port.rs index d78bfcb..5af453c 100644 --- a/backend/domain/src/video/port.rs +++ b/backend/domain/src/video/port.rs @@ -7,7 +7,7 @@ pub trait VideoPort: Send + Sync { fn list_root_folder(&self) -> Result, VideoError>; fn list_folder(&self, folder_id: Uuid) -> Result, VideoError>; fn get_video_stream(&self, video_id: Uuid) -> Result; - fn save(&self, library_item: LibraryItem) -> Result<(), VideoError>; + fn save(&self, library_item: &LibraryItem) -> Result<(), VideoError>; fn clone_box(&self) -> Box; } diff --git a/backend/infrastructure/src/video/adapter.rs b/backend/infrastructure/src/video/adapter.rs new file mode 100644 index 0000000..5eb05d1 --- /dev/null +++ b/backend/infrastructure/src/video/adapter.rs @@ -0,0 +1,55 @@ +use lumiere_domain::video::error::VideoError; +use lumiere_domain::video::model::library_item::{LibraryItem, ReadLibraryItem}; +use lumiere_domain::video::model::video::Video; +use lumiere_domain::video::port::VideoPort; +use uuid::Uuid; + +pub struct VideoAdapter { + +} + +impl VideoAdapter { + pub fn new() -> Self { + Self {} + } + + pub fn get_root_folder_read_library_items(&self) -> Result, VideoError> { + // get the root_folder path from the environment variable named "ROOT_FOLDER" + // list all elements inside this folder on the file system + // map all those elements into ReadLibraryItem objects + // return the list + todo!() + } + + pub fn get_all_library_items_from_db(&self) -> Result, VideoError> { + todo!() + } +} + +impl VideoPort for VideoAdapter { + fn list_root_folder(&self) -> Result, VideoError> { + // In parallel: + // - call method "get_root_folder_read_library_items()" + // - call method "get_all_library_items_from_db()" + // + // then, merge the two lists. If an item from the "get_root_folder_read_library_items()" result has the same id as an item from the "get_all_library_items_from_db()" results, merge those two items in one single. + // return the merged list + todo!() + } + + fn list_folder(&self, folder_id: Uuid) -> Result, VideoError> { + todo!() + } + + fn get_video_stream(&self, video_id: Uuid) -> Result { + todo!() + } + + fn save(&self, library_item: LibraryItem) -> Result<(), VideoError> { + todo!() + } + + fn clone_box(&self) -> Box { + todo!() + } +} \ No newline at end of file diff --git a/backend/infrastructure/src/video/mod.rs b/backend/infrastructure/src/video/mod.rs index cf6b588..bb40162 100644 --- a/backend/infrastructure/src/video/mod.rs +++ b/backend/infrastructure/src/video/mod.rs @@ -1,2 +1,3 @@ +pub mod adapter; pub mod model; pub mod video_format_detector; \ No newline at end of file diff --git a/backend/infrastructure/src/video/video_format_detector.rs b/backend/infrastructure/src/video/video_format_detector.rs index 2d9b9c4..3ba723c 100644 --- a/backend/infrastructure/src/video/video_format_detector.rs +++ b/backend/infrastructure/src/video/video_format_detector.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::path::Path; -use lumiere_domain::video::library_item::VideoFormat; -use lumiere_domain::video::library_item::VideoFormat::{AVI, MKV, MP4, UNKNOWN, WEBM}; +use lumiere_domain::video::model::video::VideoFormat; +use lumiere_domain::video::model::video::VideoFormat::{AVI, MKV, MP4, UNKNOWN, WEBM}; /// Determine Content-Type by reading file headers (magic numbers) pub fn get_content_type(path: &Path) -> VideoFormat {