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

Mark artists that have their own albums specifically

parent 8a7f1121
......@@ -162,6 +162,7 @@ bool Album::setAlbumArtist(Artist* artist)
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artist->id(), m_id ) == false )
return false;
m_artistId = artist->id();
artist->markAsAlbumArtist();
return true;
}
......
......@@ -38,18 +38,21 @@ Artist::Artist( DBConnection dbConnection, sqlite::Row& row )
row >> m_id
>> m_name
>> m_shortBio
>> m_artworkUrl;
>> m_artworkUrl
>> m_isAlbumArtist;
}
Artist::Artist( const std::string& name )
: m_id( 0 )
, m_name( name )
, m_isAlbumArtist( false )
{
}
Artist::Artist(DBConnection dbConnection)
: m_dbConnection( dbConnection )
, m_id( 0 )
, m_isAlbumArtist( false )
{
}
......@@ -133,6 +136,21 @@ bool Artist::setArtworkUrl( const std::string& artworkUrl )
return true;
}
bool Artist::markAsAlbumArtist()
{
if ( m_isAlbumArtist == true )
return true;
// UnknownArtist can't be an album artist.
if ( m_id == 0 )
return false;
static const std::string req = "UPDATE " + policy::ArtistTable::Name +
" SET is_album_artist=1 WHERE id_artist = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_id ) == false )
return false;
m_isAlbumArtist = true;
return true;
}
bool Artist::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
......@@ -141,7 +159,8 @@ bool Artist::createTable( DBConnection dbConnection )
"id_artist INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT UNIQUE ON CONFLICT FAIL,"
"shortbio TEXT,"
"artwork_url TEXT"
"artwork_url TEXT,"
"is_album_artist BOOLEAN DEFAULT 0"
")";
static const std::string reqRel = "CREATE TABLE IF NOT EXISTS MediaArtistRelation("
"id_media INTEGER NOT NULL,"
......
......@@ -62,6 +62,7 @@ public:
bool addMedia( Media* media );
virtual const std::string& artworkUrl() const override;
bool setArtworkUrl( const std::string& artworkUrl );
bool markAsAlbumArtist();
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<Artist> create( DBConnection dbConnection, const std::string& name );
......@@ -72,6 +73,7 @@ private:
std::string m_name;
std::string m_shortBio;
std::string m_artworkUrl;
bool m_isAlbumArtist;
friend _Cache;
friend struct policy::ArtistTable;
......
......@@ -335,7 +335,8 @@ std::shared_ptr<Artist> MediaLibrary::createArtist( const std::string& name )
std::vector<ArtistPtr> MediaLibrary::artists() const
{
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name;
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name +
" WHERE is_album_artist = 1";
return Artist::fetchAll( m_dbConnection.get(), req );
}
......
......@@ -138,3 +138,23 @@ TEST_F( Artists, GetAll )
auto artists2 = ml->artists();
ASSERT_EQ( artists2.size(), 5u );
}
TEST_F( Artists, MarkAlbumArtist )
{
auto artist = ml->createArtist( "Explotters In The Sky" );
ASSERT_NE( artist, nullptr );
// Since it's not an album artist, we shouldn't have it in the artist listing
auto artists = ml->artists();
ASSERT_EQ( artists.size(), 0u );
artist->markAsAlbumArtist();
artists = ml->artists();
ASSERT_EQ( artists.size(), 1u );
Reload();
artists = ml->artists();
ASSERT_EQ( artists.size(), 1u );
}
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