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

Movie: Remove title property.

It is a duplicate of the associated media title
parent 5747d700
......@@ -33,7 +33,6 @@ class IMovie
public:
virtual ~IMovie() {}
virtual int64_t id() const = 0;
virtual const std::string& title() const = 0;
virtual const std::string& shortSummary() const = 0;
virtual const std::string& imdbId() const = 0;
virtual Query<IMedia> media() = 0;
......
......@@ -583,14 +583,17 @@ MoviePtr MediaLibrary::movie( int64_t id ) const
MoviePtr MediaLibrary::movie( const std::string& title ) const
{
static const std::string req = "SELECT * FROM " + policy::MovieTable::Name
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE title = ?";
return Movie::fetch( this, req, title );
auto media = Media::fetch( this, req, title );
if ( media == nullptr || media->subType() != IMedia::SubType::Movie )
return nullptr;
return media->movie();
}
std::shared_ptr<Movie> MediaLibrary::createMovie( Media& media, const std::string& title )
std::shared_ptr<Movie> MediaLibrary::createMovie( Media& media )
{
auto movie = Movie::create( this, media.id(), title );
auto movie = Movie::create( this, media.id() );
media.setMovie( movie );
media.save();
return movie;
......
......@@ -99,7 +99,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual MoviePtr movie( int64_t id ) const override;
virtual MoviePtr movie( const std::string& title ) const override;
std::shared_ptr<Movie> createMovie( Media& media, const std::string& title );
std::shared_ptr<Movie> createMovie( Media& media );
virtual ArtistPtr artist( int64_t id ) const override;
ArtistPtr artist( const std::string& name );
......
......@@ -41,16 +41,14 @@ Movie::Movie(MediaLibraryPtr ml, sqlite::Row& row )
{
row >> m_id
>> m_mediaId
>> m_title
>> m_summary
>> m_imdbId;
}
Movie::Movie( MediaLibraryPtr ml, int64_t mediaId, const std::string& title )
Movie::Movie( MediaLibraryPtr ml, int64_t mediaId )
: m_ml( ml )
, m_id( 0 )
, m_mediaId( mediaId )
, m_title( title )
{
}
......@@ -59,11 +57,6 @@ int64_t Movie::id() const
return m_id;
}
const std::string&Movie::title() const
{
return m_title;
}
const std::string& Movie::shortSummary() const
{
return m_summary;
......@@ -107,7 +100,6 @@ void Movie::createTable( sqlite::Connection* dbConnection )
+ "("
"id_movie INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id UNSIGNED INTEGER NOT NULL,"
"title TEXT UNIQUE ON CONFLICT FAIL,"
"summary TEXT,"
"imdb_id TEXT,"
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name
......@@ -119,12 +111,12 @@ void Movie::createTable( sqlite::Connection* dbConnection )
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<Movie> Movie::create(MediaLibraryPtr ml, int64_t mediaId, const std::string& title )
std::shared_ptr<Movie> Movie::create(MediaLibraryPtr ml, int64_t mediaId )
{
auto movie = std::make_shared<Movie>( ml, mediaId, title );
auto movie = std::make_shared<Movie>( ml, mediaId );
static const std::string req = "INSERT INTO " + policy::MovieTable::Name
+ "(media_id, title) VALUES(?, ?)";
if ( insert( ml, movie, req, mediaId, title ) == false )
+ "(media_id) VALUES(?)";
if ( insert( ml, movie, req, mediaId ) == false )
return nullptr;
return movie;
}
......
......@@ -46,10 +46,9 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
{
public:
Movie( MediaLibraryPtr ml, sqlite::Row& row );
Movie( MediaLibraryPtr ml, int64_t mediaId, const std::string& title );
Movie( MediaLibraryPtr ml, int64_t mediaId );
virtual int64_t id() const override;
virtual const std::string& title() const override;
virtual const std::string& shortSummary() const override;
bool setShortSummary(const std::string& summary);
virtual const std::string& imdbId() const override;
......@@ -57,14 +56,13 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
virtual Query<IMedia> media() override;
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Movie> create( MediaLibraryPtr ml, int64_t mediaId, const std::string& title );
static std::shared_ptr<Movie> create( MediaLibraryPtr ml, int64_t mediaId );
static MoviePtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
private:
MediaLibraryPtr m_ml;
int64_t m_id;
int64_t m_mediaId;
std::string m_title;
std::string m_summary;
std::string m_imdbId;
......
......@@ -37,15 +37,16 @@ class Movies : public Tests
TEST_F( Movies, Create )
{
auto media = std::static_pointer_cast<Media>( ml->addMedia( "movie.mkv" ) );
auto m = ml->createMovie( *media, "movie" );
auto m = ml->createMovie( *media );
ASSERT_NE( m, nullptr );
ASSERT_EQ( m->title(), "movie" );
}
TEST_F( Movies, Fetch )
{
auto media = std::static_pointer_cast<Media>( ml->addMedia( "movie.mkv" ) );
auto m = ml->createMovie( *media, "movie" );
media->setTitle( "movie" );
// Setting the movie during ml::createMovie will save the media, thus saving the title.
auto m = ml->createMovie( *media );
auto m2 = ml->movie( "movie" );
ASSERT_EQ( m, m2 );
......@@ -54,13 +55,13 @@ TEST_F( Movies, Fetch )
m2 = ml->movie( "movie" );
ASSERT_NE( m2, nullptr );
ASSERT_EQ( m2->title(), "movie" );
}
TEST_F( Movies, SetShortSummary )
{
auto media = std::static_pointer_cast<Media>( ml->addMedia( "movie.mkv" ) );
auto m = ml->createMovie( *media, "movie" );
media->setTitle( "movie" );
auto m = ml->createMovie( *media );
ASSERT_EQ( m->shortSummary().length(), 0u );
m->setShortSummary( "great movie" );
......@@ -75,7 +76,8 @@ TEST_F( Movies, SetShortSummary )
TEST_F( Movies, SetImdbId )
{
auto media = std::static_pointer_cast<Media>( ml->addMedia( "movie.mkv" ) );
auto m = ml->createMovie( *media, "movie" );
media->setTitle( "movie" );
auto m = ml->createMovie( *media );
ASSERT_EQ( m->imdbId().length(), 0u );
m->setImdbId( "id" );
......@@ -92,7 +94,7 @@ TEST_F( Movies, AssignToFile )
auto f = std::static_pointer_cast<Media>( ml->addMedia( "file.avi" ) );
ASSERT_EQ( f->movie(), nullptr );
auto m = ml->createMovie( *f, "movie" );
auto m = ml->createMovie( *f );
ASSERT_EQ( f->movie(), m );
......@@ -101,5 +103,4 @@ TEST_F( Movies, AssignToFile )
auto f2 = ml->media( f->id() );
auto m2 = f2->movie();
ASSERT_NE( m2, nullptr );
ASSERT_EQ( m2->title(), "movie" );
}
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