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

IArtist: Return media as a vector<IMedia>

parent d1d4edaf
......@@ -35,5 +35,5 @@ public:
virtual const std::string& name() const = 0;
virtual const std::string& shortBio() const = 0;
virtual std::vector<AlbumPtr> albums() const = 0;
virtual std::vector<AlbumTrackPtr> media() const = 0;
virtual std::vector<MediaPtr> media() const = 0;
};
......@@ -87,23 +87,23 @@ std::vector<AlbumPtr> Artist::albums() const
return Album::fetchAll( m_dbConnection, req, m_id );
}
std::vector<AlbumTrackPtr> Artist::media() const
std::vector<MediaPtr> Artist::media() const
{
if ( m_id )
{
static const std::string req = "SELECT mar.* FROM " + policy::MediaTable::Name + " med "
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media "
"WHERE mar.id_artist = ?";
return AlbumTrack::fetchAll( m_dbConnection, req, m_id );
return Media::fetchAll( m_dbConnection, req, m_id );
}
else
{
// Not being able to rely on ForeignKey here makes me a saaaaad panda...
// But sqlite only accepts "IS NULL" to compare against NULL...
static const std::string req = "SELECT mar.* FROM " + policy::MediaTable::Name + " med "
static const std::string req = "SELECT med.* FROM " + policy::MediaTable::Name + " med "
"LEFT JOIN MediaArtistRelation mar ON mar.id_media = med.id_media "
"WHERE mar.id_artist IS NULL";
return AlbumTrack::fetchAll( m_dbConnection, req, m_id );
return Media::fetchAll( m_dbConnection, req, m_id );
}
}
......
......@@ -57,7 +57,7 @@ public:
virtual const std::string& shortBio() const override;
bool setShortBio( const std::string& shortBio );
virtual std::vector<AlbumPtr> albums() const override;
virtual std::vector<AlbumTrackPtr> media() const override;
virtual std::vector<MediaPtr> media() const override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<Artist> create( DBConnection dbConnection, const std::string& name );
......
......@@ -25,6 +25,7 @@
#include "Artist.h"
#include "Album.h"
#include "AlbumTrack.h"
#include "Media.h"
class Artists : public Tests
{
......@@ -83,6 +84,28 @@ TEST_F( Artists, Albums )
ASSERT_EQ( albums.size(), 2u );
}
TEST_F( Artists, AllSongs )
{
auto artist = ml->createArtist( "Cannibal Otters" );
ASSERT_NE( artist, nullptr );
for (auto i = 1; i <= 3; ++i)
{
auto f = ml->addFile( "song" + std::to_string(i) + ".mp3", nullptr );
auto res = f->addArtist( artist );
ASSERT_TRUE( res );
}
auto songs = artist->media();
ASSERT_EQ( songs.size(), 3u );
Reload();
auto artist2 = ml->artist( "Cannibal Otters" );
songs = artist2->media();
ASSERT_EQ( songs.size(), 3u );
}
TEST_F( Artists, GetAll )
{
for ( int i = 0; i < 5; i++ )
......
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