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

Albums: Add setters for release date, name, summary & artwork url

parent 9e81e199
......@@ -10,11 +10,15 @@ class IAlbum
public:
virtual ~IAlbum() {}
virtual unsigned int id() const = 0;
virtual const std::string& name() = 0;
virtual unsigned int releaseYear() = 0;
virtual const std::string& shortSummary() = 0;
virtual const std::string& artworkUrl() = 0;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) = 0;
virtual const std::string& name() const = 0;
virtual bool setName( const std::string& name ) = 0;
virtual time_t releaseDate() const = 0;
virtual bool setReleaseDate( time_t date ) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const = 0;
virtual AlbumTrackPtr addTrack( const std::string& name, unsigned int trackId ) = 0;
};
......
......@@ -12,7 +12,7 @@ Album::Album(sqlite3* dbConnection, sqlite3_stmt* stmt)
{
m_id = sqlite3_column_int( stmt, 0 );
m_name = Traits<std::string>::Load( stmt, 1 );
m_releaseYear = sqlite3_column_int( stmt, 2 );
m_releaseDate = sqlite3_column_int( stmt, 2 );
m_shortSummary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = sqlite3_column_int( stmt, 5 );
......@@ -22,7 +22,7 @@ Album::Album(sqlite3* dbConnection, sqlite3_stmt* stmt)
Album::Album( const std::string& id3tag )
: m_dbConnection( nullptr )
, m_id( 0 )
, m_releaseYear( 0 )
, m_releaseDate( 0 )
, m_lastSyncDate( 0 )
, m_id3tag( id3tag )
{
......@@ -33,32 +33,72 @@ unsigned int Album::id() const
return m_id;
}
const std::string& Album::name()
const std::string& Album::name() const
{
return m_name;
}
unsigned int Album::releaseYear()
bool Album::setName( const std::string& name )
{
return m_releaseYear;
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET name = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, name, m_id ) == false )
return false;
m_name = name;
return true;
}
const std::string& Album::shortSummary()
time_t Album::releaseDate() const
{
return m_releaseDate;
}
bool Album::setReleaseDate( time_t date )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET release_date = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
}
const std::string& Album::shortSummary() const
{
return m_shortSummary;
}
const std::string& Album::artworkUrl()
bool Album::setShortSummary( const std::string& summary )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET short_summary = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_shortSummary = summary;
return true;
}
const std::string& Album::artworkUrl() const
{
return m_artworkUrl;
}
time_t Album::lastSyncDate()
bool Album::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET artwork_url = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
}
time_t Album::lastSyncDate() const
{
return m_lastSyncDate;
}
bool Album::tracks( std::vector<std::shared_ptr<IAlbumTrack> >& tracks )
bool Album::tracks( std::vector<std::shared_ptr<IAlbumTrack> >& tracks ) const
{
const char* req = "SELECT * FROM AlbumTrack WHERE album_id = ?";
return SqliteTools::fetchAll<AlbumTrack>( m_dbConnection, req, tracks, m_id );
......@@ -74,7 +114,7 @@ bool Album::createTable( sqlite3* dbConnection )
const char* req = "CREATE TABLE IF NOT EXISTS Album("
"id_album INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT,"
"release_year UNSIGNED INTEGER,"
"release_date UNSIGNED INTEGER,"
"short_summary TEXT,"
"artwork_url TEXT,"
"UNSIGNED INTEGER last_sync_date,"
......
......@@ -30,12 +30,16 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
Album( const std::string& id3tag );
unsigned int id() const;
virtual const std::string& name();
virtual unsigned int releaseYear();
virtual const std::string& shortSummary();
virtual const std::string& artworkUrl();
virtual time_t lastSyncDate();
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks );
virtual const std::string& name() const;
virtual bool setName( const std::string& name );
virtual time_t releaseDate() const;
virtual bool setReleaseDate( time_t date );
virtual const std::string& shortSummary() const;
virtual bool setShortSummary( const std::string& summary );
virtual const std::string& artworkUrl() const;
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual time_t lastSyncDate() const;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const;
virtual AlbumTrackPtr addTrack( const std::string& name, unsigned int trackNb );
......@@ -46,7 +50,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_name;
unsigned int m_releaseYear;
unsigned int m_releaseDate;
std::string m_shortSummary;
std::string m_artworkUrl;
time_t m_lastSyncDate;
......
......@@ -113,6 +113,7 @@ TEST_F( Albums, SetGenre )
auto t = a->addTrack( "track", 1 );
t->setGenre( "happy underground post progressive death metal" );
ASSERT_EQ( t->genre(), "happy underground post progressive death metal" );
delete ml;
SetUp();
......@@ -123,3 +124,58 @@ TEST_F( Albums, SetGenre )
ASSERT_EQ( t->genre(), t2->genre() );
}
TEST_F( Albums, SetName )
{
auto a = ml->createAlbum( "album" );
a->setName( "albumname" );
ASSERT_EQ( a->name(), "albumname" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
ASSERT_EQ( a->name(), a2->name() );
}
TEST_F( Albums, SetReleaseDate )
{
auto a = ml->createAlbum( "album" );
a->setReleaseDate( 1234 );
ASSERT_EQ( a->releaseDate(), 1234 );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
ASSERT_EQ( a->releaseDate(), a2->releaseDate() );
}
TEST_F( Albums, SetShortSummary )
{
auto a = ml->createAlbum( "album" );
a->setShortSummary( "summary" );
ASSERT_EQ( a->shortSummary(), "summary" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
ASSERT_EQ( a->shortSummary(), a2->shortSummary() );
}
TEST_F( Albums, SetArtworkUrl )
{
auto a = ml->createAlbum( "album" );
a->setArtworkUrl( "artwork" );
ASSERT_EQ( a->artworkUrl(), "artwork" );
delete ml;
SetUp();
auto a2 = ml->album( "album" );
ASSERT_EQ( a->artworkUrl(), a2->artworkUrl() );
}
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