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

AlbumTrack: Re-expose an artist property

parent dd8bca5d
......@@ -33,6 +33,15 @@ class IAlbumTrack
virtual ~IAlbumTrack() {}
virtual unsigned int id() const = 0;
/**
* @brief artist Returns the artist, as tagger in the media.
* This can be different from the associated media's artist.
* For instance, in case of a featuring, Media::artist() might return
* "Artist 1", while IAlbumTrack::artist() might return something like
* "Artist 1 featuring Artist 2 and also artist 3 and a whole bunch of people"
* @return
*/
virtual const std::string& artist() const = 0;
virtual const std::string& genre() = 0;
virtual unsigned int trackNumber() = 0;
virtual std::shared_ptr<IAlbum> album() = 0;
......
......@@ -36,6 +36,7 @@ AlbumTrack::AlbumTrack(DBConnection dbConnection, sqlite::Row& row )
{
row >> m_id
>> m_mediaId
>> m_artist
>> m_genre
>> m_trackNumber
>> m_albumId;
......@@ -56,11 +57,29 @@ unsigned int AlbumTrack::id() const
return m_id;
}
const std::string&AlbumTrack::artist() const
{
return m_artist;
}
bool AlbumTrack::setArtist( const std::string& artist )
{
static const std::string req = "UPDATE " + policy::AlbumTrackTable::Name +
" SET artist = ? WHERE id_track = ?";
if ( artist == m_artist )
return true;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, artist, m_id ) == false )
return false;
m_artist = artist;
return true;
}
bool AlbumTrack::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id INTEGER,"
"artist TEXT,"
"genre TEXT,"
"track_number UNSIGNED INTEGER,"
"album_id UNSIGNED INTEGER NOT NULL,"
......
......@@ -53,6 +53,8 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
AlbumTrack(Media* media, unsigned int trackNumber, unsigned int albumId );
virtual unsigned int id() const override;
virtual const std::string& artist() const override;
bool setArtist( const std::string& artist );
virtual const std::string& genre() override;
bool setGenre( const std::string& genre );
virtual unsigned int trackNumber() override;
......@@ -66,6 +68,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
DBConnection m_dbConnection;
unsigned int m_id;
unsigned int m_mediaId;
std::string m_artist;
std::string m_genre;
unsigned int m_trackNumber;
unsigned int m_albumId;
......
......@@ -25,9 +25,27 @@
#include "Album.h"
#include "AlbumTrack.h"
#include "Artist.h"
#include "Media.h"
class AlbumTracks : public Tests
{
};
TEST_F( AlbumTracks, Artist )
{
auto album = ml->createAlbum( "album" );
auto f = ml->addFile( "track1.mp3", nullptr );
auto track = album->addTrack( f, 1 );
ASSERT_EQ( track->artist(), "" );
track->setArtist( "artist" );
ASSERT_EQ( track->artist(), "artist" );
Reload();
// Don't reuse the "track" and "f" variable, their type differ
auto file = ml->file( "track1.mp3" );
auto albumTrack = file->albumTrack();
ASSERT_EQ( albumTrack->artist(), "artist" );
}
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