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

Artist: Allow nbTracks to be edited

parent 62e4883f
......@@ -155,6 +155,18 @@ bool Artist::updateNbAlbum( int increment )
return true;
}
bool Artist::updateNbTrack(int increment)
{
assert( increment != 0 );
assert( increment > 0 || ( increment < 0 && m_nbTracks >= 1 ) );
static const std::string req = "UPDATE " + policy::ArtistTable::Name +
" SET nb_tracks = nb_tracks + ? WHERE id_artist = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, increment, m_id ) == false )
return false;
m_nbTracks += increment;
return true;
}
std::shared_ptr<Album> Artist::unknownAlbum()
{
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
......
......@@ -59,6 +59,7 @@ public:
virtual const std::string& artworkMrl() const override;
bool setArtworkMrl( const std::string& artworkMrl );
bool updateNbAlbum( int increment );
bool updateNbTrack( int increment );
std::shared_ptr<Album> unknownAlbum();
virtual const std::string& musicBrainzId() const override;
bool setMusicBrainzId( const std::string& musicBrainzId );
......
......@@ -326,3 +326,24 @@ TEST_F( Artists, DeleteWhenNoAlbum )
artists = ml->artists( medialibrary::SortingCriteria::Default, false );
ASSERT_EQ( 0u, artists.size() );
}
TEST_F( Artists, UpdateNbTracks )
{
auto artist = ml->createArtist( "artist" );
ASSERT_EQ( 0u, artist->nbTracks() );
artist->updateNbTrack( 1 );
ASSERT_EQ( 1u, artist->nbTracks() );
Reload();
artist = std::static_pointer_cast<Artist>( ml->artist( artist->id() ) );
ASSERT_EQ( 1u, artist->nbTracks() );
artist->updateNbTrack( -1 );
ASSERT_EQ( 0u, artist->nbTracks() );
Reload();
artist = std::static_pointer_cast<Artist>( ml->artist( artist->id() ) );
ASSERT_EQ( 0u, artist->nbTracks() );
}
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