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

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

parent c0f81606
......@@ -12,5 +12,6 @@ public:
virtual const std::string& path() = 0;
// This will only returns the files in this immediate folder
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0;
virtual FolderPtr parent() = 0;
};
......@@ -76,6 +76,13 @@ std::vector<FilePtr> Folder::files()
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()
{
//FIXME: use path to be able to fetch from cache?
......
......@@ -39,6 +39,7 @@ public:
virtual unsigned int id() const override;
virtual const std::string& path() override;
virtual std::vector<FilePtr> files() override;
virtual std::vector<FolderPtr> folders() override;
virtual FolderPtr parent() override;
private:
......
......@@ -197,3 +197,31 @@ TEST_F( Folders, AbsolutePath )
auto f = ml->addFolder( "." );
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