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

Album: Fix non-sensical use of id3tag

Rename name -> title
parent 71e2f28e
......@@ -10,8 +10,7 @@ class IAlbum
public:
virtual ~IAlbum() {}
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 0;
virtual bool setName( const std::string& name ) = 0;
virtual const std::string& title() const = 0;
virtual time_t releaseDate() const = 0;
virtual bool setReleaseDate( time_t date ) = 0;
virtual const std::string& shortSummary() const = 0;
......@@ -19,7 +18,7 @@ class IAlbum
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const = 0;
virtual AlbumTrackPtr addTrack( const std::string& name, unsigned int trackId ) = 0;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackId ) = 0;
virtual bool destroy() = 0;
};
......
......@@ -19,8 +19,8 @@ class IMediaLibrary
virtual bool deleteLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
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 AlbumPtr album( const std::string& title ) = 0;
virtual AlbumPtr createAlbum( const std::string& title ) = 0;
virtual ShowPtr show( const std::string& name ) = 0;
virtual ShowPtr createShow( const std::string& name ) = 0;
virtual MoviePtr movie( const std::string& title ) = 0;
......
......@@ -11,19 +11,18 @@ Album::Album(DBConnection dbConnection, sqlite3_stmt* stmt)
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
m_name = Traits<std::string>::Load( stmt, 1 );
m_title = Traits<std::string>::Load( stmt, 1 );
m_releaseDate = sqlite3_column_int( stmt, 2 );
m_shortSummary = Traits<std::string>::Load( stmt, 3 );
m_artworkUrl = Traits<std::string>::Load( stmt, 4 );
m_lastSyncDate = sqlite3_column_int( stmt, 5 );
m_id3tag = Traits<std::string>::Load( stmt, 6 );
}
Album::Album( const std::string& id3tag )
Album::Album(const std::string& title )
: m_id( 0 )
, m_title( title )
, m_releaseDate( 0 )
, m_lastSyncDate( 0 )
, m_id3tag( id3tag )
{
}
......@@ -32,19 +31,9 @@ unsigned int Album::id() const
return m_id;
}
const std::string& Album::name() const
const std::string& Album::title() const
{
return m_name;
}
bool Album::setName( const std::string& name )
{
static const std::string& req = "UPDATE " + policy::AlbumTable::Name
+ " SET name = ? WHERE id_album = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, name, m_id ) == false )
return false;
m_name = name;
return true;
return m_title;
}
time_t Album::releaseDate() const
......@@ -104,9 +93,9 @@ bool Album::tracks( std::vector<std::shared_ptr<IAlbumTrack> >& tracks ) const
return SqliteTools::fetchAll<AlbumTrack>( m_dbConnection, req, tracks, m_id );
}
AlbumTrackPtr Album::addTrack( const std::string& name, unsigned int trackNb )
AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
{
return AlbumTrack::create( m_dbConnection, m_id, name, trackNb );
return AlbumTrack::create( m_dbConnection, m_id, title, trackNb );
}
bool Album::destroy()
......@@ -128,22 +117,21 @@ bool Album::createTable(DBConnection dbConnection )
policy::AlbumTable::Name +
"("
"id_album INTEGER PRIMARY KEY AUTOINCREMENT,"
"name TEXT,"
"title TEXT UNIQUE ON CONFLICT FAIL,"
"release_date UNSIGNED INTEGER,"
"short_summary TEXT,"
"artwork_url TEXT,"
"UNSIGNED INTEGER last_sync_date,"
"id3tag TEXT UNIQUE ON CONFLICT FAIL"
"UNSIGNED INTEGER last_sync_date"
")";
return SqliteTools::executeRequest( dbConnection, req );
}
AlbumPtr Album::create(DBConnection dbConnection, const std::string& id3Tag )
AlbumPtr Album::create(DBConnection dbConnection, const std::string& title )
{
auto album = std::make_shared<Album>( id3Tag );
auto album = std::make_shared<Album>( title );
static const std::string& req = "INSERT INTO " + policy::AlbumTable::Name +
"(id_album, id3tag) VALUES(NULL, ?)";
if ( _Cache::insert( dbConnection, album, req, id3Tag ) == false )
"(id_album, title) VALUES(NULL, ?)";
if ( _Cache::insert( dbConnection, album, req, title ) == false )
return nullptr;
album->m_dbConnection = dbConnection;
return album;
......
......@@ -27,11 +27,10 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
typedef Cache<Album, IAlbum, policy::AlbumTable> _Cache;
public:
Album( DBConnection dbConnection, sqlite3_stmt* stmt );
Album( const std::string& id3tag );
Album( const std::string& title );
virtual unsigned int id() const;
virtual const std::string& name() const;
virtual bool setName( const std::string& name );
virtual const std::string& title() const;
virtual time_t releaseDate() const;
virtual bool setReleaseDate( time_t date );
virtual const std::string& shortSummary() const;
......@@ -40,21 +39,20 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual time_t lastSyncDate() const;
virtual bool tracks( std::vector<std::shared_ptr<IAlbumTrack>>& tracks ) const;
virtual AlbumTrackPtr addTrack( const std::string& name, unsigned int trackNb );
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackNb );
virtual bool destroy();
static bool createTable( DBConnection dbConnection );
static AlbumPtr create( DBConnection dbConnection, const std::string& id3Tag );
static AlbumPtr create(DBConnection dbConnection, const std::string& title );
protected:
DBConnection m_dbConnection;
unsigned int m_id;
std::string m_name;
std::string m_title;
unsigned int m_releaseDate;
std::string m_shortSummary;
std::string m_artworkUrl;
time_t m_lastSyncDate;
std::string m_id3tag;
friend class Cache<Album, IAlbum, policy::AlbumTable>;
friend struct policy::AlbumTable;
......
......@@ -92,17 +92,17 @@ bool MediaLibrary::deleteLabel( LabelPtr label )
return Label::destroy( m_dbConnection, std::static_pointer_cast<Label>( label ) );
}
AlbumPtr MediaLibrary::album( const std::string& id3Tag )
AlbumPtr MediaLibrary::album(const std::string& title )
{
// We can't use Cache helper, since albums are cached by primary keys
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE id3tag = ?";
return SqliteTools::fetchOne<Album>( DBConnection( m_dbConnection ), req, id3Tag );
" WHERE title = ?";
return SqliteTools::fetchOne<Album>( DBConnection( m_dbConnection ), req, title );
}
AlbumPtr MediaLibrary::createAlbum( const std::string& id3Tag )
AlbumPtr MediaLibrary::createAlbum(const std::string& title )
{
return Album::create( m_dbConnection, id3Tag );
return Album::create( m_dbConnection, title );
}
ShowPtr MediaLibrary::show(const std::string& name)
......
......@@ -22,8 +22,8 @@ class MediaLibrary : public IMediaLibrary
virtual bool deleteLabel(const std::string& text );
virtual bool deleteLabel( LabelPtr label );
virtual AlbumPtr album( const std::string& id3Tag );
virtual AlbumPtr createAlbum( const std::string& id3Tag );
virtual AlbumPtr album( const std::string& title );
virtual AlbumPtr createAlbum( const std::string& title );
virtual ShowPtr show( const std::string& name );
virtual ShowPtr createShow( const std::string& name );
......
......@@ -29,11 +29,12 @@ std::unique_ptr<IMediaLibrary> Albums::ml;
TEST_F( Albums, Create )
{
auto a = ml->createAlbum( "mytag" );
auto a = ml->createAlbum( "album" );
ASSERT_NE( a, nullptr );
auto a2 = ml->album( "mytag" );
auto a2 = ml->album( "album" );
ASSERT_EQ( a, a2 );
ASSERT_EQ( a2->title(), "album" );
}
TEST_F( Albums, Fetch )
......@@ -120,19 +121,6 @@ TEST_F( Albums, SetGenre )
ASSERT_EQ( t->genre(), t2->genre() );
}
TEST_F( Albums, SetName )
{
auto a = ml->createAlbum( "album" );
a->setName( "albumname" );
ASSERT_EQ( a->name(), "albumname" );
SetUp();
auto a2 = ml->album( "album" );
ASSERT_EQ( a->name(), a2->name() );
}
TEST_F( Albums, SetReleaseDate )
{
auto a = ml->createAlbum( "album" );
......@@ -176,7 +164,6 @@ TEST_F( Albums, FetchAlbumFromTrack )
{
{
auto a = ml->createAlbum( "album" );
a->setName( "album" );
auto f = ml->addFile( "file" );
auto t = a->addTrack( "track 1", 1 );
f->setAlbumTrack( t );
......@@ -187,13 +174,12 @@ TEST_F( Albums, FetchAlbumFromTrack )
auto t = f->albumTrack();
auto a = t->album();
ASSERT_NE( a, nullptr );
ASSERT_EQ( a->name(), "album" );
ASSERT_EQ( a->title(), "album" );
}
TEST_F( Albums, DestroyAlbum )
{
auto a = ml->createAlbum( "album" );
a->setName( "album" );
auto f = ml->addFile( "file" );
auto t = a->addTrack( "track 1", 1 );
f->setAlbumTrack( t );
......
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