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

Add basic ShowEpisode features

parent dc8f288d
......@@ -11,12 +11,14 @@ class IFile;
class ILabel;
class IMetadataService;
class IShow;
class IShowEpisode;
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;
typedef std::shared_ptr<IShowEpisode> ShowEpisodePtr;
class IMediaLibrary
{
......
#ifndef ISHOW_H
#define ISHOW_H
#include <string>
#include "IMediaLibrary.h"
class IShow
{
......@@ -17,6 +17,8 @@ class IShow
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual const std::string& tvdbId() = 0;
virtual bool setTvdbId( const std::string& id ) = 0;
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber ) = 0;
virtual bool episodes( std::vector<ShowEpisodePtr>& episodes ) = 0;
};
#endif // ISHOW_H
......@@ -11,13 +11,18 @@ class IShowEpisode
public:
virtual ~IShowEpisode(){}
virtual const std::string& artworkUrl() = 0;
virtual unsigned int episodeNumber() = 0;
virtual time_t lastSyncDate() = 0;
virtual const std::string& name() = 0;
virtual unsigned int seasonNuber() = 0;
virtual const std::string& shortSummary() = 0;
virtual const std::string& tvdbId() = 0;
virtual unsigned int id() const = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual unsigned int episodeNumber() const = 0;
virtual time_t lastSyncDate() const = 0;
virtual const std::string& name() const = 0;
virtual unsigned int seasonNumber() const = 0;
virtual bool setSeasonNumber(unsigned int seasonNumber) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& tvdbId() const = 0;
virtual bool setTvdbId( const std::string& tvdbId ) = 0;
virtual std::shared_ptr<IShow> show() = 0;
};
......
#include "Show.h"
#include "ShowEpisode.h"
#include "SqliteTools.h"
const std::string policy::ShowTable::Name = "Show";
......@@ -100,6 +101,18 @@ bool Show::setTvdbId( const std::string& tvdbId )
return true;
}
ShowEpisodePtr Show::addEpisode(const std::string& title, unsigned int episodeNumber)
{
return ShowEpisode::create( m_dbConnection, title, episodeNumber, m_id );
}
bool Show::episodes( std::vector<ShowEpisodePtr>& episodes )
{
static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name
+ " WHERE show_id = ?";
return SqliteTools::fetchAll<ShowEpisode>( m_dbConnection, req, episodes, m_id );
}
bool Show::createTable(sqlite3* dbConnection)
{
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowTable::Name + "("
......
......@@ -36,6 +36,8 @@ class Show : public IShow, public Cache<Show, IShow, policy::ShowTable>
virtual time_t lastSyncDate() const;
virtual const std::string& tvdbId();
virtual bool setTvdbId( const std::string& summary );
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber );
virtual bool episodes( std::vector<ShowEpisodePtr>& episodes );
static bool createTable( sqlite3* dbConnection );
static ShowPtr create(sqlite3* dbConnection, const std::string& name );
......
......@@ -2,60 +2,114 @@
#include "SqliteTools.h"
#include "Show.h"
const std::string policy::ShowEpisodeTable::Name = "Show";
const std::string policy::ShowEpisodeTable::Name = "ShowEpisode";
const std::string policy::ShowEpisodeTable::CacheColumn = "id_show";
unsigned int ShowEpisode::* const policy::ShowEpisodeTable::PrimaryKey = &ShowEpisode::m_id;
ShowEpisode::ShowEpisode( sqlite3* dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
m_artworkUrl = (const char*)sqlite3_column_text( stmt, 1 );
m_episodeNumber = sqlite3_column_int( stmt, 2 );
m_lastSyncDate = sqlite3_column_int( stmt, 3 );
m_name = (const char*)sqlite3_column_text( stmt, 4 );
m_seasonNumber = sqlite3_column_int( stmt, 5 );
m_shortSummary = (const char*)sqlite3_column_text( stmt, 6 );
m_tvdbId = (const char*)sqlite3_column_text( stmt, 7 );
m_showId = sqlite3_column_int( stmt, 8 );
m_id = Traits<unsigned int>::Load( stmt, 0 );
m_artworkUrl = Traits<std::string>::Load( stmt, 1 );
m_episodeNumber = Traits<unsigned int>::Load( stmt, 2 );
m_lastSyncDate = Traits<time_t>::Load( stmt, 3 );
m_name = Traits<std::string>::Load( stmt, 4 );
m_seasonNumber = Traits<unsigned int>::Load( stmt, 5 );
m_shortSummary = Traits<std::string>::Load( stmt, 6 );
m_tvdbId = Traits<std::string>::Load( stmt, 7 );
m_showId = Traits<unsigned int>::Load( stmt, 8 );
}
ShowEpisode::ShowEpisode(const std::string& name, unsigned int episodeNumber, unsigned int showId )
: m_dbConnection( nullptr )
, m_id( 0 )
, m_episodeNumber( episodeNumber )
, m_name( name )
, m_seasonNumber( 0 )
, m_showId( showId )
{
}
unsigned int ShowEpisode::id() const
{
return m_id;
}
const std::string& ShowEpisode::artworkUrl()
const std::string& ShowEpisode::artworkUrl() const
{
return m_artworkUrl;
}
unsigned int ShowEpisode::episodeNumber()
bool ShowEpisode::setArtworkUrl( const std::string& artworkUrl )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name
+ " SET artwork_url = ? WHERE id_episode = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, artworkUrl, m_id ) == false )
return false;
m_artworkUrl = artworkUrl;
return true;
}
unsigned int ShowEpisode::episodeNumber() const
{
return m_episodeNumber;
}
time_t ShowEpisode::lastSyncDate()
time_t ShowEpisode::lastSyncDate() const
{
return m_lastSyncDate;
}
const std::string&ShowEpisode::name()
const std::string& ShowEpisode::name() const
{
return m_name;
}
unsigned int ShowEpisode::seasonNuber()
unsigned int ShowEpisode::seasonNumber() const
{
return m_seasonNumber;
}
const std::string&ShowEpisode::shortSummary()
bool ShowEpisode::setSeasonNumber( unsigned int seasonNumber )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name
+ " SET season_number = ? WHERE id_episode = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, seasonNumber, m_id ) == false )
return false;
m_seasonNumber = seasonNumber;
return true;
}
const std::string& ShowEpisode::shortSummary() const
{
return m_shortSummary;
}
const std::string&ShowEpisode::tvdbId()
bool ShowEpisode::setShortSummary( const std::string& summary )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name
+ " SET episode_summary = ? WHERE id_episode = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, summary, m_id ) == false )
return false;
m_shortSummary = summary;
return true;
}
const std::string& ShowEpisode::tvdbId() const
{
return m_tvdbId;
}
bool ShowEpisode::setTvdbId( const std::string& tvdbId )
{
static const std::string req = "UPDATE " + policy::ShowEpisodeTable::Name
+ " SET tvdb_id = ? WHERE id_episode = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, tvdbId, m_id ) == false )
return false;
m_tvdbId = tvdbId;
return true;
}
std::shared_ptr<IShow> ShowEpisode::show()
{
if ( m_show == nullptr && m_showId != 0 )
......@@ -67,17 +121,29 @@ std::shared_ptr<IShow> ShowEpisode::show()
bool ShowEpisode::createTable(sqlite3* dbConnection)
{
const char* req = "CREATE TABLE IF NOT EXISTS ShowEpisode("
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowEpisodeTable::Name
+ "("
"id_episode INTEGER PRIMARY KEY AUTOINCREMENT,"
"artwork_url TEXT,"
"episode_number UNSIGNED INT,"
"last_sync_date UNSIGNED INT,"
"name TEXT,"
"title TEXT,"
"season_number UNSIGNED INT,"
"episode_summary TEXT,"
"tvdb_id TEXT,"
"show_id UNSIGNED INT,"
"FOREIGN KEY(show_id) REFERENCES Show(id_show)"
"FOREIGN KEY(show_id) REFERENCES " + policy::ShowTable::Name + "(id_show)"
")";
return SqliteTools::executeRequest( dbConnection, req );
}
ShowEpisodePtr ShowEpisode::create( sqlite3* dbConnection, const std::string& title, unsigned int episodeNumber, unsigned int showId )
{
auto episode = std::make_shared<ShowEpisode>( title, episodeNumber, showId );
static const std::string req = "INSERT INTO " + policy::ShowEpisodeTable::Name
+ "(episode_number, title, show_id) VALUES(? , ?, ?)";
if ( _Cache::insert( dbConnection, episode, req, episodeNumber, title, showId ) == false )
return nullptr;
episode->m_dbConnection = dbConnection;
return episode;
}
......@@ -7,6 +7,7 @@ class ShowEpisode;
#include <string>
#include <sqlite3.h>
#include "IMediaLibrary.h"
#include "IShowEpisode.h"
#include "Cache.h"
......@@ -24,17 +25,24 @@ class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode,
{
public:
ShowEpisode(sqlite3* dbConnection, sqlite3_stmt* stmt);
ShowEpisode(const std::string& name, unsigned int episodeNumber, unsigned int showId );
virtual const std::string& artworkUrl();
virtual unsigned int episodeNumber();
virtual time_t lastSyncDate();
virtual const std::string& name();
virtual unsigned int seasonNuber();
virtual const std::string& shortSummary();
virtual const std::string& tvdbId();
virtual unsigned int id() const;
virtual const std::string& artworkUrl() const;
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual unsigned int episodeNumber() const;
virtual time_t lastSyncDate() const;
virtual const std::string& name() const;
virtual unsigned int seasonNumber() const;
virtual bool setSeasonNumber(unsigned int seasonNumber);
virtual const std::string& shortSummary() const;
virtual bool setShortSummary( const std::string& summary );
virtual const std::string& tvdbId() const;
virtual bool setTvdbId( const std::string& tvdbId );
virtual std::shared_ptr<IShow> show();
static bool createTable( sqlite3* dbConnection );
static ShowEpisodePtr create(sqlite3* dbConnection, const std::string& title, unsigned int episodeNumber, unsigned int showId );
private:
sqlite3* m_dbConnection;
......@@ -47,10 +55,11 @@ class ShowEpisode : public IShowEpisode, public Cache<ShowEpisode, IShowEpisode,
std::string m_shortSummary;
std::string m_tvdbId;
unsigned int m_showId;
std::shared_ptr<Show> m_show;
ShowPtr m_show;
friend class Cache<ShowEpisode, IShowEpisode, policy::ShowEpisodeTable>;
friend struct policy::ShowEpisodeTable;
typedef Cache<ShowEpisode, IShowEpisode, policy::ShowEpisodeTable> _Cache;
};
#endif // SHOWEPISODE_H
......@@ -3,6 +3,7 @@
#include "IFile.h"
#include "IMediaLibrary.h"
#include "IShow.h"
#include "IShowEpisode.h"
class Shows : public testing::Test
{
......@@ -92,3 +93,106 @@ TEST_F( Shows, SetArtworkUrl )
auto s2 = ml->show( "show" );
ASSERT_EQ( s->artworkUrl(), s2->artworkUrl() );
}
TEST_F( Shows, SetTvdbId )
{
auto s = ml->createShow( "show" );
s->setTvdbId( "TVDBID" );
ASSERT_EQ( s->tvdbId(), "TVDBID" );
delete ml;
SetUp();
auto s2 = ml->show( "show" );
ASSERT_EQ( s->tvdbId(), s2->tvdbId() );
}
////////////////////////////////////////////////////
// Episodes:
////////////////////////////////////////////////////
TEST_F( Shows, AddEpisode )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
ASSERT_NE( e, nullptr );
ASSERT_EQ( e->episodeNumber(), 1u );
ASSERT_EQ( e->show(), show );
ASSERT_EQ( e->name(), "episode 1" );
std::vector<ShowEpisodePtr> episodes;
bool res = show->episodes( episodes );
ASSERT_TRUE( res );
ASSERT_EQ( episodes.size(), 1u );
ASSERT_EQ( episodes[0], e );
}
TEST_F( Shows, SetEpisodeArtwork )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
bool res = e->setArtworkUrl( "path-to-snapshot" );
ASSERT_TRUE( res );
ASSERT_EQ( e->artworkUrl(), "path-to-snapshot" );
delete ml;
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
ASSERT_EQ( episodes[0]->artworkUrl(), e->artworkUrl() );
}
TEST_F( Shows, SetEpisodeSeasonNumber )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
bool res = e->setSeasonNumber( 42 );
ASSERT_TRUE( res );
ASSERT_EQ( e->seasonNumber(), 42 );
delete ml;
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
ASSERT_EQ( episodes[0]->seasonNumber(), e->seasonNumber() );
}
TEST_F( Shows, SetEpisodeSummary )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
bool res = e->setShortSummary( "Insert spoilers here" );
ASSERT_TRUE( res );
ASSERT_EQ( e->shortSummary(), "Insert spoilers here" );
delete ml;
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
ASSERT_EQ( episodes[0]->shortSummary(), e->shortSummary() );
}
TEST_F( Shows, SetEpisodeTvdbId )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
bool res = e->setTvdbId( "TVDBID" );
ASSERT_TRUE( res );
ASSERT_EQ( e->tvdbId(), "TVDBID" );
delete ml;
SetUp();
show = ml->show( "show" );
std::vector<ShowEpisodePtr> episodes;
show->episodes( episodes );
ASSERT_EQ( episodes[0]->tvdbId(), e->tvdbId() );
}
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