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

IAlbum: Pass a QueryParameters to list artists

Mostly for consistency with the other methods
parent 95752202
......@@ -61,7 +61,7 @@ public:
* Artists are sorted by name.
* @param desc
*/
virtual Query<IArtist> artists( bool desc ) const = 0;
virtual Query<IArtist> artists( const QueryParameters* params = nullptr ) const = 0;
/**
* @brief nbTracks Returns the amount of track in this album.
* The value is cached, and doesn't require fetching anything.
......
......@@ -354,12 +354,12 @@ bool Album::setAlbumArtist( std::shared_ptr<Artist> artist )
return true;
}
Query<IArtist> Album::artists( bool desc ) const
Query<IArtist> Album::artists( const QueryParameters* params ) const
{
std::string req = "FROM " + policy::ArtistTable::Name + " art "
"INNER JOIN AlbumArtistRelation aar ON aar.artist_id = art.id_artist "
"WHERE aar.album_id = ? ORDER BY art.name";
if ( desc == true )
if ( params != nullptr && params->desc == true )
req += " DESC";
return make_query<Artist, IArtist>( m_ml, "art.*", std::move( req ), m_id );
}
......
......@@ -96,7 +96,7 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
virtual ArtistPtr albumArtist() const override;
bool setAlbumArtist( std::shared_ptr<Artist> artist );
virtual Query<IArtist> artists(bool desc) const override;
virtual Query<IArtist> artists( const QueryParameters* params ) const override;
bool addArtist( std::shared_ptr<Artist> artist );
bool removeArtist( Artist* artist );
......
......@@ -387,7 +387,7 @@ void Tests::checkAlbums( const rapidjson::Value& expectedAlbums, std::vector<Alb
if ( expectedAlbum.HasMember( "artists" ) )
{
const auto& expectedArtists = expectedAlbum["artists"];
auto artists = a->artists( false )->all();
auto artists = a->artists( nullptr )->all();
if ( expectedArtists.Size() != artists.size() )
return false;
for ( auto i = 0u; i < expectedArtists.Size(); ++i )
......
......@@ -232,13 +232,13 @@ TEST_F( Albums, Artists )
res = album->addArtist( artist2 );
ASSERT_EQ( res, true );
auto artists = album->artists( false )->all();
auto artists = album->artists( nullptr )->all();
ASSERT_EQ( artists.size(), 2u );
Reload();
album = std::static_pointer_cast<Album>( ml->album( album->id() ) );
artists = album->artists( false )->all();
artists = album->artists( nullptr )->all();
ASSERT_EQ( album->albumArtist(), nullptr );
ASSERT_EQ( artists.size(), 2u );
}
......@@ -252,12 +252,14 @@ TEST_F( Albums, SortArtists )
album->addArtist( artist1 );
album->addArtist( artist2 );
auto artists = album->artists( false )->all();
QueryParameters params { SortingCriteria::Default, false };
auto artists = album->artists( &params )->all();
ASSERT_EQ( artists.size(), 2u );
ASSERT_EQ( artist1->id(), artists[1]->id() );
ASSERT_EQ( artist2->id(), artists[0]->id() );
artists = album->artists( true )->all();
params.desc = true;
artists = album->artists( &params )->all();
ASSERT_EQ( artists.size(), 2u );
ASSERT_EQ( artist1->id(), artists[0]->id() );
ASSERT_EQ( artist2->id(), artists[1]->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