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

Provide basic Genres sorting

parent cfd73e7b
......@@ -146,7 +146,12 @@ class IMediaLibrary
* @param desc If true, the provided sorting criteria will be reversed.
*/
virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort, bool desc ) const = 0;
virtual std::vector<GenrePtr> genres() const = 0;
/**
* @brief genres Return the list of music genres
* @param sort A sorting criteria. So far, this is ignored, and artists are sorted by lexial order
* @param desc If true, the provided sorting criteria will be reversed.
*/
virtual std::vector<GenrePtr> genres( medialibrary::SortingCriteria sort, bool desc ) const = 0;
/***
* Playlists
......
......@@ -128,3 +128,11 @@ std::vector<GenrePtr> Genre::search( MediaLibraryPtr ml, const std::string& name
return fetchAll<IGenre>( ml, req, name + "*" );
}
std::vector<GenrePtr> Genre::listAll( MediaLibraryPtr ml, medialibrary::SortingCriteria, bool desc )
{
std::string req = "SELECT * FROM " + policy::GenreTable::Name + " ORDER BY name";
if ( desc == true )
req += " DESC";
return fetchAll<IGenre>( ml, req );
}
......@@ -53,6 +53,7 @@ public:
static std::shared_ptr<Genre> create( MediaLibraryPtr ml, const std::string& name );
static std::shared_ptr<Genre> fromName( MediaLibraryPtr ml, const std::string& name );
static std::vector<GenrePtr> search( MediaLibraryPtr ml, const std::string& name );
static std::vector<GenrePtr> listAll( MediaLibraryPtr ml, medialibrary::SortingCriteria sort, bool desc );
private:
MediaLibraryPtr m_ml;
......
......@@ -316,9 +316,9 @@ std::vector<AlbumPtr> MediaLibrary::albums( medialibrary::SortingCriteria sort,
return Album::listAll( this, sort, desc );
}
std::vector<GenrePtr> MediaLibrary::genres() const
std::vector<GenrePtr> MediaLibrary::genres( medialibrary::SortingCriteria sort, bool desc ) const
{
return Genre::fetchAll<IGenre>( this );
return Genre::listAll( this, sort, desc );
}
ShowPtr MediaLibrary::show( const std::string& name )
......
......@@ -71,7 +71,7 @@ class MediaLibrary : public IMediaLibrary
std::shared_ptr<Album> createAlbum( const std::string& title );
virtual std::vector<AlbumPtr> albums(medialibrary::SortingCriteria sort, bool desc) override;
virtual std::vector<GenrePtr> genres() const override;
virtual std::vector<GenrePtr> genres( medialibrary::SortingCriteria sort, bool desc ) const override;
virtual ShowPtr show( const std::string& name ) override;
std::shared_ptr<Show> createShow( const std::string& name );
......
......@@ -51,7 +51,7 @@ TEST_F( Genres, List )
{
auto g2 = ml->createGenre( "genre 2" );
ASSERT_NE( nullptr, g2 );
auto genres = ml->genres();
auto genres = ml->genres( medialibrary::SortingCriteria::Default, false );
ASSERT_EQ( 2u, genres.size() );
}
......@@ -122,7 +122,7 @@ TEST_F( Genres, ListAlbums )
track->setGenre( g );
}
auto genres = ml->genres();
auto genres = ml->genres( medialibrary::SortingCriteria::Default, false );
for ( auto& genre : genres )
{
auto albums = genre->albums();
......@@ -182,3 +182,18 @@ TEST_F( Genres, SortTracks )
ASSERT_EQ( 1u, tracks[1]->trackNumber() );
ASSERT_EQ( 2u, tracks[0]->trackNumber() );
}
TEST_F( Genres, Sort )
{
auto g2 = ml->createGenre( "metal" );
auto genres = ml->genres( medialibrary::SortingCriteria::Default, false );
ASSERT_EQ( 2u, genres.size() );
ASSERT_EQ( g->id(), genres[0]->id() );
ASSERT_EQ( g2->id(), genres[1]->id() );
genres = ml->genres( medialibrary::SortingCriteria::Default, true );
ASSERT_EQ( 2u, genres.size() );
ASSERT_EQ( g->id(), genres[1]->id() );
ASSERT_EQ( g2->id(), genres[0]->id() );
}
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