Working on interfacing with the database. Could do queryies via string/cstring but I'm going to try prepared statements
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
#include "database/base_repository.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "managers/directory_manager.h"
|
||||
|
||||
base_repository::base_repository()
|
||||
{ }
|
||||
|
||||
base_repository::base_repository(const std::string& path) : path(path)
|
||||
{
|
||||
intitalizeDetails();
|
||||
}
|
||||
|
||||
MYSQL* base_repository::setup_mysql_connection()
|
||||
{
|
||||
MYSQL *conn = mysql_init(nullptr);
|
||||
|
||||
auto res = mysql_real_connect(conn, details.server.c_str(), details.username.c_str(),
|
||||
details.password.c_str(), details.database.c_str(), 0, nullptr, 0);
|
||||
|
||||
return conn;
|
||||
}
|
||||
MYSQL* base_repository::setup_mysql_connection(database_connection details)
|
||||
{
|
||||
MYSQL *connection = mysql_init(NULL);
|
||||
@@ -23,3 +44,12 @@ MYSQL_RES* base_repository::perform_mysql_query(MYSQL *conn, const std::string&
|
||||
|
||||
return mysql_use_result(conn);
|
||||
}
|
||||
|
||||
void base_repository::intitalizeDetails()
|
||||
{
|
||||
auto databaseConfig = directory_manager::databaseConfigContent(path);
|
||||
details.database = databaseConfig.get<std::string>();
|
||||
details.password = databaseConfig.get<std::string>();
|
||||
details.server = databaseConfig.get<std::string>();
|
||||
details.username = databaseConfig.get<std::string>();
|
||||
}
|
||||
|
||||
@@ -1 +1,9 @@
|
||||
#include "database/coverArtRepository.h"
|
||||
|
||||
|
||||
coverArtRepository::coverArtRepository(const std::string& path) : base_repository(path)
|
||||
{ }
|
||||
|
||||
void coverArtRepository::saveRecord(const Cover& cov)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#include "managers/coverArtManager.h"
|
||||
|
||||
#include "database/coverArtRepository.h"
|
||||
#include "utilities/metadata_retriever.h"
|
||||
|
||||
coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
|
||||
{ }
|
||||
|
||||
|
||||
Cover coverArtManager::saveCover(const Song& song, std::string& rootPath, const std::string& stockCoverPath)
|
||||
{
|
||||
metadata_retriever meta;
|
||||
@@ -10,5 +15,7 @@ Cover coverArtManager::saveCover(const Song& song, std::string& rootPath, const
|
||||
cov = meta.update_cover_art(song, cov, stockCoverPath);
|
||||
cov.songTitle = song.title;
|
||||
|
||||
coverArtRepository covRepo(path);
|
||||
|
||||
return cov;
|
||||
}
|
||||
|
||||
@@ -16,31 +16,6 @@ song_manager::song_manager(std::string& x_path)
|
||||
: exe_path(x_path)
|
||||
{ }
|
||||
|
||||
/**
|
||||
std::string song_manager::retrieveMusicPath()
|
||||
{
|
||||
std::string pathConfig = directory_manager::configPath(exe_path);
|
||||
pathConfig.append("/paths.json");
|
||||
nlohmann::json config = nlohmann::json::parse(directory_manager::contentOfPath(pathConfig));
|
||||
|
||||
return config["root_music_path"].get<std::string>();
|
||||
}
|
||||
std::string song_manager::retrieveTempPath()
|
||||
{
|
||||
auto pathConfig = directory_manager::configPath(exe_path);
|
||||
pathConfig.append("/paths");
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
nlohmann::json song_manager::pathConfigContent()
|
||||
{
|
||||
auto path = directory_manager::configPath(exe_path);
|
||||
path.append("/paths.json");
|
||||
|
||||
return nlohmann::json::parse(directory_manager::contentOfPath(path));
|
||||
}
|
||||
*/
|
||||
|
||||
void song_manager::saveSong(Song& song)
|
||||
{
|
||||
@@ -51,10 +26,13 @@ void song_manager::saveSong(Song& song)
|
||||
song.data = std::move(data);
|
||||
printSong(song);
|
||||
|
||||
coverArtManager covMgr;
|
||||
coverArtManager covMgr(exe_path);
|
||||
auto coverRootPath = directory_manager::pathConfigContent(exe_path)["cover_root_path"].get<std::string>();
|
||||
//const nlohmann::json databaseConfig = directory_manager::databaseConfigContent(exe_path);
|
||||
|
||||
auto stockCoverPath = directory_manager::configPath(exe_path);
|
||||
stockCoverPath.append("/CoverArt.png");
|
||||
|
||||
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
|
||||
}
|
||||
|
||||
@@ -78,6 +56,7 @@ void song_manager::saveSongTemp(Song& song)
|
||||
std::random_device dev;
|
||||
std::mt19937 rng(dev());
|
||||
std::uniform_int_distribution<std::mt19937::result_type> dist(1,1000);
|
||||
|
||||
tmp_song.append(std::to_string(dist(rng)));
|
||||
tmp_song.append(".mp3");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user