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:
+2
-2
@@ -10,7 +10,7 @@ set(SOURCES
|
||||
src/controller/loginController.hpp
|
||||
src/controller/songController.hpp
|
||||
src/database/base_repository.cpp
|
||||
#src/database/coverArtRepository.cpp
|
||||
src/database/coverArtRepository.cpp
|
||||
#src/database/songRepository.cpp
|
||||
src/dto/loginResultDto.hpp
|
||||
src/main.cpp
|
||||
@@ -23,7 +23,7 @@ set(SOURCES
|
||||
)
|
||||
set(HEADERS
|
||||
include/database/base_repository.h
|
||||
#include/database/coverArtRepository.h
|
||||
include/database/coverArtRepository.h
|
||||
#include/database/songRepository.h
|
||||
include/managers/coverArtManager.h
|
||||
include/managers/directory_manager.h
|
||||
|
||||
@@ -10,11 +10,19 @@
|
||||
class base_repository
|
||||
{
|
||||
public:
|
||||
base_repository();
|
||||
base_repository(const std::string&);
|
||||
protected:
|
||||
MYSQL* setup_mysql_connection();
|
||||
MYSQL* setup_mysql_connection(database_connection);
|
||||
|
||||
MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&);
|
||||
|
||||
database_connection details;
|
||||
private:
|
||||
void intitalizeDetails();
|
||||
|
||||
std::string path;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,11 +3,15 @@
|
||||
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
#include "database/base_repository.h"
|
||||
#include "models/models.h"
|
||||
|
||||
class coverArtRepository
|
||||
class coverArtRepository : public base_repository
|
||||
{
|
||||
public:
|
||||
coverArtRepository(const std::string&);
|
||||
|
||||
void saveRecord(const Cover&);
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
#ifndef COVERARTMANAGER_H_
|
||||
#define COVERARTMANAGER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "models/models.h"
|
||||
|
||||
class coverArtManager
|
||||
{
|
||||
public:
|
||||
coverArtManager(const std::string&);
|
||||
|
||||
Cover saveCover(const Song&, std::string&, const std::string&);
|
||||
private:
|
||||
std::string path;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -13,13 +13,6 @@ class song_manager
|
||||
public:
|
||||
song_manager(std::string&);
|
||||
|
||||
/**
|
||||
std::string retrieveMusicPath();
|
||||
std::string retrieveTempPath();
|
||||
*/
|
||||
|
||||
//nlohmann::json pathConfigContent();
|
||||
|
||||
void saveSong(Song&);
|
||||
|
||||
static void printSong(const Song&);
|
||||
|
||||
@@ -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