From 360df2c5f4a0a31193885528cc1444f25bcde8da Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Sun, 19 Jul 2026 20:47:25 +0200 Subject: [PATCH] WIP --- .../infrastructure/src/video/repository.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/backend/infrastructure/src/video/repository.rs b/backend/infrastructure/src/video/repository.rs index 0a9ca6e..1bc6af7 100644 --- a/backend/infrastructure/src/video/repository.rs +++ b/backend/infrastructure/src/video/repository.rs @@ -2,6 +2,7 @@ use std::sync::{Arc, Mutex, MutexGuard}; use rusqlite::{Connection, Error, Row}; use rusqlite::fallible_iterator::FallibleIterator; use uuid::Uuid; +use lumiere_domain::user::model::User; use crate::video::model::LibraryItemEntity; #[derive(Clone)] @@ -85,4 +86,60 @@ impl LibraryItemSqliteRepository { prepared_statement.execute(rusqlite::params_from_iter(params))?; Ok(()) } + + pub fn get_by_id_with_all_hierarchy(&self, library_item_id: &Uuid) -> Result, Error> { + let database_connection = self.get_connection(); + + /* + Given a LibraryItem item_1: + LibraryItemEntity { + id: , + name: "item_1", + type: 0, + parent_item_id: + } + + Its parent item is item_2: + LibraryItemEntity { + id: , + name: "item_2", + type: 1, + parent_item_id: + } + + item_2 has a parent which is item_3: + LibraryItemEntity { + id: , + name: "item_3", + type: 0, + parent_item_id: NULL + } + + TODO: Write a SQL query to retrieve all LibraryItemEntity objects. It should filter on id with a parameter. + This query should return something like: + | id | name | type | parent_item_id | + | ----- | -------- | ---- | -------------- | + | | 'item_1' | 0 | | + | | 'item_2' | 1 | | + | | 'item_3' | 1 | NULL | + + Take example on the following query and adapt it. + */ + let mut prepared_statement = database_connection.prepare( + "SELECT + id, + name, + type, + parent_item_id + FROM library_item + WHERE id = ?1;" + )?; + let mut rows = prepared_statement.query([library_item_id.to_string()])?; + + if let Some(row) = rows.next()? { + Ok(Some(Self::map_to_library_item(&row)?)) + } else { + Ok(None) + } + } } \ No newline at end of file