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

Handle assigning an album track to a file

parent 87e2b32a
......@@ -25,7 +25,8 @@ class IFile
virtual ~IFile() {}
virtual unsigned int id() const = 0;
virtual std::shared_ptr<IAlbumTrack> albumTrack() = 0;
virtual AlbumTrackPtr albumTrack() = 0;
virtual bool setAlbumTrack(AlbumTrackPtr albumTrack ) = 0;
virtual unsigned int duration() const = 0;
virtual std::shared_ptr<IShowEpisode> showEpisode() = 0;
virtual int playCount() const = 0;
......
......@@ -50,7 +50,7 @@ FilePtr File::create( sqlite3* dbConnection, const std::string& mrl )
return self;
}
std::shared_ptr<IAlbumTrack> File::albumTrack()
AlbumTrackPtr File::albumTrack()
{
if ( m_albumTrack == nullptr && m_albumTrackId != 0 )
{
......@@ -59,6 +59,17 @@ std::shared_ptr<IAlbumTrack> File::albumTrack()
return m_albumTrack;
}
bool File::setAlbumTrack( AlbumTrackPtr albumTrack )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET album_track_id = ? "
"WHERE id_file = ?";
if ( SqliteTools::executeUpdate( m_dbConnection, req, albumTrack->id(), m_id ) == false )
return false;
m_albumTrackId = albumTrack->id();
m_albumTrack = albumTrack;
return true;
}
unsigned int File::duration() const
{
return m_duration;
......
......@@ -46,7 +46,8 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
static bool createTable(sqlite3* connection);
virtual unsigned int id() const;
virtual std::shared_ptr<IAlbumTrack> albumTrack();
virtual AlbumTrackPtr albumTrack();
virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual unsigned int duration() const;
virtual std::shared_ptr<IShowEpisode> showEpisode();
virtual bool addLabel( LabelPtr label );
......@@ -69,7 +70,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
// Auto fetched related properties
Album* m_album;
std::shared_ptr<AlbumTrack> m_albumTrack;
AlbumTrackPtr m_albumTrack;
std::shared_ptr<ShowEpisode> m_showEpisode;
friend class Cache<File, IFile, policy::FileTable, policy::FileCache>;
......
......@@ -29,7 +29,6 @@ unsigned int Label::id() const
return m_id;
}
const std::string& Label::name()
{
return m_name;
......
......@@ -90,10 +90,13 @@ class SqliteTools
return sqlite3_changes( dbConnection ) > 0;
}
/**
* This is meant to be used for "write only" requests, as the statement is not
* exposed to the caller.
*/
template <typename... Args>
static bool executeUpdate( sqlite3* dbConnection, const std::string& req, const Args&... args )
{
// The code would be exactly the same, do not freak out because it call delete :)
return executeDelete( dbConnection, req, args... );
}
template <typename... Args>
static bool executeRequest( sqlite3* dbConnection, const std::string& req, const Args&... args )
{
......
......@@ -2,6 +2,7 @@
#include "IAlbum.h"
#include "IAlbumTrack.h"
#include "IFile.h"
#include "IMediaLibrary.h"
class Albums : public testing::Test
......@@ -70,3 +71,24 @@ TEST_F( Albums, AddTrack )
ASSERT_EQ( tracks.size(), 1u );
ASSERT_EQ( tracks[0]->title(), track->title() );
}
TEST_F( Albums, AssignTrack )
{
auto f = ml->addFile( "file" );
auto a = ml->createAlbum( "album" );
auto t = a->addTrack( "track", 1 );
ASSERT_EQ( f->albumTrack(), nullptr );
bool res = f->setAlbumTrack( t );
ASSERT_TRUE( res );
ASSERT_NE( f->albumTrack(), nullptr );
ASSERT_EQ( f->albumTrack(), t );
delete ml;
SetUp();
f = ml->file( "file" );
t = f->albumTrack();
ASSERT_NE( t, nullptr );
ASSERT_EQ( t->title(), "track" );
}
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