Commit 73844878 authored by Pierre Lamot's avatar Pierre Lamot Committed by Hugo Beauzée-Luyssen

Genre: add sorting criteria and order for api uniformisation

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent 51b704ad
......@@ -315,7 +315,7 @@ class IMediaLibrary
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
virtual Query<IGenre> searchGenre( const std::string& genre ) const = 0;
virtual Query<IGenre> searchGenre( const std::string& genre, SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IArtist> searchArtists( const std::string& name,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
......
......@@ -171,10 +171,12 @@ std::shared_ptr<Genre> Genre::fromName( MediaLibraryPtr ml, const std::string& n
return fetch( ml, req, name );
}
Query<IGenre> Genre::search( MediaLibraryPtr ml, const std::string& name )
Query<IGenre> Genre::search( MediaLibraryPtr ml, const std::string& name, SortingCriteria sort, bool desc )
{
static const std::string req = "FROM " + policy::GenreTable::Name + " WHERE id_genre IN "
"(SELECT rowid FROM " + policy::GenreTable::Name + "Fts WHERE name MATCH '*' || ? || '*')";
std::string req = "FROM " + policy::GenreTable::Name + " WHERE id_genre IN "
"(SELECT rowid FROM " + policy::GenreTable::Name + "Fts WHERE name MATCH '*' || ? || '*') ORDER BY name";
if ( desc == true )
req += " DESC";
return make_query<Genre, IGenre>( ml, "*", req, name );
}
......
......@@ -58,7 +58,7 @@ public:
static void createTriggers( sqlite::Connection* dbConn );
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 Query<IGenre> search( MediaLibraryPtr ml, const std::string& name );
static Query<IGenre> search( MediaLibraryPtr ml, const std::string& name, SortingCriteria sort, bool desc );
static Query<IGenre> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
private:
......
......@@ -691,11 +691,11 @@ Query<IAlbum> MediaLibrary::searchAlbums( const std::string& pattern,
return Album::search( this, pattern, sort, desc );
}
Query<IGenre> MediaLibrary::searchGenre( const std::string& genre ) const
Query<IGenre> MediaLibrary::searchGenre( const std::string& genre, SortingCriteria sort, bool desc ) const
{
if ( validateSearchPattern( genre ) == false )
return {};
return Genre::search( this, genre );
return Genre::search( this, genre, sort, desc );
}
Query<IArtist> MediaLibrary::searchArtists( const std::string& name,
......@@ -713,7 +713,7 @@ SearchAggregate MediaLibrary::search( const std::string& pattern,
SearchAggregate res;
res.albums = searchAlbums( pattern, sort, desc );
res.artists = searchArtists( pattern, sort, desc );
res.genres = searchGenre( pattern );
res.genres = searchGenre( pattern, sort, desc );
res.media = searchMedia( pattern, sort, desc );
res.playlists = searchPlaylists( pattern, sort, desc );
return res;
......
......@@ -124,7 +124,9 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
SortingCriteria sort,
bool desc ) const override;
virtual Query<IGenre> searchGenre( const std::string& genre ) const override;
virtual Query<IGenre> searchGenre( const std::string& genre,
SortingCriteria sort,
bool desc ) const override;
virtual Query<IArtist> searchArtists( const std::string& name,
SortingCriteria sort,
bool desc ) const override;
......
......@@ -148,18 +148,18 @@ TEST_F( Genres, Search )
ml->createGenre( "something" );
ml->createGenre( "blork" );
auto genres = ml->searchGenre( "genr" )->all();
auto genres = ml->searchGenre( "genr", SortingCriteria::Default, false )->all();
ASSERT_EQ( 1u, genres.size() );
}
TEST_F( Genres, SearchAfterDelete )
{
auto genres = ml->searchGenre( "genre" )->all();
auto genres = ml->searchGenre( "genre", SortingCriteria::Default, false )->all();
ASSERT_EQ( 1u, genres.size() );
ml->deleteGenre( g->id() );
genres = ml->searchGenre( "genre" )->all();
genres = ml->searchGenre( "genre", SortingCriteria::Default, false )->all();
ASSERT_EQ( 0u, genres.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