Code clean up
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define SONGREPOSITORY_H_
|
#define SONGREPOSITORY_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <mysql/mysql.h>
|
#include <mysql/mysql.h>
|
||||||
@@ -28,10 +29,13 @@ namespace database
|
|||||||
void saveRecord(const model::Song&);
|
void saveRecord(const model::Song&);
|
||||||
void updateRecord(const model::Song&);
|
void updateRecord(const model::Song&);
|
||||||
private:
|
private:
|
||||||
std::vector<model::Song> parseRecords(MYSQL_RES*); // TODO: to be removed
|
std::shared_ptr<MYSQL_BIND> valueBind(model::Song&,
|
||||||
|
std::tuple<char*, char*, char*, char*, char*>&);
|
||||||
|
|
||||||
|
std::tuple<char*, char*, char*, char*, char*> metadataBuffer();
|
||||||
|
|
||||||
std::vector<model::Song> parseRecords(MYSQL_STMT*);
|
std::vector<model::Song> parseRecords(MYSQL_STMT*);
|
||||||
|
|
||||||
model::Song parseRecord(MYSQL_RES*); // TODO: to be removed
|
|
||||||
model::Song parseRecord(MYSQL_STMT*);
|
model::Song parseRecord(MYSQL_STMT*);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ namespace manager {
|
|||||||
class SongManager
|
class SongManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SongManager(std::string&);
|
|
||||||
SongManager(const model::BinaryPath&);
|
SongManager(const model::BinaryPath&);
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +43,6 @@ namespace manager {
|
|||||||
void modifySongOnFilesystem(model::Song&, const model::Song&);
|
void modifySongOnFilesystem(model::Song&, const model::Song&);
|
||||||
|
|
||||||
model::BinaryPath m_bConf;
|
model::BinaryPath m_bConf;
|
||||||
std::string exe_path;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
namespace manager {
|
namespace manager {
|
||||||
class TokenManager {
|
class TokenManager {
|
||||||
public:
|
public:
|
||||||
TokenManager();
|
TokenManager() = default;
|
||||||
|
|
||||||
model::Token retrieveToken(const model::BinaryPath&);
|
model::Token retrieveToken(const model::BinaryPath&);
|
||||||
|
|
||||||
@@ -27,7 +27,6 @@ private:
|
|||||||
|
|
||||||
nlohmann::json createTokenBody(const model::AuthCredentials&);
|
nlohmann::json createTokenBody(const model::AuthCredentials&);
|
||||||
|
|
||||||
model::AuthCredentials parseAuthCredentials(std::string_view);
|
|
||||||
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
|
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
|
||||||
|
|
||||||
std::vector<std::string> extractScopes(const jwt::decoded_jwt&&);
|
std::vector<std::string> extractScopes(const jwt::decoded_jwt&&);
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ namespace type
|
|||||||
title,
|
title,
|
||||||
album,
|
album,
|
||||||
artist,
|
artist,
|
||||||
|
albumArtist,
|
||||||
genre,
|
genre,
|
||||||
year
|
year,
|
||||||
|
titleAndArtist
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,13 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
database::AlbumRepository::AlbumRepository(const model::BinaryPath& bConf)
|
namespace database {
|
||||||
|
AlbumRepository::AlbumRepository(const model::BinaryPath& bConf)
|
||||||
: BaseRepository(bConf)
|
: BaseRepository(bConf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Album> database::AlbumRepository::retrieveRecords()
|
std::vector<model::Album> AlbumRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -30,7 +31,7 @@ std::vector<model::Album> database::AlbumRepository::retrieveRecords()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<model::Album, int> database::AlbumRepository::retrieveRecordWithSongCount(model::Album& album, type::AlbumFilter filter = type::AlbumFilter::id)
|
std::pair<model::Album, int> AlbumRepository::retrieveRecordWithSongCount(model::Album& album, type::AlbumFilter filter = type::AlbumFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving album with song count" << std::endl;
|
std::cout << "retrieving album with song count" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -71,7 +72,7 @@ std::pair<model::Album, int> database::AlbumRepository::retrieveRecordWithSongCo
|
|||||||
return albWSC;
|
return albWSC;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Album database::AlbumRepository::retrieveRecord(model::Album& album, type::AlbumFilter filter)
|
model::Album AlbumRepository::retrieveRecord(model::Album& album, type::AlbumFilter filter)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving album record" << std::endl;
|
std::cout << "retrieving album record" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -122,7 +123,7 @@ model::Album database::AlbumRepository::retrieveRecord(model::Album& album, type
|
|||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool database::AlbumRepository::doesAlbumExists(const model::Album& album, type::AlbumFilter filter)
|
bool AlbumRepository::doesAlbumExists(const model::Album& album, type::AlbumFilter filter)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -173,7 +174,7 @@ bool database::AlbumRepository::doesAlbumExists(const model::Album& album, type:
|
|||||||
return (rowCount > 0) ? true : false;
|
return (rowCount > 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::AlbumRepository::saveAlbum(const model::Album& album)
|
void AlbumRepository::saveAlbum(const model::Album& album)
|
||||||
{
|
{
|
||||||
std::cout << "beginning to insert album record" << std::endl;
|
std::cout << "beginning to insert album record" << std::endl;
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ void database::AlbumRepository::saveAlbum(const model::Album& album)
|
|||||||
std::cout << "done inserting album record" << std::endl;
|
std::cout << "done inserting album record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::AlbumRepository::deleteAlbum(const model::Album& album, type::AlbumFilter filter = type::AlbumFilter::id)
|
void AlbumRepository::deleteAlbum(const model::Album& album, type::AlbumFilter filter = type::AlbumFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "deleting album record" << std::endl;
|
std::cout << "deleting album record" << std::endl;
|
||||||
|
|
||||||
@@ -243,7 +244,7 @@ void database::AlbumRepository::deleteAlbum(const model::Album& album, type::Alb
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Album> database::AlbumRepository::parseRecords(MYSQL_STMT* stmt)
|
std::vector<model::Album> AlbumRepository::parseRecords(MYSQL_STMT* stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing album record" << std::endl;
|
std::cout << "parsing album record" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -304,7 +305,7 @@ std::vector<model::Album> database::AlbumRepository::parseRecords(MYSQL_STMT* st
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check to see if this is not used, if not then remove it
|
// TODO: check to see if this is not used, if not then remove it
|
||||||
model::Album database::AlbumRepository::parseRecord(MYSQL_RES* results)
|
model::Album AlbumRepository::parseRecord(MYSQL_RES* results)
|
||||||
{
|
{
|
||||||
std::cout << "parsing album record" << std::endl;
|
std::cout << "parsing album record" << std::endl;
|
||||||
model::Album album;
|
model::Album album;
|
||||||
@@ -329,7 +330,7 @@ model::Album database::AlbumRepository::parseRecord(MYSQL_RES* results)
|
|||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Album, int> database::AlbumRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
std::pair<model::Album, int> AlbumRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing album record with song count" << std::endl;
|
std::cout << "parsing album record with song count" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -392,7 +393,7 @@ std::pair<model::Album, int> database::AlbumRepository::parseRecordWithSongCount
|
|||||||
return albWSC;
|
return albWSC;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Album database::AlbumRepository::parseRecord(MYSQL_STMT *stmt)
|
model::Album AlbumRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing album record" << std::endl;
|
std::cout << "parsing album record" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -447,3 +448,4 @@ model::Album database::AlbumRepository::parseRecord(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,13 +6,14 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
database::ArtistRepository::ArtistRepository(const model::BinaryPath& binConf)
|
namespace database {
|
||||||
|
ArtistRepository::ArtistRepository(const model::BinaryPath& binConf)
|
||||||
: BaseRepository(binConf)
|
: BaseRepository(binConf)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Artist> database::ArtistRepository::retrieveRecords()
|
std::vector<model::Artist> ArtistRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -29,7 +30,7 @@ std::vector<model::Artist> database::ArtistRepository::retrieveRecords()
|
|||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Artist, int> database::ArtistRepository::retrieveRecordWithSongCount(model::Artist& artist, type::ArtistFilter filter = type::ArtistFilter::id)
|
std::pair<model::Artist, int> ArtistRepository::retrieveRecordWithSongCount(model::Artist& artist, type::ArtistFilter filter = type::ArtistFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving artist record with song count" << std::endl;
|
std::cout << "retrieving artist record with song count" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -73,7 +74,7 @@ std::pair<model::Artist, int> database::ArtistRepository::retrieveRecordWithSong
|
|||||||
return artWSC;
|
return artWSC;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Artist database::ArtistRepository::retrieveRecord(model::Artist& artist, type::ArtistFilter filter)
|
model::Artist ArtistRepository::retrieveRecord(model::Artist& artist, type::ArtistFilter filter)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving artist record" << std::endl;
|
std::cout << "retrieving artist record" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -123,7 +124,7 @@ model::Artist database::ArtistRepository::retrieveRecord(model::Artist& artist,
|
|||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool database::ArtistRepository::doesArtistExist(const model::Artist& artist, type::ArtistFilter filter)
|
bool ArtistRepository::doesArtistExist(const model::Artist& artist, type::ArtistFilter filter)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -174,7 +175,7 @@ bool database::ArtistRepository::doesArtistExist(const model::Artist& artist, ty
|
|||||||
return (rowCount > 0) ? true : false;
|
return (rowCount > 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::ArtistRepository::saveRecord(const model::Artist& artist)
|
void ArtistRepository::saveRecord(const model::Artist& artist)
|
||||||
{
|
{
|
||||||
std::cout << "inserting artist record" << std::endl;
|
std::cout << "inserting artist record" << std::endl;
|
||||||
|
|
||||||
@@ -203,8 +204,7 @@ void database::ArtistRepository::saveRecord(const model::Artist& artist)
|
|||||||
std::cout<< "inserted artist record" << std::endl;
|
std::cout<< "inserted artist record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::ArtistRepository::deleteArtist(const model::Artist& artist, type::ArtistFilter filter = type::ArtistFilter::id) {
|
void ArtistRepository::deleteArtist(const model::Artist& artist, type::ArtistFilter filter = type::ArtistFilter::id) {
|
||||||
// TODO: implement this
|
|
||||||
std::cout << "delete Artist record" << std::endl;
|
std::cout << "delete Artist record" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -240,7 +240,7 @@ void database::ArtistRepository::deleteArtist(const model::Artist& artist, type:
|
|||||||
std::cout << "deleted artist record" << std::endl;
|
std::cout << "deleted artist record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<model::Artist> database::ArtistRepository::parseRecords(MYSQL_STMT *stmt)
|
std::vector<model::Artist> ArtistRepository::parseRecords(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
|
|
||||||
@@ -291,7 +291,7 @@ std::vector<model::Artist> database::ArtistRepository::parseRecords(MYSQL_STMT *
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
model::Artist database::ArtistRepository::parseRecord(MYSQL_RES* results)
|
model::Artist ArtistRepository::parseRecord(MYSQL_RES* results)
|
||||||
{
|
{
|
||||||
std::cout << "parsing artist record" << std::endl;
|
std::cout << "parsing artist record" << std::endl;
|
||||||
model::Artist artist;
|
model::Artist artist;
|
||||||
@@ -315,7 +315,7 @@ model::Artist database::ArtistRepository::parseRecord(MYSQL_RES* results)
|
|||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Artist, int> database::ArtistRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
std::pair<model::Artist, int> ArtistRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing artist record with song count" << std::endl;
|
std::cout << "parsing artist record with song count" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -364,7 +364,7 @@ std::pair<model::Artist, int> database::ArtistRepository::parseRecordWithSongCou
|
|||||||
return std::make_pair(artist, songCount);
|
return std::make_pair(artist, songCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Artist database::ArtistRepository::parseRecord(MYSQL_STMT *stmt)
|
model::Artist ArtistRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing artist record" << std::endl;
|
std::cout << "parsing artist record" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -413,3 +413,4 @@ model::Artist database::ArtistRepository::parseRecord(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
return art;
|
return art;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,21 +6,22 @@
|
|||||||
|
|
||||||
#include "manager/DirectoryManager.h"
|
#include "manager/DirectoryManager.h"
|
||||||
|
|
||||||
database::BaseRepository::BaseRepository()
|
namespace database {
|
||||||
|
BaseRepository::BaseRepository()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
database::BaseRepository::BaseRepository(const std::string& path) : path(path)
|
BaseRepository::BaseRepository(const std::string& path) : path(path)
|
||||||
{
|
{
|
||||||
intitalizeDetails();
|
intitalizeDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
database::BaseRepository::BaseRepository(const model::BinaryPath& bConf)
|
BaseRepository::BaseRepository(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
initializeDetails(bConf);
|
initializeDetails(bConf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool database::BaseRepository::testConnection()
|
bool BaseRepository::testConnection()
|
||||||
{
|
{
|
||||||
auto conn = mysql_init(nullptr);
|
auto conn = mysql_init(nullptr);
|
||||||
if (!mysql_real_connect(conn, details.server.c_str(), details.username.c_str(),
|
if (!mysql_real_connect(conn, details.server.c_str(), details.username.c_str(),
|
||||||
@@ -36,7 +37,7 @@ bool database::BaseRepository::testConnection()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYSQL* database::BaseRepository::setupMysqlConnection()
|
MYSQL* BaseRepository::setupMysqlConnection()
|
||||||
{
|
{
|
||||||
MYSQL *conn = mysql_init(nullptr);
|
MYSQL *conn = mysql_init(nullptr);
|
||||||
|
|
||||||
@@ -48,7 +49,7 @@ MYSQL* database::BaseRepository::setupMysqlConnection()
|
|||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYSQL* database::BaseRepository::setupMysqlConnection(model::DatabaseConnection details)
|
MYSQL* BaseRepository::setupMysqlConnection(model::DatabaseConnection details)
|
||||||
{
|
{
|
||||||
MYSQL *connection = mysql_init(NULL);
|
MYSQL *connection = mysql_init(NULL);
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ MYSQL* database::BaseRepository::setupMysqlConnection(model::DatabaseConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MYSQL_RES* database::BaseRepository::performMysqlQuery(MYSQL *conn, const std::string& query)
|
MYSQL_RES* BaseRepository::performMysqlQuery(MYSQL *conn, const std::string& query)
|
||||||
{
|
{
|
||||||
// send the query to the database
|
// send the query to the database
|
||||||
if (mysql_query(conn, query.c_str()))
|
if (mysql_query(conn, query.c_str()))
|
||||||
@@ -74,7 +75,7 @@ MYSQL_RES* database::BaseRepository::performMysqlQuery(MYSQL *conn, const std::s
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void database::BaseRepository::intitalizeDetails()
|
void BaseRepository::intitalizeDetails()
|
||||||
{
|
{
|
||||||
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(path);
|
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(path);
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ void database::BaseRepository::intitalizeDetails()
|
|||||||
details.server = databaseConfig["server"].get<std::string>();
|
details.server = databaseConfig["server"].get<std::string>();
|
||||||
details.username = databaseConfig["username"].get<std::string>();
|
details.username = databaseConfig["username"].get<std::string>();
|
||||||
}
|
}
|
||||||
void database::BaseRepository::initializeDetails(const model::BinaryPath& bConf)
|
void BaseRepository::initializeDetails(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(bConf);
|
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(bConf);
|
||||||
|
|
||||||
@@ -94,3 +95,4 @@ void database::BaseRepository::initializeDetails(const model::BinaryPath& bConf)
|
|||||||
|
|
||||||
std::cout << "retrieved database details" << std::endl;
|
std::cout << "retrieved database details" << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
database::CoverArtRepository::CoverArtRepository(const std::string& path) : BaseRepository(path)
|
namespace database {
|
||||||
|
CoverArtRepository::CoverArtRepository(const std::string& path) : BaseRepository(path)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
database::CoverArtRepository::CoverArtRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
|
CoverArtRepository::CoverArtRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Cover> database::CoverArtRepository::retrieveRecords()
|
std::vector<model::Cover> CoverArtRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -30,7 +31,7 @@ std::vector<model::Cover> database::CoverArtRepository::retrieveRecords()
|
|||||||
return coverArts;
|
return coverArts;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Cover database::CoverArtRepository::retrieveRecord(model::Cover& cov, type::CoverFilter filter = type::CoverFilter::id)
|
model::Cover CoverArtRepository::retrieveRecord(model::Cover& cov, type::CoverFilter filter = type::CoverFilter::id)
|
||||||
{
|
{
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -80,7 +81,7 @@ model::Cover database::CoverArtRepository::retrieveRecord(model::Cover& cov, typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool database::CoverArtRepository::doesCoverArtExist(const model::Cover& cover, type::CoverFilter filter)
|
bool CoverArtRepository::doesCoverArtExist(const model::Cover& cover, type::CoverFilter filter)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -133,7 +134,7 @@ bool database::CoverArtRepository::doesCoverArtExist(const model::Cover& cover,
|
|||||||
|
|
||||||
|
|
||||||
// TODO: change to prepared statement
|
// TODO: change to prepared statement
|
||||||
void database::CoverArtRepository::deleteRecord(const model::Cover& cov)
|
void CoverArtRepository::deleteRecord(const model::Cover& cov)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
const std::string query("DELETE FROM CoverArt WHERE CoverArtId = " + std::to_string(cov.id));
|
const std::string query("DELETE FROM CoverArt WHERE CoverArtId = " + std::to_string(cov.id));
|
||||||
@@ -143,7 +144,7 @@ void database::CoverArtRepository::deleteRecord(const model::Cover& cov)
|
|||||||
mysql_close(conn);
|
mysql_close(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::CoverArtRepository::saveRecord(const model::Cover& cov)
|
void CoverArtRepository::saveRecord(const model::Cover& cov)
|
||||||
{
|
{
|
||||||
std::cout << "saving cover art record";
|
std::cout << "saving cover art record";
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -178,7 +179,7 @@ void database::CoverArtRepository::saveRecord(const model::Cover& cov)
|
|||||||
std::cout << "saved cover art record" << std::endl;
|
std::cout << "saved cover art record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::CoverArtRepository::updateRecord(const model::Cover& cover)
|
void CoverArtRepository::updateRecord(const model::Cover& cover)
|
||||||
{
|
{
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -222,7 +223,7 @@ void database::CoverArtRepository::updateRecord(const model::Cover& cover)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Cover> database::CoverArtRepository::parseRecords(MYSQL_STMT *stmt)
|
std::vector<model::Cover> CoverArtRepository::parseRecords(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
auto rowCount = mysql_stmt_num_rows(stmt);
|
auto rowCount = mysql_stmt_num_rows(stmt);
|
||||||
@@ -288,7 +289,7 @@ std::vector<model::Cover> database::CoverArtRepository::parseRecords(MYSQL_STMT
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
model::Cover database::CoverArtRepository::parseRecord(MYSQL_RES *results)
|
model::Cover CoverArtRepository::parseRecord(MYSQL_RES *results)
|
||||||
{
|
{
|
||||||
std::cout << "parsing record" << std::endl;
|
std::cout << "parsing record" << std::endl;
|
||||||
model::Cover cov;
|
model::Cover cov;
|
||||||
@@ -314,7 +315,7 @@ model::Cover database::CoverArtRepository::parseRecord(MYSQL_RES *results)
|
|||||||
return cov;
|
return cov;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Cover database::CoverArtRepository::parseRecord(MYSQL_STMT *stmt)
|
model::Cover CoverArtRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing cover art record" << std::endl;
|
std::cout << "parsing cover art record" << std::endl;
|
||||||
|
|
||||||
@@ -372,3 +373,4 @@ model::Cover database::CoverArtRepository::parseRecord(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
return cover;
|
return cover;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
database::GenreRepository::GenreRepository(const model::BinaryPath& bConf)
|
namespace database {
|
||||||
|
|
||||||
|
GenreRepository::GenreRepository(const model::BinaryPath& bConf)
|
||||||
: BaseRepository(bConf)
|
: BaseRepository(bConf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Genre> database::GenreRepository::retrieveRecords()
|
std::vector<model::Genre> GenreRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -27,7 +29,7 @@ std::vector<model::Genre> database::GenreRepository::retrieveRecords()
|
|||||||
return genres;
|
return genres;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Genre, int> database::GenreRepository::retrieveRecordWithSongCount(model::Genre& genre, type::GenreFilter filter = type::GenreFilter::id)
|
std::pair<model::Genre, int> GenreRepository::retrieveRecordWithSongCount(model::Genre& genre, type::GenreFilter filter = type::GenreFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving genre record with song count" << std::endl;
|
std::cout << "retrieving genre record with song count" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -71,7 +73,7 @@ std::pair<model::Genre, int> database::GenreRepository::retrieveRecordWithSongCo
|
|||||||
return gnrWSC;
|
return gnrWSC;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Genre database::GenreRepository::retrieveRecord(model::Genre& genre, type::GenreFilter filter)
|
model::Genre GenreRepository::retrieveRecord(model::Genre& genre, type::GenreFilter filter)
|
||||||
{
|
{
|
||||||
// TODO: change to prepared statement
|
// TODO: change to prepared statement
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ model::Genre database::GenreRepository::retrieveRecord(model::Genre& genre, type
|
|||||||
return genre;
|
return genre;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool database::GenreRepository::doesGenreExist(const model::Genre& genre, type::GenreFilter filter)
|
bool GenreRepository::doesGenreExist(const model::Genre& genre, type::GenreFilter filter)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -159,7 +161,7 @@ bool database::GenreRepository::doesGenreExist(const model::Genre& genre, type::
|
|||||||
return (rowCount > 0) ? true : false;
|
return (rowCount > 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::GenreRepository::saveRecord(const model::Genre& genre)
|
void GenreRepository::saveRecord(const model::Genre& genre)
|
||||||
{
|
{
|
||||||
std::cout << "inserting genre record" << std::endl;
|
std::cout << "inserting genre record" << std::endl;
|
||||||
|
|
||||||
@@ -188,7 +190,7 @@ void database::GenreRepository::saveRecord(const model::Genre& genre)
|
|||||||
std::cout << "inserted record" << std::endl;
|
std::cout << "inserted record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::GenreRepository::deleteRecord(const model::Genre& genre, type::GenreFilter filter = type::GenreFilter::id)
|
void GenreRepository::deleteRecord(const model::Genre& genre, type::GenreFilter filter = type::GenreFilter::id)
|
||||||
{
|
{
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
std::cout << "deleting genre record" << std::endl;
|
std::cout << "deleting genre record" << std::endl;
|
||||||
@@ -227,7 +229,7 @@ void database::GenreRepository::deleteRecord(const model::Genre& genre, type::Ge
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Genre> database::GenreRepository::parseRecords(MYSQL_STMT *stmt)
|
std::vector<model::Genre> GenreRepository::parseRecords(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
|
|
||||||
@@ -277,7 +279,7 @@ std::vector<model::Genre> database::GenreRepository::parseRecords(MYSQL_STMT *st
|
|||||||
return genres;
|
return genres;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Genre, int> database::GenreRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
std::pair<model::Genre, int> GenreRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing genre record with song count" << std::endl;
|
std::cout << "parsing genre record with song count" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -326,7 +328,7 @@ std::pair<model::Genre, int> database::GenreRepository::parseRecordWithSongCount
|
|||||||
return std::make_pair(genre, songCount);
|
return std::make_pair(genre, songCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Genre database::GenreRepository::parseRecord(MYSQL_RES* results)
|
model::Genre GenreRepository::parseRecord(MYSQL_RES* results)
|
||||||
{
|
{
|
||||||
std::cout << "parsing genre record" << std::endl;
|
std::cout << "parsing genre record" << std::endl;
|
||||||
model::Genre genre;
|
model::Genre genre;
|
||||||
@@ -349,7 +351,7 @@ model::Genre database::GenreRepository::parseRecord(MYSQL_RES* results)
|
|||||||
|
|
||||||
return genre;
|
return genre;
|
||||||
}
|
}
|
||||||
model::Genre database::GenreRepository::parseRecord(MYSQL_STMT *stmt)
|
model::Genre GenreRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
// TODO: implement this
|
// TODO: implement this
|
||||||
|
|
||||||
@@ -357,3 +359,4 @@ model::Genre database::GenreRepository::parseRecord(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
return genre;
|
return genre;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
+146
-380
@@ -7,14 +7,16 @@
|
|||||||
|
|
||||||
#include "type/SongFilter.h"
|
#include "type/SongFilter.h"
|
||||||
|
|
||||||
database::SongRepository::SongRepository(const std::string& path) : BaseRepository(path)
|
namespace database {
|
||||||
|
|
||||||
|
SongRepository::SongRepository(const std::string& path) : BaseRepository(path)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
database::SongRepository::SongRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
|
SongRepository::SongRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Song> database::SongRepository::retrieveRecords()
|
std::vector<model::Song> SongRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -32,18 +34,28 @@ std::vector<model::Song> database::SongRepository::retrieveRecords()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
model::Song database::SongRepository::retrieveRecord(model::Song& song, type::SongFilter filter)
|
model::Song SongRepository::retrieveRecord(model::Song& song, type::SongFilter filter)
|
||||||
{
|
{
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
|
|
||||||
MYSQL_BIND params[1];
|
auto valueFilterCount = 1;
|
||||||
|
switch (filter) {
|
||||||
|
case type::SongFilter::titleAndArtist:
|
||||||
|
valueFilterCount = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
MYSQL_BIND params[valueFilterCount];
|
||||||
memset(params, 0, sizeof(params));
|
memset(params, 0, sizeof(params));
|
||||||
|
|
||||||
qry << "SELECT * FROM Song WHERE ";
|
qry << "SELECT * FROM Song WHERE ";
|
||||||
|
|
||||||
auto titleLength = song.title.size();
|
auto titleLength = song.title.size();
|
||||||
|
auto artistLength = song.artist.size();
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case type::SongFilter::id:
|
case type::SongFilter::id:
|
||||||
qry << "SongId = ?";
|
qry << "SongId = ?";
|
||||||
@@ -61,6 +73,19 @@ model::Song database::SongRepository::retrieveRecord(model::Song& song, type::So
|
|||||||
params[0].length = &titleLength;
|
params[0].length = &titleLength;
|
||||||
params[0].is_null = 0;
|
params[0].is_null = 0;
|
||||||
break;
|
break;
|
||||||
|
case type::SongFilter::titleAndArtist:
|
||||||
|
qry << "Title = ? AND Artist = ?";
|
||||||
|
|
||||||
|
params[0].buffer_type = MYSQL_TYPE_STRING;
|
||||||
|
params[0].buffer = (char*)song.title.c_str();
|
||||||
|
params[0].length = &titleLength;
|
||||||
|
params[0].is_null = 0;
|
||||||
|
|
||||||
|
params[1].buffer_type = MYSQL_TYPE_STRING;
|
||||||
|
params[1].buffer = (char*)song.artist.c_str();
|
||||||
|
params[1].length = &artistLength;
|
||||||
|
params[1].is_null = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -84,19 +109,29 @@ model::Song database::SongRepository::retrieveRecord(model::Song& song, type::So
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool database::SongRepository::doesSongExist(const model::Song& song, type::SongFilter filter)
|
bool SongRepository::doesSongExist(const model::Song& song, type::SongFilter filter)
|
||||||
{
|
{
|
||||||
std::cout << "checking to see if song exists" << std::endl;
|
std::cout << "checking to see if song exists" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
|
auto valueFilterCount = 1;
|
||||||
|
switch (filter) {
|
||||||
|
case type::SongFilter::titleAndArtist:
|
||||||
|
valueFilterCount = 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
MYSQL_BIND params[1];
|
|
||||||
|
MYSQL_BIND params[valueFilterCount];
|
||||||
memset(params, 0, sizeof(params));
|
memset(params, 0, sizeof(params));
|
||||||
|
|
||||||
qry << "SELECT * FROM Song WHERE ";
|
qry << "SELECT * FROM Song WHERE ";
|
||||||
|
|
||||||
auto titleLength = song.title.size();
|
auto titleLength = song.title.size();
|
||||||
|
auto artistLength = song.artist.size();
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case type::SongFilter::id:
|
case type::SongFilter::id:
|
||||||
qry << "SongId = ?";
|
qry << "SongId = ?";
|
||||||
@@ -114,6 +149,19 @@ bool database::SongRepository::doesSongExist(const model::Song& song, type::Song
|
|||||||
params[0].length = &titleLength;
|
params[0].length = &titleLength;
|
||||||
params[0].is_null = 0;
|
params[0].is_null = 0;
|
||||||
break;
|
break;
|
||||||
|
case type::SongFilter::titleAndArtist:
|
||||||
|
qry << "Title = ? AND Artist = ?";
|
||||||
|
|
||||||
|
params[0].buffer_type = MYSQL_TYPE_STRING;
|
||||||
|
params[0].buffer = (char*)song.title.c_str();
|
||||||
|
params[0].length = &titleLength;
|
||||||
|
params[0].is_null = 0;
|
||||||
|
|
||||||
|
params[1].buffer_type = MYSQL_TYPE_STRING;
|
||||||
|
params[1].buffer = (char*)song.artist.c_str();
|
||||||
|
params[1].length = &artistLength;
|
||||||
|
params[1].is_null = 0;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -137,7 +185,7 @@ bool database::SongRepository::doesSongExist(const model::Song& song, type::Song
|
|||||||
return (rowCount > 0) ? true : false;
|
return (rowCount > 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool database::SongRepository::deleteRecord(const model::Song& song)
|
bool SongRepository::deleteRecord(const model::Song& song)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto status = 0;
|
auto status = 0;
|
||||||
@@ -151,7 +199,7 @@ bool database::SongRepository::deleteRecord(const model::Song& song)
|
|||||||
return (result == 0) ? true : false;
|
return (result == 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::SongRepository::saveRecord(const model::Song& song)
|
void SongRepository::saveRecord(const model::Song& song)
|
||||||
{
|
{
|
||||||
std::cout << "beginning to insert song record" << std::endl;
|
std::cout << "beginning to insert song record" << std::endl;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -252,7 +300,7 @@ void database::SongRepository::saveRecord(const model::Song& song)
|
|||||||
std::cout << "done inserting song record" << std::endl;
|
std::cout << "done inserting song record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::SongRepository::updateRecord(const model::Song& song)
|
void SongRepository::updateRecord(const model::Song& song)
|
||||||
{
|
{
|
||||||
std::cout << "executing query to update record" << std::endl;
|
std::cout << "executing query to update record" << std::endl;
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
@@ -344,116 +392,84 @@ void database::SongRepository::updateRecord(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: delete this, not being used
|
std::shared_ptr<MYSQL_BIND> SongRepository::valueBind(model::Song& song,
|
||||||
std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_RES* results)
|
std::tuple<char*, char*, char*, char*, char*>& metadata)
|
||||||
{
|
{
|
||||||
auto fieldNum = mysql_num_fields(results);
|
constexpr auto strLen = 1024;
|
||||||
auto numRows = mysql_num_rows(results);
|
constexpr auto valueCount = 15;
|
||||||
|
std::shared_ptr<MYSQL_BIND> values((MYSQL_BIND*) std::calloc(valueCount, sizeof(MYSQL_BIND)));
|
||||||
|
unsigned long len[valueCount];
|
||||||
|
my_bool nullRes[valueCount];
|
||||||
|
|
||||||
std::vector<model::Song> songs;
|
|
||||||
songs.reserve(numRows);
|
|
||||||
|
|
||||||
for (MYSQL_ROW row = nullptr; (row = mysql_fetch_row(results)) != nullptr; ) {
|
values.get()[0].buffer_type = MYSQL_TYPE_LONG;
|
||||||
model::Song song;
|
values.get()[0].buffer = (char*)&song.id;
|
||||||
|
|
||||||
for (auto i = 0; i != fieldNum; ++i) {
|
values.get()[1].buffer_type = MYSQL_TYPE_STRING;
|
||||||
/**
|
values.get()[1].buffer = (char*)std::get<0>(metadata);
|
||||||
auto field = mysql_fetch_field(results);
|
values.get()[1].buffer_length = strLen;
|
||||||
if (field->name == NULL) {
|
|
||||||
std::cout << "null field" << std::endl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
std::string field;
|
|
||||||
if ((i + 0) == fieldNum) {
|
|
||||||
std::cout << "goodbye" << std::endl;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
std::cout << "still good" << std::endl;
|
|
||||||
field.assign(mysql_fetch_field(results)->name);
|
|
||||||
}
|
|
||||||
//const std::string field(row[i].field);
|
|
||||||
std::cout << field << std::endl;
|
|
||||||
|
|
||||||
if (field.compare("SongId") == 0) {
|
values.get()[2].buffer_type = MYSQL_TYPE_STRING;
|
||||||
song.id = std::stoi(row[i]);
|
values.get()[2].buffer = (char*)std::get<1>(metadata);
|
||||||
}
|
values.get()[2].buffer_length = strLen;
|
||||||
if (field.compare("Title") == 0) {
|
|
||||||
song.title = row[i];
|
values.get()[3].buffer_type = MYSQL_TYPE_STRING;
|
||||||
}
|
values.get()[3].buffer = (char*)std::get<2>(metadata);
|
||||||
if (field.compare("Artist") == 0) {
|
values.get()[3].buffer_length = strLen;
|
||||||
song.artist = row[i];
|
|
||||||
}
|
values.get()[4].buffer_type = MYSQL_TYPE_STRING;
|
||||||
if (field.compare("Album") == 0) {
|
values.get()[4].buffer = (char*)std::get<3>(metadata);
|
||||||
song.album = row[i];
|
values.get()[4].buffer_length = strLen;
|
||||||
}
|
|
||||||
if (field.compare("Genre") == 0) {
|
values.get()[5].buffer_type = MYSQL_TYPE_LONG;
|
||||||
song.genre = row[i];
|
values.get()[5].buffer = (char*)&song.year;
|
||||||
}
|
|
||||||
if (field.compare("Year") == 0) {
|
values.get()[6].buffer_type = MYSQL_TYPE_LONG;
|
||||||
song.year = std::stoi(row[i]);
|
values.get()[6].buffer = (char*)&song.duration;
|
||||||
}
|
|
||||||
if (field.compare("Duration") == 0) {
|
values.get()[7].buffer_type = MYSQL_TYPE_LONG;
|
||||||
song.duration = std::stoi(row[i]);
|
values.get()[7].buffer = (char*)&song.track;
|
||||||
}
|
|
||||||
if (field.compare("Track") == 0) {
|
values.get()[8].buffer_type = MYSQL_TYPE_LONG;
|
||||||
song.track = std::stoi(row[i]);
|
values.get()[8].buffer = (char*)&song.disc;
|
||||||
}
|
|
||||||
if (field.compare("Disc") == 0) {
|
values.get()[9].buffer_type = MYSQL_TYPE_STRING;
|
||||||
song.disc = std::stoi(row[i]);
|
values.get()[9].buffer = (char*)std::get<4>(metadata);
|
||||||
}
|
values.get()[9].buffer_length = strLen;
|
||||||
if (field.compare("SongPath") == 0) {
|
|
||||||
song.songPath = row[i];
|
values.get()[10].buffer_type = MYSQL_TYPE_LONG;
|
||||||
}
|
values.get()[10].buffer = (char*)&song.coverArtId;
|
||||||
if (field.compare("CoverArtId") == 0) {
|
|
||||||
song.coverArtId = std::stoi(row[i]);
|
values.get()[11].buffer_type = MYSQL_TYPE_LONG;
|
||||||
}
|
values.get()[11].buffer = (char*)&song.artistId;
|
||||||
*/
|
|
||||||
switch (i) {
|
values.get()[12].buffer_type = MYSQL_TYPE_LONG;
|
||||||
case 0:
|
values.get()[12].buffer = (char*)&song.albumId;;
|
||||||
song.id = std::stoi(row[i]);
|
|
||||||
break;
|
values.get()[13].buffer_type = MYSQL_TYPE_LONG;
|
||||||
case 1:
|
values.get()[13].buffer = (char*)&song.genreId;
|
||||||
song.title = row[i];
|
|
||||||
break;
|
values.get()[14].buffer_type = MYSQL_TYPE_LONG;
|
||||||
case 2:
|
values.get()[14].buffer = (char*)&song.yearId;
|
||||||
song.artist= row[i];
|
|
||||||
break;
|
return values;
|
||||||
case 3:
|
|
||||||
song.album = row[i];
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
song.genre = row[i];
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
song.year = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
song.duration = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
song.track = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
song.disc = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
song.songPath = row[i];
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
song.coverArtId = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
songs.push_back(song);
|
|
||||||
|
std::tuple<char*, char*, char*, char*, char*> SongRepository::metadataBuffer()
|
||||||
|
{
|
||||||
|
constexpr auto length = 1024;
|
||||||
|
char title[length];
|
||||||
|
char artist[length];
|
||||||
|
char album[length];
|
||||||
|
char genre[length];
|
||||||
|
char path[length];
|
||||||
|
|
||||||
|
return std::make_tuple(title, artist, album, genre, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return songs;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_STMT *stmt)
|
std::vector<model::Song> SongRepository::parseRecords(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
::mysql_stmt_store_result(stmt);
|
::mysql_stmt_store_result(stmt);
|
||||||
auto c = ::mysql_stmt_num_rows(stmt);
|
auto c = ::mysql_stmt_num_rows(stmt);
|
||||||
@@ -463,110 +479,14 @@ std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_STMT *stmt
|
|||||||
|
|
||||||
auto status = 0;
|
auto status = 0;
|
||||||
auto time = 0;
|
auto time = 0;
|
||||||
auto valAmt = 15;
|
|
||||||
unsigned long len[valAmt];
|
|
||||||
my_bool nullRes[valAmt];
|
|
||||||
|
|
||||||
while (status == 0) {
|
while (status == 0) {
|
||||||
std::cout << time++ << " time" << std::endl;
|
|
||||||
std::cout << "field count " << ::mysql_stmt_field_count(stmt) << std::endl;
|
|
||||||
|
|
||||||
if (::mysql_stmt_field_count(stmt) > 0) {
|
if (::mysql_stmt_field_count(stmt) > 0) {
|
||||||
|
|
||||||
model::Song song;
|
model::Song song;
|
||||||
auto res = ::mysql_stmt_result_metadata(stmt);
|
auto metaBuff = metadataBuffer();
|
||||||
auto fields = ::mysql_fetch_fields(res);
|
auto val = valueBind(song, metaBuff);
|
||||||
auto strLen = 1024;
|
|
||||||
MYSQL_BIND val[valAmt];
|
|
||||||
memset(val, 0, sizeof(val));
|
|
||||||
|
|
||||||
char title[strLen];
|
status = ::mysql_stmt_bind_result(stmt, val.get());
|
||||||
char album[strLen];
|
|
||||||
char artist[strLen];
|
|
||||||
char genre[strLen];
|
|
||||||
char path[strLen];
|
|
||||||
|
|
||||||
val[0].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[0].buffer = (char*)&song.id;
|
|
||||||
val[0].length = &len[0];
|
|
||||||
val[0].is_null = &nullRes[0];
|
|
||||||
|
|
||||||
val[1].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[1].buffer = (char*)title;
|
|
||||||
val[1].buffer_length = strLen;
|
|
||||||
val[1].length = &len[1];
|
|
||||||
val[1].is_null = &nullRes[1];
|
|
||||||
|
|
||||||
val[2].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[2].buffer = (char*)artist;
|
|
||||||
val[2].buffer_length = strLen;
|
|
||||||
val[2].length = &len[2];
|
|
||||||
val[2].is_null = &nullRes[2];
|
|
||||||
|
|
||||||
val[3].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[3].buffer = (char*)album;
|
|
||||||
val[3].buffer_length = strLen;
|
|
||||||
val[3].length = &len[3];
|
|
||||||
val[3].is_null = &nullRes[3];
|
|
||||||
|
|
||||||
val[4].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[4].buffer = (char*)genre;
|
|
||||||
val[4].buffer_length = strLen;
|
|
||||||
val[4].length = &len[4];
|
|
||||||
val[4].is_null = &nullRes[4];
|
|
||||||
|
|
||||||
val[5].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[5].buffer = (char*)&song.year;
|
|
||||||
val[5].length = &len[5];
|
|
||||||
val[5].is_null = &nullRes[5];
|
|
||||||
|
|
||||||
val[6].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[6].buffer = (char*)&song.duration;
|
|
||||||
val[6].length = &len[6];
|
|
||||||
val[6].is_null = &nullRes[6];
|
|
||||||
|
|
||||||
val[7].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[7].buffer = (char*)&song.track;
|
|
||||||
val[7].length = &len[7];
|
|
||||||
val[7].is_null = &nullRes[7];
|
|
||||||
|
|
||||||
val[8].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[8].buffer = (char*)&song.disc;
|
|
||||||
val[8].length = &len[8];
|
|
||||||
val[8].is_null = &nullRes[8];
|
|
||||||
|
|
||||||
val[9].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[9].buffer = (char*)path;
|
|
||||||
val[9].buffer_length = strLen;
|
|
||||||
val[9].length = &len[9];
|
|
||||||
val[9].is_null = &nullRes[9];
|
|
||||||
|
|
||||||
val[10].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[10].buffer = (char*)&song.coverArtId;
|
|
||||||
val[10].length = &len[10];
|
|
||||||
val[10].is_null = &nullRes[10];
|
|
||||||
|
|
||||||
val[11].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[11].buffer = (char*)&song.artistId;
|
|
||||||
val[11].length = &len[11];
|
|
||||||
val[11].is_null = &nullRes[11];
|
|
||||||
|
|
||||||
val[12].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[12].buffer = (char*)&song.albumId;;
|
|
||||||
val[12].length = &len[12];
|
|
||||||
val[12].is_null = &nullRes[12];
|
|
||||||
|
|
||||||
val[13].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[13].buffer = (char*)&song.genreId;
|
|
||||||
val[13].length = &len[13];
|
|
||||||
val[13].is_null = &nullRes[13];
|
|
||||||
|
|
||||||
val[14].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[14].buffer = (char*)&song.yearId;
|
|
||||||
val[14].length = &len[14];
|
|
||||||
val[14].is_null = &nullRes[14];
|
|
||||||
|
|
||||||
status = ::mysql_stmt_bind_result(stmt, val);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
std::cout << "fetching statement result" << std::endl;
|
std::cout << "fetching statement result" << std::endl;
|
||||||
@@ -575,11 +495,12 @@ std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_STMT *stmt
|
|||||||
if (status == 1 || status == MYSQL_NO_DATA) {
|
if (status == 1 || status == MYSQL_NO_DATA) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
song.title = title;
|
|
||||||
song.album = album;
|
song.title = std::get<0>(metaBuff);
|
||||||
song.artist = artist;
|
song.artist = std::get<1>(metaBuff);
|
||||||
song.genre = genre;
|
song.album = std::get<2>(metaBuff);
|
||||||
song.songPath = path;
|
song.genre = std::get<3>(metaBuff);
|
||||||
|
song.songPath = std::get<4>(metaBuff);
|
||||||
|
|
||||||
songs.push_back(song);
|
songs.push_back(song);
|
||||||
}
|
}
|
||||||
@@ -592,177 +513,22 @@ std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_STMT *stmt
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: delete this, not being used anymore
|
model::Song SongRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
model::Song database::SongRepository::parseRecord(MYSQL_RES* results)
|
|
||||||
{
|
{
|
||||||
model::Song song;
|
model::Song song;
|
||||||
|
auto metaBuff = metadataBuffer();
|
||||||
|
auto bindedValues = valueBind(song, metaBuff);
|
||||||
|
auto status = mysql_stmt_bind_result(stmt, bindedValues.get());
|
||||||
|
status = mysql_stmt_fetch(stmt);
|
||||||
|
|
||||||
auto fieldNum = mysql_num_fields(results);
|
song.title = std::get<0>(metaBuff);
|
||||||
auto row = mysql_fetch_row(results);
|
song.artist = std::get<1>(metaBuff);
|
||||||
|
song.album = std::get<2>(metaBuff);
|
||||||
for (auto i = 0; i != fieldNum; ++i) {
|
song.genre = std::get<3>(metaBuff);
|
||||||
const std::string field(mysql_fetch_field(results)->name);
|
song.songPath = std::get<4>(metaBuff);
|
||||||
|
|
||||||
switch (i) {
|
|
||||||
case 0:
|
|
||||||
song.id = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
song.title = row[i];
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
song.artist= row[i];
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
song.album = row[i];
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
song.genre = row[i];
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
song.year = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
song.duration = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
song.track = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
song.disc = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
song.songPath = row[i];
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
song.coverArtId = std::stoi(row[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << "done parsing record" << std::endl;
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
|
|
||||||
model::Song database::SongRepository::parseRecord(MYSQL_STMT *stmt)
|
|
||||||
{
|
|
||||||
model::Song song;
|
|
||||||
auto status = 0;
|
|
||||||
auto time = 0;
|
|
||||||
auto valAmt = 15;
|
|
||||||
unsigned long len[valAmt];
|
|
||||||
my_bool nullRes[valAmt];
|
|
||||||
|
|
||||||
while (status == 0) {
|
|
||||||
if (::mysql_stmt_field_count(stmt) > 0) {
|
|
||||||
auto res = ::mysql_stmt_result_metadata(stmt);
|
|
||||||
auto fields = ::mysql_fetch_fields(res);
|
|
||||||
auto strLen = 1024;
|
|
||||||
MYSQL_BIND val[valAmt];
|
|
||||||
memset(val, 0, sizeof(val));
|
|
||||||
|
|
||||||
char title[strLen];
|
|
||||||
char album[strLen];
|
|
||||||
char artist[strLen];
|
|
||||||
char genre[strLen];
|
|
||||||
char path[strLen];
|
|
||||||
|
|
||||||
val[0].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[0].buffer = (char*)&song.id;
|
|
||||||
val[0].length = &len[0];
|
|
||||||
val[0].is_null = &nullRes[0];
|
|
||||||
|
|
||||||
val[1].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[1].buffer = (char*)title;
|
|
||||||
val[1].buffer_length = strLen;
|
|
||||||
val[1].length = &len[1];
|
|
||||||
val[1].is_null = &nullRes[1];
|
|
||||||
|
|
||||||
val[2].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[2].buffer = (char*)artist;
|
|
||||||
val[2].buffer_length = strLen;
|
|
||||||
val[2].length = &len[2];
|
|
||||||
val[2].is_null = &nullRes[2];
|
|
||||||
|
|
||||||
val[3].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[3].buffer = (char*)album;
|
|
||||||
val[3].buffer_length = strLen;
|
|
||||||
val[3].length = &len[3];
|
|
||||||
val[3].is_null = &nullRes[3];
|
|
||||||
|
|
||||||
val[4].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[4].buffer = (char*)genre;
|
|
||||||
val[4].buffer_length = strLen;
|
|
||||||
val[4].length = &len[4];
|
|
||||||
val[4].is_null = &nullRes[4];
|
|
||||||
|
|
||||||
val[5].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[5].buffer = (char*)&song.year;
|
|
||||||
val[5].length = &len[5];
|
|
||||||
val[5].is_null = &nullRes[5];
|
|
||||||
|
|
||||||
val[6].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[6].buffer = (char*)&song.duration;
|
|
||||||
val[6].length = &len[6];
|
|
||||||
val[6].is_null = &nullRes[6];
|
|
||||||
|
|
||||||
val[7].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[7].buffer = (char*)&song.track;
|
|
||||||
val[7].length = &len[7];
|
|
||||||
val[7].is_null = &nullRes[7];
|
|
||||||
|
|
||||||
val[8].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[8].buffer = (char*)&song.disc;
|
|
||||||
val[8].length = &len[8];
|
|
||||||
val[8].is_null = &nullRes[8];
|
|
||||||
|
|
||||||
val[9].buffer_type = MYSQL_TYPE_STRING;
|
|
||||||
val[9].buffer = (char*)path;
|
|
||||||
val[9].buffer_length = strLen;
|
|
||||||
val[9].length = &len[9];
|
|
||||||
val[9].is_null = &nullRes[9];
|
|
||||||
|
|
||||||
val[10].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[10].buffer = (char*)&song.coverArtId;
|
|
||||||
val[10].length = &len[10];
|
|
||||||
val[10].is_null = &nullRes[10];
|
|
||||||
|
|
||||||
val[11].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[11].buffer = (char*)&song.artistId;
|
|
||||||
val[11].length = &len[11];
|
|
||||||
val[11].is_null = &nullRes[11];
|
|
||||||
|
|
||||||
val[12].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[12].buffer = (char*)&song.albumId;;
|
|
||||||
val[12].length = &len[12];
|
|
||||||
val[12].is_null = &nullRes[12];
|
|
||||||
|
|
||||||
val[13].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[13].buffer = (char*)&song.genreId;
|
|
||||||
val[13].length = &len[13];
|
|
||||||
val[13].is_null = &nullRes[13];
|
|
||||||
|
|
||||||
val[14].buffer_type = MYSQL_TYPE_LONG;
|
|
||||||
val[14].buffer = (char*)&song.yearId;
|
|
||||||
val[14].length = &len[14];
|
|
||||||
val[14].is_null = &nullRes[14];
|
|
||||||
|
|
||||||
status = ::mysql_stmt_bind_result(stmt, val);
|
|
||||||
::mysql_stmt_store_result(stmt);
|
|
||||||
|
|
||||||
status = ::mysql_stmt_fetch(stmt);
|
|
||||||
|
|
||||||
song.title = title;
|
|
||||||
song.album = album;
|
|
||||||
song.artist = artist;
|
|
||||||
song.genre = genre;
|
|
||||||
song.songPath = path;
|
|
||||||
|
|
||||||
}
|
|
||||||
status = ::mysql_stmt_next_result(stmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "done parsing record" << std::endl;
|
std::cout << "done parsing record" << std::endl;
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ model::User UserRepository::retrieveUserRecord(model::User& user,
|
|||||||
auto userLength = user.username.size();
|
auto userLength = user.username.size();
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case type::UserFilter::id:
|
case type::UserFilter::id:
|
||||||
|
qry << "UserId = ?";
|
||||||
|
|
||||||
|
params[0].buffer_type = MYSQL_TYPE_LONG;
|
||||||
|
params[0].buffer = (char*)&user.id;
|
||||||
|
params[0].length = nullptr;
|
||||||
|
params[0].is_null = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case type::UserFilter::username:
|
case type::UserFilter::username:
|
||||||
qry << "Username = ?";
|
qry << "Username = ?";
|
||||||
|
|||||||
@@ -6,13 +6,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace database {
|
||||||
database::YearRepository::YearRepository(const model::BinaryPath& bConf)
|
YearRepository::YearRepository(const model::BinaryPath& bConf) : BaseRepository(bConf) { }
|
||||||
: BaseRepository(bConf)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<model::Year> database::YearRepository::retrieveRecords()
|
std::vector<model::Year> YearRepository::retrieveRecords()
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -29,7 +27,7 @@ std::vector<model::Year> database::YearRepository::retrieveRecords()
|
|||||||
return yearRecs;
|
return yearRecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Year, int> database::YearRepository::retrieveRecordWithSongCount(model::Year& year, type::YearFilter filter = type::YearFilter::id)
|
std::pair<model::Year, int> YearRepository::retrieveRecordWithSongCount(model::Year& year, type::YearFilter filter = type::YearFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving year record with song count" << std::endl;
|
std::cout << "retrieving year record with song count" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -73,7 +71,7 @@ std::pair<model::Year, int> database::YearRepository::retrieveRecordWithSongCoun
|
|||||||
return yearWSC;
|
return yearWSC;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Year database::YearRepository::retrieveRecord(model::Year& year, type::YearFilter filter)
|
model::Year YearRepository::retrieveRecord(model::Year& year, type::YearFilter filter)
|
||||||
{
|
{
|
||||||
// TODO: switch to prepared statements
|
// TODO: switch to prepared statements
|
||||||
std::cout << "retrieving year record" << std::endl;
|
std::cout << "retrieving year record" << std::endl;
|
||||||
@@ -106,7 +104,7 @@ model::Year database::YearRepository::retrieveRecord(model::Year& year, type::Ye
|
|||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool database::YearRepository::doesYearExist(const model::Year& year, type::YearFilter filter)
|
bool YearRepository::doesYearExist(const model::Year& year, type::YearFilter filter)
|
||||||
{
|
{
|
||||||
auto conn = setupMysqlConnection();
|
auto conn = setupMysqlConnection();
|
||||||
auto stmt = mysql_stmt_init(conn);
|
auto stmt = mysql_stmt_init(conn);
|
||||||
@@ -156,7 +154,7 @@ bool database::YearRepository::doesYearExist(const model::Year& year, type::Year
|
|||||||
return (rowCount > 0) ? true : false;
|
return (rowCount > 0) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::YearRepository::saveRecord(const model::Year& year)
|
void YearRepository::saveRecord(const model::Year& year)
|
||||||
{
|
{
|
||||||
std::cout << "saving year record" << std::endl;
|
std::cout << "saving year record" << std::endl;
|
||||||
|
|
||||||
@@ -184,7 +182,7 @@ void database::YearRepository::saveRecord(const model::Year& year)
|
|||||||
std::cout << "saved record" << std::endl;
|
std::cout << "saved record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::YearRepository::deleteYear(const model::Year& year, type::YearFilter filter = type::YearFilter::id)
|
void YearRepository::deleteYear(const model::Year& year, type::YearFilter filter = type::YearFilter::id)
|
||||||
{
|
{
|
||||||
std::cout << "deleting year record" << std::endl;
|
std::cout << "deleting year record" << std::endl;
|
||||||
std::stringstream qry;
|
std::stringstream qry;
|
||||||
@@ -221,7 +219,7 @@ void database::YearRepository::deleteYear(const model::Year& year, type::YearFil
|
|||||||
std::cout << "deleted year record" << std::endl;
|
std::cout << "deleted year record" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<model::Year> database::YearRepository::parseRecords(MYSQL_STMT *stmt)
|
std::vector<model::Year> YearRepository::parseRecords(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
|
|
||||||
@@ -265,7 +263,7 @@ std::vector<model::Year> database::YearRepository::parseRecords(MYSQL_STMT *stmt
|
|||||||
return yearRecs;
|
return yearRecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<model::Year, int> database::YearRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
std::pair<model::Year, int> YearRepository::parseRecordWithSongCount(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
std::cout << "parsing year record" << std::endl;
|
std::cout << "parsing year record" << std::endl;
|
||||||
mysql_stmt_store_result(stmt);
|
mysql_stmt_store_result(stmt);
|
||||||
@@ -308,7 +306,7 @@ std::pair<model::Year, int> database::YearRepository::parseRecordWithSongCount(M
|
|||||||
return std::make_pair(year, songCount);
|
return std::make_pair(year, songCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Year database::YearRepository::parseRecord(MYSQL_RES *results)
|
model::Year YearRepository::parseRecord(MYSQL_RES *results)
|
||||||
{
|
{
|
||||||
std::cout << "parsing year record" << std::endl;
|
std::cout << "parsing year record" << std::endl;
|
||||||
model::Year year;
|
model::Year year;
|
||||||
@@ -331,7 +329,7 @@ model::Year database::YearRepository::parseRecord(MYSQL_RES *results)
|
|||||||
|
|
||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
model::Year database::YearRepository::parseRecord(MYSQL_STMT *stmt)
|
model::Year YearRepository::parseRecord(MYSQL_STMT *stmt)
|
||||||
{
|
{
|
||||||
// TODO: imeplement this
|
// TODO: imeplement this
|
||||||
// I really thought that I had already done this
|
// I really thought that I had already done this
|
||||||
@@ -340,3 +338,4 @@ model::Year database::YearRepository::parseRecord(MYSQL_STMT *stmt)
|
|||||||
|
|
||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "dto/conversion/DtoConversions.h"
|
#include "dto/conversion/DtoConversions.h"
|
||||||
|
|
||||||
namespace dto { namespace conversion {
|
namespace dto { namespace conversion {
|
||||||
dto::LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user,
|
LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user,
|
||||||
const model::Token& token) {
|
const model::Token& token) {
|
||||||
auto logRes = dto::LoginResultDto::createShared();
|
auto logRes = dto::LoginResultDto::createShared();
|
||||||
logRes->username = user.username.c_str();
|
logRes->username = user.username.c_str();
|
||||||
|
|||||||
@@ -6,12 +6,11 @@
|
|||||||
#include "model/Models.h"
|
#include "model/Models.h"
|
||||||
#include "type/AlbumFilter.h"
|
#include "type/AlbumFilter.h"
|
||||||
|
|
||||||
manager::AlbumManager::AlbumManager(const model::BinaryPath& bConf)
|
namespace manager {
|
||||||
: m_bConf(bConf)
|
AlbumManager::AlbumManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
model::Album manager::AlbumManager::retrieveAlbum(model::Album& album)
|
model::Album AlbumManager::retrieveAlbum(model::Album& album)
|
||||||
{
|
{
|
||||||
database::AlbumRepository albRepo(m_bConf);
|
database::AlbumRepository albRepo(m_bConf);
|
||||||
album = std::move(albRepo.retrieveRecord(album, type::AlbumFilter::title));
|
album = std::move(albRepo.retrieveRecord(album, type::AlbumFilter::title));
|
||||||
@@ -19,7 +18,7 @@ model::Album manager::AlbumManager::retrieveAlbum(model::Album& album)
|
|||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Album manager::AlbumManager::saveAlbum(const model::Song& song)
|
model::Album AlbumManager::saveAlbum(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Album album;
|
model::Album album;
|
||||||
album.title = song.album;
|
album.title = song.album;
|
||||||
@@ -37,7 +36,7 @@ model::Album manager::AlbumManager::saveAlbum(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::AlbumManager::deleteAlbum(const model::Song& song)
|
void AlbumManager::deleteAlbum(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Album album(song);
|
model::Album album(song);
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ void manager::AlbumManager::deleteAlbum(const model::Song& song)
|
|||||||
albRepo.deleteAlbum(album, type::AlbumFilter::id);
|
albRepo.deleteAlbum(album, type::AlbumFilter::id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::AlbumManager::updateAlbum(model::Song& updatedSong,
|
void AlbumManager::updateAlbum(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
model::Album album;
|
model::Album album;
|
||||||
@@ -72,10 +71,11 @@ void manager::AlbumManager::updateAlbum(model::Song& updatedSong,
|
|||||||
updatedSong.albumId = album.id;
|
updatedSong.albumId = album.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::AlbumManager::printAlbum(const model::Album& album)
|
void AlbumManager::printAlbum(const model::Album& album)
|
||||||
{
|
{
|
||||||
std::cout << "\nalbum record" << std::endl;
|
std::cout << "\nalbum record" << std::endl;
|
||||||
std::cout << "id: " << album.id << std::endl;
|
std::cout << "id: " << album.id << std::endl;
|
||||||
std::cout << "title: " << album.title << std::endl;
|
std::cout << "title: " << album.title << std::endl;
|
||||||
std::cout << "year: " << album.year << std::endl;
|
std::cout << "year: " << album.year << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
#include "database/ArtistRepository.h"
|
#include "database/ArtistRepository.h"
|
||||||
#include "type/ArtistFilter.h"
|
#include "type/ArtistFilter.h"
|
||||||
|
|
||||||
manager::ArtistManager::ArtistManager(const model::BinaryPath& bConf)
|
namespace manager {
|
||||||
: m_bConf(bConf)
|
|
||||||
{ }
|
ArtistManager::ArtistManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||||
|
|
||||||
|
|
||||||
model::Artist manager::ArtistManager::retrieveArtist(model::Artist& artist)
|
model::Artist ArtistManager::retrieveArtist(model::Artist& artist)
|
||||||
{
|
{
|
||||||
std::cout << "retrieving artist record" << std::endl;
|
std::cout << "retrieving artist record" << std::endl;
|
||||||
database::ArtistRepository artRepo(m_bConf);
|
database::ArtistRepository artRepo(m_bConf);
|
||||||
@@ -21,7 +21,7 @@ model::Artist manager::ArtistManager::retrieveArtist(model::Artist& artist)
|
|||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Artist manager::ArtistManager::saveArtist(const model::Song& song)
|
model::Artist ArtistManager::saveArtist(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Artist artist;
|
model::Artist artist;
|
||||||
artist.artist = song.artist;
|
artist.artist = song.artist;
|
||||||
@@ -37,7 +37,7 @@ model::Artist manager::ArtistManager::saveArtist(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::ArtistManager::deleteArtist(const model::Song& song)
|
void ArtistManager::deleteArtist(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Artist artist(song);
|
model::Artist artist(song);
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ void manager::ArtistManager::deleteArtist(const model::Song& song)
|
|||||||
artRepo.deleteArtist(artist, type::ArtistFilter::id);
|
artRepo.deleteArtist(artist, type::ArtistFilter::id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::ArtistManager::updateArtist(model::Song& updatedSong,
|
void ArtistManager::updateArtist(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
model::Artist artist;
|
model::Artist artist;
|
||||||
@@ -72,9 +72,10 @@ void manager::ArtistManager::updateArtist(model::Song& updatedSong,
|
|||||||
updatedSong.artistId = artist.id;
|
updatedSong.artistId = artist.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::ArtistManager::printArtist(const model::Artist& artist)
|
void ArtistManager::printArtist(const model::Artist& artist)
|
||||||
{
|
{
|
||||||
std::cout << "\nartist record" << std::endl;
|
std::cout << "\nartist record" << std::endl;
|
||||||
std::cout << "id: " << artist.id << std::endl;
|
std::cout << "id: " << artist.id << std::endl;
|
||||||
std::cout << "artist: " << artist.artist << std::endl;
|
std::cout << "artist: " << artist.artist << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,17 +11,14 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
manager::CoverArtManager::CoverArtManager(const std::string& configPath) : path(configPath)
|
namespace manager {
|
||||||
{ }
|
CoverArtManager::CoverArtManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||||
|
|
||||||
manager::CoverArtManager::CoverArtManager(const model::BinaryPath& bConf) : m_bConf(bConf)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
model::Cover manager::CoverArtManager::saveCover(const model::Song& song)
|
model::Cover CoverArtManager::saveCover(const model::Song& song)
|
||||||
{
|
{
|
||||||
auto pathConfigContent = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto pathConfigContent = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
auto stockCoverPath = manager::DirectoryManager::configPath(m_bConf);
|
auto stockCoverPath = DirectoryManager::configPath(m_bConf);
|
||||||
stockCoverPath.append("/CoverArt.png");
|
stockCoverPath.append("/CoverArt.png");
|
||||||
|
|
||||||
utility::MetadataRetriever meta;
|
utility::MetadataRetriever meta;
|
||||||
@@ -51,12 +48,12 @@ model::Cover manager::CoverArtManager::saveCover(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::pair<bool, std::string> manager::CoverArtManager::defaultCover(
|
std::pair<bool, std::string> CoverArtManager::defaultCover(
|
||||||
const model::Cover& cover) {
|
const model::Cover& cover) {
|
||||||
|
|
||||||
auto paths = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto paths = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
const auto coverArtPath =
|
const auto coverArtPath =
|
||||||
paths[manager::DirectoryManager::retrievePathType(
|
paths[DirectoryManager::retrievePathType(
|
||||||
type::PathType::coverArt)].get<std::string>();
|
type::PathType::coverArt)].get<std::string>();
|
||||||
|
|
||||||
auto stockCoverArtPath = coverArtPath;
|
auto stockCoverArtPath = coverArtPath;
|
||||||
@@ -70,7 +67,7 @@ std::pair<bool, std::string> manager::CoverArtManager::defaultCover(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::CoverArtManager::deleteCover(const model::Song& song)
|
void CoverArtManager::deleteCover(const model::Song& song)
|
||||||
{
|
{
|
||||||
database::CoverArtRepository covRepo(m_bConf);
|
database::CoverArtRepository covRepo(m_bConf);
|
||||||
|
|
||||||
@@ -89,10 +86,10 @@ void manager::CoverArtManager::deleteCover(const model::Song& song)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
manager::DirectoryManager::deleteDirectories(song, result.second);
|
DirectoryManager::deleteDirectories(song, result.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::CoverArtManager::updateCover(const model::Song& updatedSong,
|
void CoverArtManager::updateCover(const model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
database::CoverArtRepository covRepo(m_bConf);
|
database::CoverArtRepository covRepo(m_bConf);
|
||||||
@@ -110,10 +107,10 @@ void manager::CoverArtManager::updateCover(const model::Song& updatedSong,
|
|||||||
fs::copy(cover.imagePath, imagePath);
|
fs::copy(cover.imagePath, imagePath);
|
||||||
fs::remove(cover.imagePath);
|
fs::remove(cover.imagePath);
|
||||||
|
|
||||||
manager::DirectoryManager::deleteDirectories(currSong, result.second);
|
DirectoryManager::deleteDirectories(currSong, result.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::CoverArtManager::updateCoverRecord(const model::Song& updatedSong)
|
void CoverArtManager::updateCoverRecord(const model::Song& updatedSong)
|
||||||
{
|
{
|
||||||
model::Cover updatedCover(updatedSong);
|
model::Cover updatedCover(updatedSong);
|
||||||
auto updatedImagePath = createImagePath(updatedSong);
|
auto updatedImagePath = createImagePath(updatedSong);
|
||||||
@@ -123,9 +120,9 @@ void manager::CoverArtManager::updateCoverRecord(const model::Song& updatedSong)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string manager::CoverArtManager::createImagePath(const model::Song& song)
|
std::string CoverArtManager::createImagePath(const model::Song& song)
|
||||||
{
|
{
|
||||||
auto imagePath = manager::DirectoryManager::createDirectoryProcess(
|
auto imagePath = DirectoryManager::createDirectoryProcess(
|
||||||
song, m_bConf, type::PathType::coverArt);
|
song, m_bConf, type::PathType::coverArt);
|
||||||
|
|
||||||
if (song.track != 0) {
|
if (song.track != 0) {
|
||||||
@@ -140,3 +137,4 @@ std::string manager::CoverArtManager::createImagePath(const model::Song& song)
|
|||||||
|
|
||||||
return imagePath;
|
return imagePath;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
namespace manager {
|
||||||
std::string manager::DirectoryManager::createDirectoryProcess(model::Song song, const std::string& rootPath)
|
std::string DirectoryManager::createDirectoryProcess(model::Song song, const std::string& rootPath)
|
||||||
{
|
{
|
||||||
auto currPath = fs::path(rootPath);
|
auto currPath = fs::path(rootPath);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ std::string manager::DirectoryManager::createDirectoryProcess(model::Song song,
|
|||||||
return albPath.string() + "/";
|
return albPath.string() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string manager::DirectoryManager::createDirectoryProcess(const model::Song& song,
|
std::string DirectoryManager::createDirectoryProcess(const model::Song& song,
|
||||||
const model::BinaryPath& bConf, type::PathType pType)
|
const model::BinaryPath& bConf, type::PathType pType)
|
||||||
{
|
{
|
||||||
auto path = pathConfigContent(bConf)[retrievePathType(pType)];
|
auto path = pathConfigContent(bConf)[retrievePathType(pType)];
|
||||||
@@ -71,17 +71,17 @@ std::string manager::DirectoryManager::createDirectoryProcess(const model::Song&
|
|||||||
return albPath.string() + "/";
|
return albPath.string() + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string manager::DirectoryManager::configPath(std::string_view path)
|
std::string DirectoryManager::configPath(std::string_view path)
|
||||||
{
|
{
|
||||||
return fs::canonical(path).parent_path().string();
|
return fs::canonical(path).parent_path().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string manager::DirectoryManager::configPath(const model::BinaryPath& bConf)
|
std::string DirectoryManager::configPath(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
return fs::canonical(bConf.path).parent_path().string();
|
return fs::canonical(bConf.path).parent_path().string();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string manager::DirectoryManager::contentOfPath(const std::string& path)
|
std::string DirectoryManager::contentOfPath(const std::string& path)
|
||||||
{
|
{
|
||||||
std::fstream a(path, std::ios::in);
|
std::fstream a(path, std::ios::in);
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
@@ -91,7 +91,7 @@ std::string manager::DirectoryManager::contentOfPath(const std::string& path)
|
|||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string manager::DirectoryManager::retrievePathType(type::PathType pType)
|
std::string DirectoryManager::retrievePathType(type::PathType pType)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
switch (pType) {
|
switch (pType) {
|
||||||
@@ -115,7 +115,7 @@ std::string manager::DirectoryManager::retrievePathType(type::PathType pType)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nlohmann::json manager::DirectoryManager::credentialConfigContent(const model::BinaryPath& bConf)
|
nlohmann::json DirectoryManager::credentialConfigContent(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto path = configPath(bConf);
|
auto path = configPath(bConf);
|
||||||
path.append("/authcredentials.json");
|
path.append("/authcredentials.json");
|
||||||
@@ -123,7 +123,7 @@ nlohmann::json manager::DirectoryManager::credentialConfigContent(const model::B
|
|||||||
return nlohmann::json::parse(contentOfPath(path));
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json manager::DirectoryManager::databaseConfigContent(const model::BinaryPath& bConf)
|
nlohmann::json DirectoryManager::databaseConfigContent(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto path = configPath(bConf);
|
auto path = configPath(bConf);
|
||||||
path.append("/database.json");
|
path.append("/database.json");
|
||||||
@@ -131,7 +131,7 @@ nlohmann::json manager::DirectoryManager::databaseConfigContent(const model::Bin
|
|||||||
return nlohmann::json::parse(contentOfPath(path));
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json manager::DirectoryManager::pathConfigContent(const model::BinaryPath& bConf)
|
nlohmann::json DirectoryManager::pathConfigContent(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto path = configPath(bConf);
|
auto path = configPath(bConf);
|
||||||
path.append("/paths.json");
|
path.append("/paths.json");
|
||||||
@@ -139,7 +139,8 @@ nlohmann::json manager::DirectoryManager::pathConfigContent(const model::BinaryP
|
|||||||
return nlohmann::json::parse(contentOfPath(path));
|
return nlohmann::json::parse(contentOfPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::DirectoryManager::deleteDirectories(model::Song song, const std::string& rootPath)
|
|
||||||
|
void DirectoryManager::deleteDirectories(model::Song song, const std::string& rootPath)
|
||||||
{
|
{
|
||||||
std::cout << "checking for empty directories to delete" << std::endl;
|
std::cout << "checking for empty directories to delete" << std::endl;
|
||||||
const std::string art(rootPath + std::string("/") + song.artist);
|
const std::string art(rootPath + std::string("/") + song.artist);
|
||||||
@@ -165,7 +166,8 @@ void manager::DirectoryManager::deleteDirectories(model::Song song, const std::s
|
|||||||
std::cout << "deleted empty directory or directories" << std::endl;
|
std::cout << "deleted empty directory or directories" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::DirectoryManager::deleteCoverArtFile(const std::string& covPath, const std::string& stockCoverPath)
|
void DirectoryManager::deleteCoverArtFile(const std::string& covPath,
|
||||||
|
const std::string& stockCoverPath)
|
||||||
{
|
{
|
||||||
if (covPath.compare(stockCoverPath) == 0) {
|
if (covPath.compare(stockCoverPath) == 0) {
|
||||||
std::cout << "cover has stock cover art, will not deleted" << std::endl;
|
std::cout << "cover has stock cover art, will not deleted" << std::endl;
|
||||||
@@ -176,7 +178,7 @@ void manager::DirectoryManager::deleteCoverArtFile(const std::string& covPath, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::DirectoryManager::deleteSong(const model::Song song)
|
void DirectoryManager::deleteSong(const model::Song song)
|
||||||
{
|
{
|
||||||
std::cout << "deleting song" << std::endl;
|
std::cout << "deleting song" << std::endl;
|
||||||
auto songPath = fs::path(song.songPath);
|
auto songPath = fs::path(song.songPath);
|
||||||
@@ -190,3 +192,4 @@ void manager::DirectoryManager::deleteSong(const model::Song song)
|
|||||||
std::cout << "deleted song" << std::endl;
|
std::cout << "deleted song" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
#include "database/GenreRepository.h"
|
#include "database/GenreRepository.h"
|
||||||
#include "type/GenreFilter.h"
|
#include "type/GenreFilter.h"
|
||||||
|
|
||||||
manager::GenreManager::GenreManager(const model::BinaryPath& bConf)
|
namespace manager {
|
||||||
: m_bConf(bConf)
|
GenreManager::GenreManager(const model::BinaryPath& bConf) : m_bConf(bConf) { }
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
model::Genre manager::GenreManager::retrieveGenre(model::Genre& genre)
|
model::Genre GenreManager::retrieveGenre(model::Genre& genre)
|
||||||
{
|
{
|
||||||
database::GenreRepository gnrRepo(m_bConf);
|
database::GenreRepository gnrRepo(m_bConf);
|
||||||
genre = gnrRepo.retrieveRecord(genre, type::GenreFilter::category);
|
genre = gnrRepo.retrieveRecord(genre, type::GenreFilter::category);
|
||||||
@@ -18,7 +17,7 @@ model::Genre manager::GenreManager::retrieveGenre(model::Genre& genre)
|
|||||||
return genre;
|
return genre;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Genre manager::GenreManager::saveGenre(const model::Song& song)
|
model::Genre GenreManager::saveGenre(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Genre genre;
|
model::Genre genre;
|
||||||
genre.category = song.genre;
|
genre.category = song.genre;
|
||||||
@@ -34,7 +33,7 @@ model::Genre manager::GenreManager::saveGenre(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::GenreManager::deleteGenre(const model::Song& song)
|
void GenreManager::deleteGenre(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Genre genre(song);
|
model::Genre genre(song);
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ void manager::GenreManager::deleteGenre(const model::Song& song)
|
|||||||
gnrRepo.deleteRecord(genre, type::GenreFilter::id);
|
gnrRepo.deleteRecord(genre, type::GenreFilter::id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::GenreManager::updateGenre(model::Song& updatedSong,
|
void GenreManager::updateGenre(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
model::Genre genre;
|
model::Genre genre;
|
||||||
@@ -69,9 +68,10 @@ void manager::GenreManager::updateGenre(model::Song& updatedSong,
|
|||||||
updatedSong.genreId = genre.id;
|
updatedSong.genreId = genre.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::GenreManager::printGenre(const model::Genre& genre)
|
void GenreManager::printGenre(const model::Genre& genre)
|
||||||
{
|
{
|
||||||
std::cout << "genre record" << std::endl;
|
std::cout << "genre record" << std::endl;
|
||||||
std::cout << "id: " << genre.id << std::endl;
|
std::cout << "id: " << genre.id << std::endl;
|
||||||
std::cout << "category: " << genre.category << std::endl;
|
std::cout << "category: " << genre.category << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
+47
-49
@@ -21,16 +21,13 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
manager::SongManager::SongManager(std::string& x_path)
|
namespace manager {
|
||||||
: exe_path(x_path)
|
SongManager::SongManager(const model::BinaryPath& bConf)
|
||||||
{ }
|
|
||||||
|
|
||||||
manager::SongManager::SongManager(const model::BinaryPath& bConf)
|
|
||||||
: m_bConf(bConf)
|
: m_bConf(bConf)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
bool manager::SongManager::didSongChange(const model::Song& updatedSong,
|
bool SongManager::didSongChange(const model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
if (!updatedSong.title.empty()) {
|
if (!updatedSong.title.empty()) {
|
||||||
@@ -52,7 +49,7 @@ bool manager::SongManager::didSongChange(const model::Song& updatedSong,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool manager::SongManager::requiresFilesystemChange(const model::Song& updatedSong,
|
bool SongManager::requiresFilesystemChange(const model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
if (updatedSong.title.compare(currSong.title) != 0) {
|
if (updatedSong.title.compare(currSong.title) != 0) {
|
||||||
@@ -68,7 +65,7 @@ bool manager::SongManager::requiresFilesystemChange(const model::Song& updatedSo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool manager::SongManager::deleteSong(model::Song& song)
|
bool SongManager::deleteSong(model::Song& song)
|
||||||
{
|
{
|
||||||
database::SongRepository songRepo(m_bConf);
|
database::SongRepository songRepo(m_bConf);
|
||||||
|
|
||||||
@@ -79,7 +76,7 @@ bool manager::SongManager::deleteSong(model::Song& song)
|
|||||||
|
|
||||||
song = songRepo.retrieveRecord(song, type::SongFilter::id);
|
song = songRepo.retrieveRecord(song, type::SongFilter::id);
|
||||||
|
|
||||||
auto paths = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto paths = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
|
|
||||||
auto deleted = songRepo.deleteRecord(song);
|
auto deleted = songRepo.deleteRecord(song);
|
||||||
|
|
||||||
@@ -90,11 +87,11 @@ bool manager::SongManager::deleteSong(model::Song& song)
|
|||||||
deleteMisc(song);
|
deleteMisc(song);
|
||||||
|
|
||||||
fs::remove(song.songPath);
|
fs::remove(song.songPath);
|
||||||
manager::DirectoryManager::deleteDirectories(song, paths["root_music_path"].get<std::string>());
|
DirectoryManager::deleteDirectories(song, paths["root_music_path"].get<std::string>());
|
||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool manager::SongManager::updateSong(model::Song& updatedSong)
|
bool SongManager::updateSong(model::Song& updatedSong)
|
||||||
{
|
{
|
||||||
database::SongRepository songRepo(m_bConf);
|
database::SongRepository songRepo(m_bConf);
|
||||||
model::Song currSong(updatedSong.id);
|
model::Song currSong(updatedSong.id);
|
||||||
@@ -126,7 +123,7 @@ bool manager::SongManager::updateSong(model::Song& updatedSong)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::SongManager::saveSong(model::Song& song)
|
void SongManager::saveSong(model::Song& song)
|
||||||
{
|
{
|
||||||
saveSongTemp(song);
|
saveSongTemp(song);
|
||||||
utility::MetadataRetriever meta;
|
utility::MetadataRetriever meta;
|
||||||
@@ -140,11 +137,11 @@ void manager::SongManager::saveSong(model::Song& song)
|
|||||||
|
|
||||||
database::SongRepository songRepo(m_bConf);
|
database::SongRepository songRepo(m_bConf);
|
||||||
songRepo.saveRecord(song);
|
songRepo.saveRecord(song);
|
||||||
song = songRepo.retrieveRecord(song, type::SongFilter::title);
|
song = songRepo.retrieveRecord(song, type::SongFilter::titleAndArtist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void manager::SongManager::printSong(const model::Song& song)
|
void SongManager::printSong(const model::Song& song)
|
||||||
{
|
{
|
||||||
std::cout << "\nsong" << std::endl;
|
std::cout << "\nsong" << std::endl;
|
||||||
std::cout << "title: " << song.title << std::endl;
|
std::cout << "title: " << song.title << std::endl;
|
||||||
@@ -164,7 +161,7 @@ void manager::SongManager::printSong(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::map<type::SongChanged, bool> manager::SongManager::changesInSong(
|
std::map<type::SongChanged, bool> SongManager::changesInSong(
|
||||||
const model::Song& updatedSong, const model::Song& currSong)
|
const model::Song& updatedSong, const model::Song& currSong)
|
||||||
{
|
{
|
||||||
std::map<type::SongChanged, bool> songChanges;
|
std::map<type::SongChanged, bool> songChanges;
|
||||||
@@ -197,9 +194,9 @@ std::map<type::SongChanged, bool> manager::SongManager::changesInSong(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string manager::SongManager::createSongPath(const model::Song& song)
|
std::string SongManager::createSongPath(const model::Song& song)
|
||||||
{
|
{
|
||||||
auto songPath = manager::DirectoryManager::createDirectoryProcess(
|
auto songPath = DirectoryManager::createDirectoryProcess(
|
||||||
song, m_bConf, type::PathType::music);
|
song, m_bConf, type::PathType::music);
|
||||||
|
|
||||||
if (song.track != 0) {
|
if (song.track != 0) {
|
||||||
@@ -217,7 +214,7 @@ std::string manager::SongManager::createSongPath(const model::Song& song)
|
|||||||
|
|
||||||
|
|
||||||
// used to prevent empty values to appear in the updated song
|
// used to prevent empty values to appear in the updated song
|
||||||
void manager::SongManager::assignMiscFields(
|
void SongManager::assignMiscFields(
|
||||||
std::map<type::SongChanged, bool>& songChanges, model::Song& updatedSong,
|
std::map<type::SongChanged, bool>& songChanges, model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
@@ -256,7 +253,7 @@ void manager::SongManager::assignMiscFields(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// used to dump miscellaneous id to the updated song
|
// used to dump miscellaneous id to the updated song
|
||||||
void manager::SongManager::assignMiscId(model::Song& updatedSong,
|
void SongManager::assignMiscId(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
std::cout << "assigning miscellaneous Id's to updated song" << std::endl;
|
std::cout << "assigning miscellaneous Id's to updated song" << std::endl;
|
||||||
@@ -268,9 +265,9 @@ void manager::SongManager::assignMiscId(model::Song& updatedSong,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// saves song to a temporary path
|
// saves song to a temporary path
|
||||||
void manager::SongManager::saveSongTemp(model::Song& song)
|
void SongManager::saveSongTemp(model::Song& song)
|
||||||
{
|
{
|
||||||
auto config = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto config = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
|
|
||||||
auto tmpSongPath = config["temp_root_path"].get<std::string>();
|
auto tmpSongPath = config["temp_root_path"].get<std::string>();
|
||||||
std::random_device dev;
|
std::random_device dev;
|
||||||
@@ -287,10 +284,10 @@ void manager::SongManager::saveSongTemp(model::Song& song)
|
|||||||
song.songPath = tmpSongPath;
|
song.songPath = tmpSongPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::SongManager::saveMisc(model::Song& song)
|
void SongManager::saveMisc(model::Song& song)
|
||||||
{
|
{
|
||||||
CoverArtManager covMgr(m_bConf);
|
CoverArtManager covMgr(m_bConf);
|
||||||
auto pathConfigContent = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto pathConfigContent = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
|
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
|
||||||
|
|
||||||
auto cov = covMgr.saveCover(song);
|
auto cov = covMgr.saveCover(song);
|
||||||
@@ -311,22 +308,22 @@ void manager::SongManager::saveMisc(model::Song& song)
|
|||||||
AlbumManager albMgr(m_bConf);
|
AlbumManager albMgr(m_bConf);
|
||||||
auto album = albMgr.saveAlbum(song);
|
auto album = albMgr.saveAlbum(song);
|
||||||
album = albMgr.retrieveAlbum(album);
|
album = albMgr.retrieveAlbum(album);
|
||||||
manager::AlbumManager::printAlbum(album);
|
AlbumManager::printAlbum(album);
|
||||||
|
|
||||||
ArtistManager artMgr(m_bConf);
|
ArtistManager artMgr(m_bConf);
|
||||||
auto artist = artMgr.saveArtist(song);
|
auto artist = artMgr.saveArtist(song);
|
||||||
artist = artMgr.retrieveArtist(artist);
|
artist = artMgr.retrieveArtist(artist);
|
||||||
manager::ArtistManager::printArtist(artist);
|
ArtistManager::printArtist(artist);
|
||||||
|
|
||||||
GenreManager gnrMgr(m_bConf);
|
GenreManager gnrMgr(m_bConf);
|
||||||
auto genre = gnrMgr.saveGenre(song);
|
auto genre = gnrMgr.saveGenre(song);
|
||||||
genre = gnrMgr.retrieveGenre(genre);
|
genre = gnrMgr.retrieveGenre(genre);
|
||||||
manager::GenreManager::printGenre(genre);
|
GenreManager::printGenre(genre);
|
||||||
|
|
||||||
YearManager yrMgr(m_bConf);
|
YearManager yrMgr(m_bConf);
|
||||||
auto year = yrMgr.saveYear(song);
|
auto year = yrMgr.saveYear(song);
|
||||||
year = yrMgr.retrieveYear(year);
|
year = yrMgr.retrieveYear(year);
|
||||||
manager::YearManager::printYear(year);
|
YearManager::printYear(year);
|
||||||
|
|
||||||
song.coverArtId = cov.id;
|
song.coverArtId = cov.id;
|
||||||
song.albumId = album.id;
|
song.albumId = album.id;
|
||||||
@@ -337,41 +334,41 @@ void manager::SongManager::saveMisc(model::Song& song)
|
|||||||
std::cout << "done with miscellaneous database records" << std::endl;
|
std::cout << "done with miscellaneous database records" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::SongManager::deleteMisc(const model::Song& song)
|
void SongManager::deleteMisc(const model::Song& song)
|
||||||
{
|
{
|
||||||
manager::CoverArtManager covMgr(m_bConf);
|
CoverArtManager covMgr(m_bConf);
|
||||||
covMgr.deleteCover(song);
|
covMgr.deleteCover(song);
|
||||||
|
|
||||||
manager::AlbumManager albMgr(m_bConf);
|
AlbumManager albMgr(m_bConf);
|
||||||
albMgr.deleteAlbum(song);
|
albMgr.deleteAlbum(song);
|
||||||
|
|
||||||
manager::ArtistManager artMgr(m_bConf);
|
ArtistManager artMgr(m_bConf);
|
||||||
artMgr.deleteArtist(song);
|
artMgr.deleteArtist(song);
|
||||||
|
|
||||||
manager::GenreManager gnrMgr(m_bConf);
|
GenreManager gnrMgr(m_bConf);
|
||||||
gnrMgr.deleteGenre(song);
|
gnrMgr.deleteGenre(song);
|
||||||
|
|
||||||
manager::YearManager yrMgr(m_bConf);
|
YearManager yrMgr(m_bConf);
|
||||||
yrMgr.deleteYear(song);
|
yrMgr.deleteYear(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
// deletes miscellanes records
|
// deletes miscellanes records
|
||||||
void manager::SongManager::deleteMiscExceptCoverArt(const model::Song& song)
|
void SongManager::deleteMiscExceptCoverArt(const model::Song& song)
|
||||||
{
|
{
|
||||||
manager::AlbumManager albMgr(m_bConf);
|
AlbumManager albMgr(m_bConf);
|
||||||
albMgr.deleteAlbum(song);
|
albMgr.deleteAlbum(song);
|
||||||
|
|
||||||
manager::ArtistManager artMgr(m_bConf);
|
ArtistManager artMgr(m_bConf);
|
||||||
artMgr.deleteArtist(song);
|
artMgr.deleteArtist(song);
|
||||||
|
|
||||||
manager::GenreManager gnrMgr(m_bConf);
|
GenreManager gnrMgr(m_bConf);
|
||||||
gnrMgr.deleteGenre(song);
|
gnrMgr.deleteGenre(song);
|
||||||
|
|
||||||
manager::YearManager yrMgr(m_bConf);
|
YearManager yrMgr(m_bConf);
|
||||||
yrMgr.deleteYear(song);
|
yrMgr.deleteYear(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::SongManager::updateMisc(
|
void SongManager::updateMisc(
|
||||||
const std::map<type::SongChanged, bool>& songChanges,
|
const std::map<type::SongChanged, bool>& songChanges,
|
||||||
model::Song& updatedSong, const model::Song& currSong)
|
model::Song& updatedSong, const model::Song& currSong)
|
||||||
{
|
{
|
||||||
@@ -382,25 +379,25 @@ void manager::SongManager::updateMisc(
|
|||||||
auto yearChange = songChanges.at(type::SongChanged::year);
|
auto yearChange = songChanges.at(type::SongChanged::year);
|
||||||
|
|
||||||
if (artistChange) {
|
if (artistChange) {
|
||||||
manager::ArtistManager artMgr(m_bConf);
|
ArtistManager artMgr(m_bConf);
|
||||||
artMgr.updateArtist(updatedSong, currSong);
|
artMgr.updateArtist(updatedSong, currSong);
|
||||||
}
|
}
|
||||||
if (albumChange) {
|
if (albumChange) {
|
||||||
manager::AlbumManager albMgr(m_bConf);
|
AlbumManager albMgr(m_bConf);
|
||||||
albMgr.updateAlbum(updatedSong, currSong);
|
albMgr.updateAlbum(updatedSong, currSong);
|
||||||
}
|
}
|
||||||
if (genreChange) {
|
if (genreChange) {
|
||||||
manager::GenreManager gnrMgr(m_bConf);
|
GenreManager gnrMgr(m_bConf);
|
||||||
gnrMgr.updateGenre(updatedSong, currSong);
|
gnrMgr.updateGenre(updatedSong, currSong);
|
||||||
}
|
}
|
||||||
if (yearChange) {
|
if (yearChange) {
|
||||||
manager::YearManager yrMgr(m_bConf);
|
YearManager yrMgr(m_bConf);
|
||||||
yrMgr.updateYear(updatedSong, currSong);
|
yrMgr.updateYear(updatedSong, currSong);
|
||||||
}
|
}
|
||||||
|
|
||||||
// determins to update the cover art record
|
// determins to update the cover art record
|
||||||
if (titleChange || artistChange || albumChange) {
|
if (titleChange || artistChange || albumChange) {
|
||||||
manager::CoverArtManager covMgr(m_bConf);
|
CoverArtManager covMgr(m_bConf);
|
||||||
covMgr.updateCoverRecord(updatedSong);
|
covMgr.updateCoverRecord(updatedSong);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,7 +407,7 @@ void manager::SongManager::updateMisc(
|
|||||||
deleteMiscExceptCoverArt(currSong);
|
deleteMiscExceptCoverArt(currSong);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::SongManager::modifySongOnFilesystem(model::Song& updatedSong,
|
void SongManager::modifySongOnFilesystem(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
std::cout << "preparing to modify song" << std::endl;
|
std::cout << "preparing to modify song" << std::endl;
|
||||||
@@ -422,12 +419,13 @@ void manager::SongManager::modifySongOnFilesystem(model::Song& updatedSong,
|
|||||||
fs::copy(currSong.songPath, updatedSong.songPath);
|
fs::copy(currSong.songPath, updatedSong.songPath);
|
||||||
fs::remove(currSong.songPath);
|
fs::remove(currSong.songPath);
|
||||||
|
|
||||||
auto paths = manager::DirectoryManager::pathConfigContent(m_bConf);
|
auto paths = DirectoryManager::pathConfigContent(m_bConf);
|
||||||
const auto musicRootPath =
|
const auto musicRootPath =
|
||||||
paths[manager::DirectoryManager::retrievePathType(
|
paths[DirectoryManager::retrievePathType(
|
||||||
type::PathType::music)].get<std::string>();
|
type::PathType::music)].get<std::string>();
|
||||||
manager::DirectoryManager::deleteDirectories(currSong, musicRootPath);
|
DirectoryManager::deleteDirectories(currSong, musicRootPath);
|
||||||
|
|
||||||
manager::CoverArtManager covMgr(m_bConf);
|
CoverArtManager covMgr(m_bConf);
|
||||||
covMgr.updateCover(updatedSong, currSong);
|
covMgr.updateCover(updatedSong, currSong);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace manager {
|
namespace manager {
|
||||||
TokenManager::TokenManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf)
|
model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto cred = parseAuthCredentials(bConf);
|
auto cred = parseAuthCredentials(bConf);
|
||||||
@@ -122,24 +117,6 @@ nlohmann::json TokenManager::createTokenBody(const model::AuthCredentials& auth)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[[depreacted("use the other function with the same name")]]
|
|
||||||
model::AuthCredentials TokenManager::parseAuthCredentials(std::string_view path)
|
|
||||||
{
|
|
||||||
auto exe_path = DirectoryManager::configPath(path);
|
|
||||||
exe_path.append("/authcredentials.json");
|
|
||||||
|
|
||||||
auto con = DirectoryManager::credentialConfigContent(exe_path);
|
|
||||||
|
|
||||||
model::AuthCredentials auth;
|
|
||||||
auth.uri = "https://";
|
|
||||||
auth.uri.append(con["domain"]);
|
|
||||||
auth.apiIdentifier = con["api_identifier"];
|
|
||||||
auth.clientId = con["client_id"];
|
|
||||||
auth.clientSecret = con["client_secret"];
|
|
||||||
auth.endpoint = "oauth/token";
|
|
||||||
|
|
||||||
return auth;
|
|
||||||
}
|
|
||||||
model::AuthCredentials TokenManager::parseAuthCredentials(const model::BinaryPath& bConf)
|
model::AuthCredentials TokenManager::parseAuthCredentials(const model::BinaryPath& bConf)
|
||||||
{
|
{
|
||||||
auto con = DirectoryManager::credentialConfigContent(bConf);
|
auto con = DirectoryManager::credentialConfigContent(bConf);
|
||||||
@@ -155,6 +132,7 @@ model::AuthCredentials TokenManager::parseAuthCredentials(const model::BinaryPat
|
|||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> TokenManager::extractScopes(const jwt::decoded_jwt&& decoded)
|
std::vector<std::string> TokenManager::extractScopes(const jwt::decoded_jwt&& decoded)
|
||||||
{
|
{
|
||||||
std::vector<std::string> scopes;
|
std::vector<std::string> scopes;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
#include "database/YearRepository.h"
|
#include "database/YearRepository.h"
|
||||||
#include "type/YearFilter.h"
|
#include "type/YearFilter.h"
|
||||||
|
|
||||||
manager::YearManager::YearManager(const model::BinaryPath& bConf)
|
namespace manager {
|
||||||
: m_bConf(bConf)
|
YearManager::YearManager(const model::BinaryPath& bConf)
|
||||||
{ }
|
: m_bConf(bConf) { }
|
||||||
|
|
||||||
|
|
||||||
model::Year manager::YearManager::retrieveYear(model::Year& year)
|
model::Year YearManager::retrieveYear(model::Year& year)
|
||||||
{
|
{
|
||||||
database::YearRepository yearRepo(m_bConf);
|
database::YearRepository yearRepo(m_bConf);
|
||||||
year = yearRepo.retrieveRecord(year, type::YearFilter::year);
|
year = yearRepo.retrieveRecord(year, type::YearFilter::year);
|
||||||
@@ -18,7 +18,7 @@ model::Year manager::YearManager::retrieveYear(model::Year& year)
|
|||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Year manager::YearManager::saveYear(const model::Song& song)
|
model::Year YearManager::saveYear(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Year year;
|
model::Year year;
|
||||||
year.year = song.year;
|
year.year = song.year;
|
||||||
@@ -33,7 +33,7 @@ model::Year manager::YearManager::saveYear(const model::Song& song)
|
|||||||
return year;
|
return year;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::YearManager::deleteYear(const model::Song& song)
|
void YearManager::deleteYear(const model::Song& song)
|
||||||
{
|
{
|
||||||
model::Year year(song);
|
model::Year year(song);
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ void manager::YearManager::deleteYear(const model::Song& song)
|
|||||||
yrRepo.deleteYear(year, type::YearFilter::id);
|
yrRepo.deleteYear(year, type::YearFilter::id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::YearManager::updateYear(model::Song& updatedSong,
|
void YearManager::updateYear(model::Song& updatedSong,
|
||||||
const model::Song& currSong)
|
const model::Song& currSong)
|
||||||
{
|
{
|
||||||
model::Year year;
|
model::Year year;
|
||||||
@@ -68,9 +68,10 @@ void manager::YearManager::updateYear(model::Song& updatedSong,
|
|||||||
updatedSong.yearId = year.id;
|
updatedSong.yearId = year.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager::YearManager::printYear(const model::Year& year)
|
void YearManager::printYear(const model::Year& year)
|
||||||
{
|
{
|
||||||
std::cout << "\nyear record" << std::endl;
|
std::cout << "\nyear record" << std::endl;
|
||||||
std::cout << "id: " << year.id << std::endl;
|
std::cout << "id: " << year.id << std::endl;
|
||||||
std::cout << "year: " << year.year << std::endl;
|
std::cout << "year: " << year.year << std::endl;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
#include "utility/ImageFile.h"
|
#include "utility/ImageFile.h"
|
||||||
|
|
||||||
utility::ImageFile::ImageFile(const char *file) : TagLib::File(file)
|
namespace utility {
|
||||||
|
ImageFile::ImageFile(const char *file) : TagLib::File(file)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TagLib::ByteVector utility::ImageFile::data()
|
TagLib::ByteVector ImageFile::data()
|
||||||
{
|
{
|
||||||
return readBlock(length());
|
return readBlock(length());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
model::Song utility::MetadataRetriever::retrieveMetadata(std::string& songPath)
|
namespace utility {
|
||||||
|
model::Song MetadataRetriever::retrieveMetadata(std::string& songPath)
|
||||||
{
|
{
|
||||||
TagLib::FileRef file(songPath.c_str());
|
TagLib::FileRef file(songPath.c_str());
|
||||||
model::Song song;
|
model::Song song;
|
||||||
@@ -48,7 +49,8 @@ model::Song utility::MetadataRetriever::retrieveMetadata(std::string& songPath)
|
|||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
model::Cover utility::MetadataRetriever::updateCoverArt(const model::Song& song, model::Cover& cov, const std::string& stockCoverPath)
|
model::Cover MetadataRetriever::updateCoverArt(const model::Song& song, model::Cover& cov,
|
||||||
|
const std::string& stockCoverPath)
|
||||||
{
|
{
|
||||||
TagLib::MPEG::File sngF(song.songPath.c_str());
|
TagLib::MPEG::File sngF(song.songPath.c_str());
|
||||||
auto tag = sngF.ID3v2Tag();
|
auto tag = sngF.ID3v2Tag();
|
||||||
@@ -93,14 +95,14 @@ model::Cover utility::MetadataRetriever::updateCoverArt(const model::Song& song,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tags song with the stock cover art
|
// tags song with the stock cover art
|
||||||
model::Cover utility::MetadataRetriever::applyStockCoverArt(
|
model::Cover MetadataRetriever::applyStockCoverArt(
|
||||||
const model::Song& song, model::Cover& cov,
|
const model::Song& song, model::Cover& cov,
|
||||||
const std::string& stockCoverPath)
|
const std::string& stockCoverPath)
|
||||||
{
|
{
|
||||||
TagLib::MPEG::File songFile(song.songPath.c_str());
|
TagLib::MPEG::File songFile(song.songPath.c_str());
|
||||||
auto tag = songFile.ID3v2Tag();
|
auto tag = songFile.ID3v2Tag();
|
||||||
|
|
||||||
utility::ImageFile stockImg(cov.imagePath.c_str());
|
ImageFile stockImg(cov.imagePath.c_str());
|
||||||
TagLib::ID3v2::AttachedPictureFrame *pic =
|
TagLib::ID3v2::AttachedPictureFrame *pic =
|
||||||
new TagLib::ID3v2::AttachedPictureFrame;
|
new TagLib::ID3v2::AttachedPictureFrame;
|
||||||
|
|
||||||
@@ -119,7 +121,7 @@ model::Cover utility::MetadataRetriever::applyStockCoverArt(
|
|||||||
|
|
||||||
// extracts cover art from the song and save it to the
|
// extracts cover art from the song and save it to the
|
||||||
// appropriate directory
|
// appropriate directory
|
||||||
model::Cover utility::MetadataRetriever::applyCoverArt(const model::Song& song,
|
model::Cover MetadataRetriever::applyCoverArt(const model::Song& song,
|
||||||
model::Cover& cov)
|
model::Cover& cov)
|
||||||
{
|
{
|
||||||
TagLib::MPEG::File songFile(song.songPath.c_str());
|
TagLib::MPEG::File songFile(song.songPath.c_str());
|
||||||
@@ -140,7 +142,7 @@ model::Cover utility::MetadataRetriever::applyCoverArt(const model::Song& song,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool utility::MetadataRetriever::songContainsCoverArt(const model::Song& song)
|
bool MetadataRetriever::songContainsCoverArt(const model::Song& song)
|
||||||
{
|
{
|
||||||
TagLib::MPEG::File songFile(song.songPath.c_str());
|
TagLib::MPEG::File songFile(song.songPath.c_str());
|
||||||
auto tag = songFile.ID3v2Tag();
|
auto tag = songFile.ID3v2Tag();
|
||||||
@@ -150,7 +152,7 @@ bool utility::MetadataRetriever::songContainsCoverArt(const model::Song& song)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void utility::MetadataRetriever::updateMetadata(model::Song& sngUpdated, const model::Song& sngOld)
|
void MetadataRetriever::updateMetadata(model::Song& sngUpdated, const model::Song& sngOld)
|
||||||
{
|
{
|
||||||
std::cout<<"updating metadata"<<std::endl;
|
std::cout<<"updating metadata"<<std::endl;
|
||||||
TagLib::FileRef file(sngOld.songPath.c_str());
|
TagLib::FileRef file(sngOld.songPath.c_str());
|
||||||
@@ -175,3 +177,4 @@ void utility::MetadataRetriever::updateMetadata(model::Song& sngUpdated, const m
|
|||||||
|
|
||||||
file.save();
|
file.save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user