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

Playlist: Expose creation date

parent becf6355
......@@ -33,6 +33,7 @@ public:
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 0;
virtual bool setName( const std::string& name ) = 0;
virtual unsigned int creationDate() const = 0;
virtual std::vector<MediaPtr> media() const = 0;
///
/// \brief append Appends a media to a playlist
......
......@@ -35,21 +35,24 @@ Playlist::Playlist( MediaLibraryPtr ml, sqlite::Row& row )
: m_ml( ml )
{
row >> m_id
>> m_name;
>> m_name
>> m_creationDate;
}
Playlist::Playlist( MediaLibraryPtr ml, const std::string& name )
: m_ml( ml )
, m_id( 0 )
, m_name( name )
, m_creationDate( time( nullptr ) )
{
}
std::shared_ptr<Playlist> Playlist::create( MediaLibraryPtr ml, const std::string& name )
{
auto self = std::make_shared<Playlist>( ml, name );
static const std::string req = "INSERT INTO " + policy::PlaylistTable::Name + "(name) VALUES(?)";
if ( insert( ml, self, req, name ) == false )
static const std::string req = "INSERT INTO " + policy::PlaylistTable::Name + \
"(name, creation_date) VALUES(?, ?)";
if ( insert( ml, self, req, name, self->m_creationDate ) == false )
return nullptr;
return self;
}
......@@ -75,6 +78,11 @@ bool Playlist::setName( const std::string& name )
return true;
}
unsigned int Playlist::creationDate() const
{
return m_creationDate;
}
std::vector<MediaPtr> Playlist::media() const
{
static const std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m "
......@@ -116,7 +124,8 @@ bool Playlist::createTable( DBConnection dbConn )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::PlaylistTable::Name + "("
+ policy::PlaylistTable::PrimaryKeyColumn + " INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT"
"name TEXT,"
"creation_date UNSIGNED INT NOT NULL"
")";
static const std::string relTableReq = "CREATE TABLE IF NOT EXISTS PlaylistMediaRelation("
"media_id INTEGER,"
......
......@@ -51,6 +51,7 @@ public:
virtual unsigned int id() const override;
virtual const std::string& name() const override;
virtual bool setName( const std::string& name ) override;
virtual unsigned int creationDate() const override;
virtual std::vector<MediaPtr> media() const override;
virtual bool append( unsigned int mediaId ) override;
virtual bool add( unsigned int mediaId, unsigned int position ) override;
......@@ -66,6 +67,7 @@ private:
unsigned int m_id;
std::string m_name;
unsigned int m_creationDate;
friend class policy::PlaylistTable;
};
......@@ -43,6 +43,7 @@ TEST_F( Playlists, Create )
ASSERT_NE( nullptr, pl );
ASSERT_NE( 0u, pl->id() );
ASSERT_EQ( "test playlist", pl->name() );
ASSERT_NE( 0u, pl->creationDate() );
}
TEST_F( Playlists, Fetch )
......
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