Commit f6e552e5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Folders: Add a folders() method, to list subfolders

parent c0f81606
...@@ -12,5 +12,6 @@ public: ...@@ -12,5 +12,6 @@ public:
virtual const std::string& path() = 0; virtual const std::string& path() = 0;
// This will only returns the files in this immediate folder // This will only returns the files in this immediate folder
virtual std::vector<FilePtr> files() = 0; virtual std::vector<FilePtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0;
virtual FolderPtr parent() = 0; virtual FolderPtr parent() = 0;
}; };
...@@ -76,6 +76,13 @@ std::vector<FilePtr> Folder::files() ...@@ -76,6 +76,13 @@ std::vector<FilePtr> Folder::files()
return sqlite::Tools::fetchAll<File, IFile>( m_dbConection, req, m_id ); return sqlite::Tools::fetchAll<File, IFile>( m_dbConection, req, m_id );
} }
std::vector<FolderPtr> Folder::folders()
{
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE id_parent = ?";
return sqlite::Tools::fetchAll<Folder, IFolder>( m_dbConection, req, m_id );
}
FolderPtr Folder::parent() FolderPtr Folder::parent()
{ {
//FIXME: use path to be able to fetch from cache? //FIXME: use path to be able to fetch from cache?
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
virtual unsigned int id() const override; virtual unsigned int id() const override;
virtual const std::string& path() override; virtual const std::string& path() override;
virtual std::vector<FilePtr> files() override; virtual std::vector<FilePtr> files() override;
virtual std::vector<FolderPtr> folders() override;
virtual FolderPtr parent() override; virtual FolderPtr parent() override;
private: private:
......
...@@ -197,3 +197,31 @@ TEST_F( Folders, AbsolutePath ) ...@@ -197,3 +197,31 @@ TEST_F( Folders, AbsolutePath )
auto f = ml->addFolder( "." ); auto f = ml->addFolder( "." );
ASSERT_NE( f->path(), "." ); ASSERT_NE( f->path(), "." );
} }
TEST_F( Folders, ListFolders )
{
auto f = ml->addFolder( "." );
auto subFolders = f->folders();
ASSERT_EQ( 1u, subFolders.size() );
auto subFolder = subFolders[0];
auto subFiles = subFolder->files();
ASSERT_EQ( 1u, subFiles.size() );
auto file = subFiles[0];
ASSERT_EQ( std::string{ mock::FileSystemFactory::SubFolder } + "subfile.mp4", file->mrl() );
// Now again, without cache
SetUp();
f = ml->folder( f->path() );
subFolders = f->folders();
ASSERT_EQ( 1u, subFolders.size() );
subFolder = subFolders[0];
subFiles = subFolder->files();
ASSERT_EQ( 1u, subFiles.size() );
file = subFiles[0];
ASSERT_EQ( std::string{ mock::FileSystemFactory::SubFolder } + "subfile.mp4", file->mrl() );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment