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

IMediaLibrary: Add a shows listing

parent 2788ac76
...@@ -266,6 +266,7 @@ class IMediaLibrary ...@@ -266,6 +266,7 @@ class IMediaLibrary
virtual ShowPtr show( int64_t id ) const = 0; virtual ShowPtr show( int64_t id ) const = 0;
virtual MoviePtr movie( int64_t id ) const = 0; virtual MoviePtr movie( int64_t id ) const = 0;
virtual ArtistPtr artist( int64_t id ) const = 0; virtual ArtistPtr artist( int64_t id ) const = 0;
virtual Query<IShow> shows( const QueryParameters* params = nullptr ) const = 0;
/** /**
* @brief artists List all artists that have at least an album. * @brief artists List all artists that have at least an album.
* Artists that only appear on albums as guests won't be listed from here, but will be * Artists that only appear on albums as guests won't be listed from here, but will be
......
...@@ -580,6 +580,11 @@ std::shared_ptr<Show> MediaLibrary::createShow( const std::string& name ) ...@@ -580,6 +580,11 @@ std::shared_ptr<Show> MediaLibrary::createShow( const std::string& name )
return Show::create( this, name ); return Show::create( this, name );
} }
Query<IShow> MediaLibrary::shows(const QueryParameters* params) const
{
return Show::listAll( this, params );
}
MoviePtr MediaLibrary::movie( int64_t id ) const MoviePtr MediaLibrary::movie( int64_t id ) const
{ {
return Movie::fetch( this, id ); return Movie::fetch( this, id );
......
...@@ -95,6 +95,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb ...@@ -95,6 +95,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual ShowPtr show( int64_t id ) const override; virtual ShowPtr show( int64_t id ) const override;
std::shared_ptr<Show> createShow( const std::string& name ); std::shared_ptr<Show> createShow( const std::string& name );
virtual Query<IShow> shows( const QueryParameters* params = nullptr ) const override;
virtual MoviePtr movie( int64_t id ) const override; virtual MoviePtr movie( int64_t id ) const override;
std::shared_ptr<Movie> createMovie( Media& media ); std::shared_ptr<Movie> createMovie( Media& media );
......
...@@ -177,4 +177,25 @@ std::shared_ptr<Show> Show::create( MediaLibraryPtr ml, const std::string& name ...@@ -177,4 +177,25 @@ std::shared_ptr<Show> Show::create( MediaLibraryPtr ml, const std::string& name
return show; return show;
} }
Query<IShow> Show::listAll( MediaLibraryPtr ml, const QueryParameters* params )
{
std::string req = "FROM " + policy::ShowTable::Name + " ORDER BY ";
SortingCriteria sort = params != nullptr ? params->sort : SortingCriteria::Default;
switch ( sort )
{
case SortingCriteria::ReleaseDate:
req += "release_date";
break;
case SortingCriteria::Default:
case SortingCriteria::Alpha:
default:
req += "name";
break;
}
if ( params != nullptr && params->desc == true )
req += " DESC";
return make_query<Show, IShow>( ml, "*", req );
}
} }
...@@ -70,6 +70,8 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable> ...@@ -70,6 +70,8 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable>
static void createTable( sqlite::Connection* dbConnection ); static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Show> create( MediaLibraryPtr ml, const std::string& name ); static std::shared_ptr<Show> create( MediaLibraryPtr ml, const std::string& name );
static Query<IShow> listAll( MediaLibraryPtr ml, const QueryParameters* params );
protected: protected:
MediaLibraryPtr m_ml; MediaLibraryPtr m_ml;
......
...@@ -199,6 +199,26 @@ TEST_F( Shows, SetEpisodeTvdbId ) ...@@ -199,6 +199,26 @@ TEST_F( Shows, SetEpisodeTvdbId )
ASSERT_EQ( episodes[0]->tvdbId(), e->tvdbId() ); ASSERT_EQ( episodes[0]->tvdbId(), e->tvdbId() );
} }
TEST_F( Shows, ListAll )
{
auto show1 = ml->createShow( "aaaa" );
auto show2 = ml->createShow( "zzzz" );
auto show3 = ml->createShow( "pppp" );
auto shows = ml->shows( nullptr )->all();
ASSERT_EQ( 3u, shows.size() );
ASSERT_EQ( show1->id(), shows[0]->id() );
ASSERT_EQ( show3->id(), shows[1]->id() );
ASSERT_EQ( show2->id(), shows[2]->id() );
medialibrary::QueryParameters params { SortingCriteria::Alpha, true };
shows = ml->shows( &params )->all();
ASSERT_EQ( 3u, shows.size() );
ASSERT_EQ( show2->id(), shows[0]->id() );
ASSERT_EQ( show3->id(), shows[1]->id() );
ASSERT_EQ( show1->id(), shows[2]->id() );
}
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// Files links: // Files links:
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
......
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