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

Artist: Expose an artworkUrl

parent be5a7a2e
......@@ -36,4 +36,5 @@ public:
virtual const std::string& shortBio() const = 0;
virtual std::vector<AlbumPtr> albums() const = 0;
virtual std::vector<MediaPtr> media() const = 0;
virtual const std::string& artworkUrl() const = 0;
};
......@@ -37,7 +37,8 @@ Artist::Artist( DBConnection dbConnection, sqlite::Row& row )
{
row >> m_id
>> m_name
>> m_shortBio;
>> m_shortBio
>> m_artworkUrl;
}
Artist::Artist( const std::string& name )
......@@ -115,6 +116,23 @@ bool Artist::addMedia(Media* media)
return sqlite::Tools::executeRequest( m_dbConnection, req, media->id(), artistForeignKey );
}
const std::string& Artist::artworkUrl() const
{
return m_artworkUrl;
}
bool Artist::setArtworkUrl( const std::string& artworkUrl )
{
if ( m_artworkUrl == artworkUrl )
return true;
static const std::string req = "UPDATE " + policy::ArtistTable::Name +
" SET artwork_url = ? WHERE id_artist = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
}
bool Artist::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
......@@ -122,7 +140,8 @@ bool Artist::createTable( DBConnection dbConnection )
"("
"id_artist INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT UNIQUE ON CONFLICT FAIL,"
"shortbio TEXT"
"shortbio TEXT,"
"artwork_url TEXT"
")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
"id_media INTEGER NOT NULL,"
......
......@@ -60,6 +60,8 @@ public:
virtual std::vector<AlbumPtr> albums() const override;
virtual std::vector<MediaPtr> media() const override;
bool addMedia( Media* media );
virtual const std::string& artworkUrl() const override;
bool setArtworkUrl( const std::string& artworkUrl );
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<Artist> create( DBConnection dbConnection, const std::string& name );
......@@ -69,6 +71,7 @@ private:
unsigned int m_id;
std::string m_name;
std::string m_shortBio;
std::string m_artworkUrl;
friend _Cache;
friend struct policy::ArtistTable;
......
......@@ -61,6 +61,23 @@ TEST_F( Artists, ShortBio )
ASSERT_EQ( a2->shortBio(), bio );
}
TEST_F( Artists, ArtworkUrl )
{
auto a = ml->createArtist( "Dream seaotter" );
ASSERT_NE( a, nullptr );
ASSERT_EQ( a->artworkUrl(), "" );
std::string artwork("/tmp/otter.png");
a->setArtworkUrl( artwork );
ASSERT_EQ( a->artworkUrl(), artwork );
Reload();
auto a2 = ml->artist( "Dream seaotter" );
ASSERT_NE( a2, nullptr );
ASSERT_EQ( a2->artworkUrl(), artwork );
}
TEST_F( Artists, Albums )
{
auto artist = ml->createArtist( "Cannibal Otters" );
......
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