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

Add basic Show functionnalities

parent 87f40f8a
......@@ -10,11 +10,13 @@ class IAlbumTrack;
class IFile;
class ILabel;
class IMetadataService;
class IShow;
typedef std::shared_ptr<IFile> FilePtr;
typedef std::shared_ptr<ILabel> LabelPtr;
typedef std::shared_ptr<IAlbum> AlbumPtr;
typedef std::shared_ptr<IAlbumTrack> AlbumTrackPtr;
typedef std::shared_ptr<IShow> ShowPtr;
class IMediaLibrary
{
......@@ -31,6 +33,8 @@ class IMediaLibrary
virtual bool files( std::vector<FilePtr>& res ) = 0;
virtual AlbumPtr album( const std::string& id3Tag ) = 0;
virtual AlbumPtr createAlbum( const std::string& id3Tag ) = 0;
virtual ShowPtr show( const std::string& name ) = 0;
virtual ShowPtr createShow( const std::string& name ) = 0;
virtual void addMetadataService( IMetadataService* service ) = 0;
};
......
......@@ -7,12 +7,16 @@ class IShow
{
public:
virtual ~IShow() {}
virtual const std::string& name() = 0;
virtual unsigned int releaseYear() = 0;
virtual const std::string& shortSummary() = 0;
virtual const std::string& artworkUrl() = 0;
virtual time_t lastSyncDate() = 0;
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 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 const std::string& tvdbId() = 0;
virtual bool setTvdbId( const std::string& id ) = 0;
};
#endif // ISHOW_H
......@@ -29,7 +29,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
Album( sqlite3* dbConnection, sqlite3_stmt* stmt );
Album( const std::string& id3tag );
unsigned int id() const;
virtual unsigned int id() const;
virtual const std::string& name() const;
virtual bool setName( const std::string& name );
virtual time_t releaseDate() const;
......
......@@ -95,6 +95,18 @@ AlbumPtr MediaLibrary::createAlbum( const std::string& id3Tag )
return Album::create( m_dbConnection, id3Tag );
}
ShowPtr MediaLibrary::show(const std::string& name)
{
static const std::string req = "SELECT * FROM " + policy::ShowTable::Name
+ " WHERE name = ?";
return SqliteTools::fetchOne<Show>( m_dbConnection, req, name );
}
ShowPtr MediaLibrary::createShow(const std::string& name)
{
return Show::create( m_dbConnection, name );
}
void MediaLibrary::addMetadataService(IMetadataService* service)
{
typedef std::unique_ptr<IMetadataService> MdsPtr;
......
......@@ -25,6 +25,9 @@ class MediaLibrary : public IMediaLibrary
virtual AlbumPtr album( const std::string& id3Tag );
virtual AlbumPtr createAlbum( const std::string& id3Tag );
virtual ShowPtr show( const std::string& name );
virtual ShowPtr createShow( const std::string& name );
virtual void addMetadataService( IMetadataService* service );
private:
sqlite3* m_dbConnection;
......
......@@ -8,43 +8,79 @@ unsigned int Show::* const policy::ShowTable::PrimaryKey = &Show::m_id;
Show::Show(sqlite3* dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
m_name = (const char*)sqlite3_column_text( stmt, 1 );
m_releaseYear = sqlite3_column_int( stmt, 2 );
m_shortSummary = (const char*)sqlite3_column_text( stmt, 3 );
m_artworkUrl = (const char*)sqlite3_column_text( stmt, 4 );
m_lastSyncDate = sqlite3_column_int( stmt, 5 );
m_tvdbId = (const char*)sqlite3_column_text( stmt, 6 );
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_name = Traits<std::string>::Load( stmt, 1 );
m_releaseDate = Traits<unsigned int>::Load( stmt, 2 );
m_shortSummary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = Traits<unsigned int>::Load( stmt, 5 );
m_tvdbId = Traits<std::string>::Load( stmt, 6 );
}
Show::Show(sqlite3* dbConnection)
: m_dbConnection( dbConnection )
, m_id( 0 )
Show::Show( const std::string& name )
: m_id( 0 )
, m_name( name )
, m_releaseDate( 0 )
, m_lastSyncDate( 0 )
{
}
const std::string& Show::name()
unsigned int Show::id() const
{
return m_id;
}
const std::string& Show::name() const
{
return m_name;
}
unsigned int Show::releaseYear()
time_t Show::releaseDate() const
{
return m_releaseYear;
return m_releaseDate;
}
const std::string& Show::shortSummary()
bool Show::setReleaseDate( time_t date )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET release_date = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
}
const std::string& Show::shortSummary() const
{
return m_shortSummary;
}
const std::string& Show::artworkUrl()
bool Show::setShortSummary( const std::string& summary )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET short_summary = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_shortSummary = summary;
return true;
}
const std::string& Show::artworkUrl() const
{
return m_artworkUrl;
}
bool Show::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET artwork_url = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
}
time_t Show::lastSyncDate()
time_t Show::lastSyncDate() const
{
return m_lastSyncDate;
}
......@@ -54,14 +90,37 @@ const std::string& Show::tvdbId()
return m_tvdbId;
}
bool Show::setTvdbId( const std::string& tvdbId )
{
static const std::string& req = "UPDATE " + policy::ShowTable::Name
+ " SET tvdb_id = ? WHERE id_show = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, tvdbId, m_id ) == false )
return false;
m_tvdbId = tvdbId;
return true;
}
bool Show::createTable(sqlite3* dbConnection)
{
const char* req = "CREATE TABLE IF NOT EXISTS Show("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowTable::Name + "("
"id_show INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT, UNSIGNED INTEGER release_year, TEXT short_summary,"
"name TEXT, "
"release_date UNSIGNED INTEGER,"
"short_summary TEXT,"
"artwork_url TEXT,"
"last_sync_date UNSIGNED INTEGER,"
"tvdb_id TEXT"
")";
return SqliteTools::executeRequest( dbConnection, req );
}
ShowPtr Show::create( sqlite3* dbConnection, const std::string& name )
{
auto show = std::make_shared<Show>( name );
static const std::string req = "INSERT INTO " + policy::ShowTable::Name
+ "(name) VALUES(?)";
if ( _Cache::insert( dbConnection, show, req, name ) == false )
return nullptr;
show->m_dbConnection = dbConnection;
return show;
}
......@@ -4,6 +4,7 @@
#include <sqlite3.h>
#include "Cache.h"
#include "IMediaLibrary.h"
#include "IShow.h"
class Show;
......@@ -22,22 +23,28 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
{
public:
Show( sqlite3* dbConnection, sqlite3_stmt* stmt );
Show( sqlite3* dbConnection );
virtual const std::string& name();
virtual unsigned int releaseYear();
virtual const std::string& shortSummary();
virtual const std::string& artworkUrl();
virtual time_t lastSyncDate();
Show( const std::string& name );
virtual unsigned int id() const;
virtual const std::string& name() const;
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 const std::string& tvdbId();
virtual bool setTvdbId( const std::string& summary );
static bool createTable( sqlite3* dbConnection );
static ShowPtr create(sqlite3* dbConnection, const std::string& name );
protected:
sqlite3* m_dbConnection;
unsigned int m_id;
std::string m_name;
unsigned int m_releaseYear;
time_t m_releaseDate;
std::string m_shortSummary;
std::string m_artworkUrl;
time_t m_lastSyncDate;
......@@ -45,6 +52,7 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
friend class Cache<Show, IShow, policy::ShowTable>;
friend struct policy::ShowTable;
typedef Cache<Show, IShow, policy::ShowTable> _Cache;
};
#endif // SHOW_H
......@@ -35,6 +35,7 @@ list(APPEND TEST_SRCS
Labels.cpp
Albums.cpp
Tests.cpp
Shows.cpp
)
add_executable(unittest ${TEST_SRCS})
......
#include "gtest/gtest.h"
#include "IFile.h"
#include "IMediaLibrary.h"
#include "IShow.h"
class Shows : public testing::Test
{
public:
static IMediaLibrary* ml;
protected:
virtual void SetUp()
{
ml = MediaLibraryFactory::create();
bool res = ml->initialize( "test.db" );
ASSERT_TRUE( res );
}
virtual void TearDown()
{
delete ml;
ml = nullptr;
unlink("test.db");
}
};
IMediaLibrary* Shows::ml;
TEST_F( Shows, Create )
{
auto s = ml->createShow( "show" );
ASSERT_NE( s, nullptr );
auto s2 = ml->show( "show" );
ASSERT_EQ( s, s2 );
}
TEST_F( Shows, Fetch )
{
auto s = ml->createShow( "show" );
// Clear the cache
delete ml;
SetUp();
auto s2 = ml->show( "show" );
// The shared pointers are expected to point to different instances
ASSERT_NE( s, s2 );
ASSERT_EQ( s->id(), s2->id() );
}
TEST_F( Shows, SetReleaseDate )
{
auto s = ml->createShow( "show" );
s->setReleaseDate( 1234 );
ASSERT_EQ( s->releaseDate(), 1234 );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
ASSERT_EQ( s->releaseDate(), s2->releaseDate() );
}
TEST_F( Shows, SetShortSummary )
{
auto s = ml->createShow( "show" );
s->setShortSummary( "summary" );
ASSERT_EQ( s->shortSummary(), "summary" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
ASSERT_EQ( s->shortSummary(), s2->shortSummary() );
}
TEST_F( Shows, SetArtworkUrl )
{
auto s = ml->createShow( "show" );
s->setArtworkUrl( "artwork" );
ASSERT_EQ( s->artworkUrl(), "artwork" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
ASSERT_EQ( s->artworkUrl(), s2->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