Commit b5114be5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Genre: Return albumTracks as IMedia instead of IAlbumTrack

parent dd1c464e
......@@ -33,6 +33,6 @@ public:
virtual int64_t id() const = 0;
virtual const std::string& name() const = 0;
virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumTrackPtr> tracks( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> tracks( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
};
......@@ -137,11 +137,11 @@ AlbumTrackPtr AlbumTrack::fromMedia( MediaLibraryPtr ml, int64_t mediaId )
return fetch( ml, req, mediaId );
}
std::vector<AlbumTrackPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc )
std::vector<MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc )
{
std::string req = "SELECT t.* FROM " + policy::AlbumTrackTable::Name + " t"
" INNER JOIN " + policy::MediaTable::Name + " m ON m.id_media = t.media_id"
" WHERE genre_id = ? ORDER BY ";
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m"
" INNER JOIN " + policy::AlbumTrackTable::Name + " t ON m.id_media = t.media_id"
" WHERE t.genre_id = ? ORDER BY ";
switch ( sort )
{
case medialibrary::SortingCriteria::Duration:
......@@ -163,7 +163,7 @@ std::vector<AlbumTrackPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t ge
if ( desc == true )
req += " DESC";
return fetchAll<IAlbumTrack>( ml, req, genreId );
return Media::fetchAll<IMedia>( ml, req, genreId );
}
GenrePtr AlbumTrack::genre()
......
......@@ -68,7 +68,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
static std::shared_ptr<AlbumTrack> create( MediaLibraryPtr ml, int64_t albumId,
std::shared_ptr<Media> media, unsigned int trackNb , unsigned int discNumber );
static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
static std::vector<AlbumTrackPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc );
static std::vector<MediaPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc );
static std::vector<MediaPtr> search(DBConnection dbConn, const std::string& title );
private:
......
......@@ -68,7 +68,7 @@ std::vector<ArtistPtr> Genre::artists( medialibrary::SortingCriteria, bool desc
return Artist::fetchAll<IArtist>( m_ml, req, m_id );
}
std::vector<AlbumTrackPtr> Genre::tracks( medialibrary::SortingCriteria sort, bool desc ) const
std::vector<MediaPtr> Genre::tracks( medialibrary::SortingCriteria sort, bool desc ) const
{
return AlbumTrack::fromGenre( m_ml, m_id, sort, desc );
}
......
......@@ -46,7 +46,7 @@ public:
virtual int64_t id() const;
virtual const std::string& name() 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<MediaPtr> tracks(medialibrary::SortingCriteria sort, bool desc) const override;
virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort, bool desc ) const override;
static bool createTable( DBConnection dbConn );
......
......@@ -174,13 +174,13 @@ TEST_F( Genres, SortTracks )
}
auto tracks = g->tracks( medialibrary::SortingCriteria::Duration, false );
ASSERT_EQ( 2u, tracks.size() );
ASSERT_EQ( 1u, tracks[0]->trackNumber() );
ASSERT_EQ( 2u, tracks[1]->trackNumber() );
ASSERT_EQ( 1u, tracks[0]->albumTrack()->trackNumber() );
ASSERT_EQ( 2u, tracks[1]->albumTrack()->trackNumber() );
tracks = g->tracks( medialibrary::SortingCriteria::Duration, true );
ASSERT_EQ( 2u, tracks.size() );
ASSERT_EQ( 1u, tracks[1]->trackNumber() );
ASSERT_EQ( 2u, tracks[0]->trackNumber() );
ASSERT_EQ( 1u, tracks[1]->albumTrack()->trackNumber() );
ASSERT_EQ( 2u, tracks[0]->albumTrack()->trackNumber() );
}
TEST_F( Genres, Sort )
......
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