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

Artist: Add a musicbrainzId field

parent 6ff9e16c
......@@ -37,4 +37,5 @@ public:
virtual std::vector<AlbumPtr> albums() const = 0;
virtual std::vector<MediaPtr> media() const = 0;
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& musicBrainzId() const = 0;
};
......@@ -40,6 +40,7 @@ Artist::Artist( DBConnection dbConnection, sqlite::Row& row )
>> m_shortBio
>> m_artworkMrl
>> m_nbAlbums
>> m_mbId
>> m_isPresent;
}
......@@ -162,6 +163,23 @@ std::shared_ptr<Album> Artist::unknownAlbum()
return album;
}
const std::string& Artist::musicBrainzId() const
{
return m_mbId;
}
bool Artist::setMusicBrainzId( const std::string& mbId )
{
static const std::string req = "UPDATE " + policy::ArtistTable::Name
+ " SET mb_id = ? WHERE id_artist = ?";
if ( mbId == m_mbId )
return true;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, mbId, m_id ) == false )
return false;
m_mbId = mbId;
return true;
}
bool Artist::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
......@@ -172,6 +190,7 @@ bool Artist::createTable( DBConnection dbConnection )
"shortbio TEXT,"
"artwork_mrl TEXT,"
"nb_albums UNSIGNED INT DEFAULT 0,"
"mb_id TEXT,"
"is_present BOOLEAN NOT NULL DEFAULT 1"
")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
......
......@@ -57,6 +57,8 @@ public:
bool setArtworkMrl( const std::string& artworkMrl );
bool updateNbAlbum( int increment );
std::shared_ptr<Album> unknownAlbum();
virtual const std::string& musicBrainzId() const override;
bool setMusicBrainzId( const std::string& musicBrainzId );
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
......@@ -71,6 +73,7 @@ private:
std::string m_artworkMrl;
unsigned int m_nbAlbums;
bool m_isPresent;
std::string m_mbId;
friend struct policy::ArtistTable;
};
......@@ -173,3 +173,20 @@ TEST_F( Artists, UnknownAlbum )
ASSERT_NE( nullptr, album2 );
ASSERT_EQ( album2->id(), album->id() );
}
TEST_F( Artists, MusicBrainzId )
{
auto a = ml->createArtist( "Otters Never Say Die" );
ASSERT_NE( a, nullptr );
ASSERT_EQ( a->musicBrainzId(), "" );
std::string mbId("{this-id-an-id}");
a->setMusicBrainzId( mbId );
ASSERT_EQ( a->musicBrainzId(), mbId );
Reload();
auto a2 = ml->artist( "Otters Never Say Die" );
ASSERT_NE( a2, nullptr );
ASSERT_EQ( a2->musicBrainzId(), mbId );
}
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