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

Genre: Sort the artists list

parent 1dc494cd
......@@ -32,7 +32,7 @@ public:
virtual ~IGenre() = default;
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 0;
virtual std::vector<ArtistPtr> artists() const = 0;
virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort, bool desc ) const = 0;
virtual std::vector<AlbumTrackPtr> tracks( medialibrary::SortingCriteria sort, bool desc ) const = 0;
virtual std::vector<AlbumPtr> albums() const = 0;
};
......@@ -56,11 +56,14 @@ const std::string& Genre::name() const
return m_name;
}
std::vector<ArtistPtr> Genre::artists() const
std::vector<ArtistPtr> Genre::artists( medialibrary::SortingCriteria, bool desc ) const
{
static const std::string req = "SELECT a.* FROM " + policy::ArtistTable::Name + " a "
std::string req = "SELECT a.* FROM " + policy::ArtistTable::Name + " a "
"INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.artist_id = a.id_artist "
"WHERE att.genre_id = ? GROUP BY att.artist_id";
"WHERE att.genre_id = ? GROUP BY att.artist_id"
" ORDER BY a.name";
if ( desc == true )
req += " DESC";
return Artist::fetchAll<IArtist>( m_ml, req, m_id );
}
......
......@@ -45,7 +45,7 @@ public:
Genre( MediaLibraryPtr ml, const std::string& name );
virtual unsigned int id() const;
virtual const std::string& name() const override;
virtual std::vector<ArtistPtr> artists() const override;
virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort, bool desc ) const override;
virtual std::vector<AlbumTrackPtr> tracks(medialibrary::SortingCriteria sort, bool desc) const override;
virtual std::vector<AlbumPtr> albums() const override;
......
......@@ -72,7 +72,7 @@ TEST_F( Genres, ListAlbumTracks )
TEST_F( Genres, ListArtists )
{
auto artists = g->artists();
auto artists = g->artists( medialibrary::SortingCriteria::Default, false );
ASSERT_EQ( 0u, artists.size() );
auto a = ml->createArtist( "artist" );
......@@ -96,7 +96,7 @@ TEST_F( Genres, ListArtists )
track->setGenre( g );
track->setArtist( a2 );
}
artists = g->artists();
artists = g->artists( medialibrary::SortingCriteria::Default, false );
ASSERT_EQ( 2u, artists.size() );
}
......
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