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

AlbumTracks: Add artist handling

parent cceb91f9
......@@ -16,6 +16,8 @@ class IAlbumTrack
virtual const std::string& title() = 0;
virtual unsigned int trackNumber() = 0;
virtual std::shared_ptr<IAlbum> album() = 0;
virtual const std::string& artist() const = 0;
virtual bool setArtist( const std::string& artist ) = 0;
virtual bool files( std::vector<FilePtr>& files ) = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
......
......@@ -15,7 +15,8 @@ AlbumTrack::AlbumTrack( DBConnection dbConnection, sqlite3_stmt* stmt )
m_title = Traits<std::string>::Load( stmt, 1 );
m_genre = Traits<std::string>::Load( stmt, 2 );
m_trackNumber = Traits<unsigned int>::Load( stmt, 3 );
m_albumId = Traits<unsigned int>::Load( stmt, 4 );
m_artist = Traits<std::string>::Load( stmt, 4 );
m_albumId = Traits<unsigned int>::Load( stmt, 5 );
}
AlbumTrack::AlbumTrack( const std::string& title, unsigned int trackNumber, unsigned int albumId )
......@@ -39,6 +40,7 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
"title TEXT,"
"genre TEXT,"
"track_number UNSIGNED INTEGER,"
"artist TEXT,"
"album_id UNSIGNED INTEGER NOT NULL,"
"FOREIGN KEY (album_id) REFERENCES Album(id_album) ON DELETE CASCADE"
")";
......@@ -107,6 +109,21 @@ bool AlbumTrack::destroy()
return _Cache::destroy( m_dbConnection, this );
}
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 ( SqliteTools::executeUpdate( m_dbConnection, req, artist, m_id ) == false )
return false;
m_artist = artist;
return true;
}
bool AlbumTrack::files(std::vector<FilePtr>& files)
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
......
......@@ -36,6 +36,8 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual unsigned int trackNumber();
virtual std::shared_ptr<IAlbum> album();
virtual bool destroy();
virtual const std::string& artist() const;
virtual bool setArtist( const std::string& artist );
virtual bool files( std::vector<FilePtr>& files );
static bool createTable( DBConnection dbConnection );
......@@ -48,6 +50,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
std::string m_title;
std::string m_genre;
unsigned int m_trackNumber;
std::string m_artist;
unsigned int m_albumId;
std::shared_ptr<Album> m_album;
......
......@@ -160,6 +160,23 @@ TEST_F( Albums, SetArtworkUrl )
ASSERT_EQ( a->artworkUrl(), a2->artworkUrl() );
}
TEST_F( Albums, SetArtist )
{
auto a = ml->createAlbum( "album" );
auto t = a->addTrack("track1", 1);
t->setArtist( "The undead otters" );
ASSERT_EQ( t->artist(), "The undead otters" );
SetUp();
auto a2 = ml->album( "album" );
std::vector<AlbumTrackPtr> tracks;
a2->tracks( tracks );
auto t2 = tracks[0];
ASSERT_EQ( t->artist(), t2->artist() );
}
TEST_F( Albums, FetchAlbumFromTrack )
{
{
......
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