Added Manager namespace

This commit is contained in:
kdeng00
2019-09-01 14:14:46 -04:00
parent d44a5bb1bc
commit d16b8dc3c9
12 changed files with 94 additions and 83 deletions
+10 -7
View File
@@ -5,14 +5,17 @@
#include "models/models.h"
class coverArtManager
namespace Manager
{
public:
coverArtManager(const std::string&);
class coverArtManager
{
public:
coverArtManager(const std::string&);
Model::Cover saveCover(const Model::Song&, std::string&, const std::string&);
private:
std::string path;
};
Model::Cover saveCover(const Model::Song&, std::string&, const std::string&);
private:
std::string path;
};
}
#endif
+16 -14
View File
@@ -8,23 +8,25 @@
#include "models/models.h"
class directory_manager
namespace Manager
{
public:
class directory_manager
{
public:
static std::string create_directory_process(Model::Song, const std::string&);
static std::string configPath(std::string_view);
static std::string contentOfPath(std::string_view);
static std::string create_directory_process(Model::Song, const std::string&);
static std::string configPath(std::string_view);
static std::string contentOfPath(std::string_view);
static nlohmann::json credentialConfigContent(const std::string&);
static nlohmann::json databaseConfigContent(const std::string&);
static nlohmann::json pathConfigContent(const std::string&);
static nlohmann::json credentialConfigContent(const std::string&);
static nlohmann::json databaseConfigContent(const std::string&);
static nlohmann::json pathConfigContent(const std::string&);
void delete_cover_art_file(const std::string&, const std::string&);
static void delete_directories(Model::Song, const std::string&);
void delete_cover_art_file(const std::string&, const std::string&);
static void delete_directories(Model::Song, const std::string&);
private:
void delete_song(const Model::Song);
};
private:
void delete_song(const Model::Song);
};
}
#endif
+13 -10
View File
@@ -8,19 +8,22 @@
#include "models/models.h"
class song_manager
namespace Manager
{
public:
song_manager(std::string&);
class song_manager
{
public:
song_manager(std::string&);
void saveSong(Model::Song&);
void deleteSong(Model::Song&);
void saveSong(Model::Song&);
void deleteSong(Model::Song&);
static void printSong(const Model::Song&);
private:
void saveSongTemp(Model::Song&);
static void printSong(const Model::Song&);
private:
void saveSongTemp(Model::Song&);
std::string exe_path;
};
std::string exe_path;
};
}
#endif
+15 -12
View File
@@ -11,22 +11,25 @@
#include "models/models.h"
#include "types/scopes.h"
class token_manager
namespace Manager
{
public:
token_manager();
class token_manager
{
public:
token_manager();
Model::loginResult retrieve_token();
Model::loginResult retrieve_token(std::string_view);
Model::loginResult retrieve_token();
Model::loginResult retrieve_token(std::string_view);
bool is_token_valid(std::string&, Scope);
private:
Model::auth_credentials parse_auth_credentials(std::string_view);
bool is_token_valid(std::string&, Scope);
private:
Model::auth_credentials parse_auth_credentials(std::string_view);
std::vector<std::string> extract_scopes(const jwt::decoded_jwt&&);
std::pair<bool, std::vector<std::string>> fetch_auth_header(const std::string&);
std::vector<std::string> extract_scopes(const jwt::decoded_jwt&&);
std::pair<bool, std::vector<std::string>> fetch_auth_header(const std::string&);
bool token_supports_scope(const std::vector<std::string>, const std::string&&);
};
bool token_supports_scope(const std::vector<std::string>, const std::string&&);
};
}
#endif
+1 -1
View File
@@ -26,7 +26,7 @@ public:
{
OATPP_LOGI("icarus", "logging in");
token_manager tok;
Manager::token_manager tok;
auto token = tok.retrieve_token(exe_path);
auto logRes = loginResultDto::createShared();
+3 -3
View File
@@ -46,7 +46,7 @@ public:
auto auth = authHeader->std_str();
token_manager tok;
Manager::token_manager tok;
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Scope::upload), Status::CODE_403, "Not allowed");
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
@@ -69,7 +69,7 @@ public:
Model::Song sng;
sng.data = std::move(data);
song_manager s_mgr(m_exe_path);
Manager::song_manager s_mgr(m_exe_path);
s_mgr.saveSong(sng);
return createResponse(Status::CODE_200, "OK");
@@ -159,7 +159,7 @@ public:
Model::Song song;
song.id = id;
song_manager sngMgr(m_exe_path);
Manager::song_manager sngMgr(m_exe_path);
sngMgr.deleteSong(song);
return createResponse(Status::CODE_200, "OK");
+1 -1
View File
@@ -51,7 +51,7 @@ MYSQL_RES* base_repository::perform_mysql_query(MYSQL *conn, const std::string&
void base_repository::intitalizeDetails()
{
auto databaseConfig = directory_manager::databaseConfigContent(path);
auto databaseConfig = Manager::directory_manager::databaseConfigContent(path);
details.database = databaseConfig["database"].get<std::string>();
details.password = databaseConfig["password"].get<std::string>();
+2 -2
View File
@@ -4,11 +4,11 @@
#include "types/coverFilter.h"
#include "utilities/metadata_retriever.h"
coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
Manager::coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
{ }
Model::Cover coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
{
metadata_retriever meta;
Model::Cover cov;
+9 -9
View File
@@ -7,7 +7,7 @@
namespace fs = std::filesystem;
std::string directory_manager::create_directory_process(Model::Song song, const std::string& root_path)
std::string Manager::directory_manager::create_directory_process(Model::Song song, const std::string& root_path)
{
auto curr_path = fs::path(root_path);
@@ -37,11 +37,11 @@ std::string directory_manager::create_directory_process(Model::Song song, const
return alb_path.string() + "/";
}
std::string directory_manager::configPath(std::string_view path)
std::string Manager::directory_manager::configPath(std::string_view path)
{
return fs::canonical(path).parent_path().string();
}
std::string directory_manager::contentOfPath(std::string_view path)
std::string Manager::directory_manager::contentOfPath(std::string_view path)
{
std::string configPath(path);
std::fstream a(configPath, std::ios::in);
@@ -52,21 +52,21 @@ std::string directory_manager::contentOfPath(std::string_view path)
return s.str();
}
nlohmann::json directory_manager::credentialConfigContent(const std::string& exe_path)
nlohmann::json Manager::directory_manager::credentialConfigContent(const std::string& exe_path)
{
auto path = configPath(exe_path);
path.append("/authcredentials.json");
return nlohmann::json::parse(contentOfPath(path));
}
nlohmann::json directory_manager::databaseConfigContent(const std::string& exe_path)
nlohmann::json Manager::directory_manager::databaseConfigContent(const std::string& exe_path)
{
auto path = configPath(exe_path);
path.append("/database.json");
return nlohmann::json::parse(contentOfPath(path));
}
nlohmann::json directory_manager::pathConfigContent(const std::string& exe_path)
nlohmann::json Manager::directory_manager::pathConfigContent(const std::string& exe_path)
{
auto path = configPath(exe_path);
path.append("/paths.json");
@@ -74,7 +74,7 @@ nlohmann::json directory_manager::pathConfigContent(const std::string& exe_path)
return nlohmann::json::parse(contentOfPath(path));
}
void directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
void Manager::directory_manager::delete_cover_art_file(const std::string& cov_path, const std::string& stock_cover_path)
{
if (cov_path.compare(stock_cover_path) == 0) {
std::cout << "cover has stock cover art, will not deleted" << std::endl;
@@ -84,7 +84,7 @@ void directory_manager::delete_cover_art_file(const std::string& cov_path, const
fs::remove(cov);
}
}
void directory_manager::delete_directories(Model::Song song, const std::string& root_path)
void Manager::directory_manager::delete_directories(Model::Song song, const std::string& root_path)
{
std::cout<<"checking to for empty directories to delete"<<std::endl;
const std::string art{root_path + std::string{"/"} + song.artist};
@@ -109,7 +109,7 @@ void directory_manager::delete_directories(Model::Song song, const std::string&
std::cout<<"deleted empty directory or directories"<<std::endl;
}
void directory_manager::delete_song(const Model::Song song)
void Manager::directory_manager::delete_song(const Model::Song song)
{
std::cout<<"deleting song"<<std::endl;
auto song_path = fs::path(song.songPath);
+12 -12
View File
@@ -14,12 +14,12 @@
namespace fs = std::filesystem;
song_manager::song_manager(std::string& x_path)
Manager::song_manager::song_manager(std::string& x_path)
: exe_path(x_path)
{ }
void song_manager::saveSong(Model::Song& song)
void Manager::song_manager::saveSong(Model::Song& song)
{
saveSongTemp(song);
metadata_retriever meta;
@@ -28,17 +28,17 @@ void song_manager::saveSong(Model::Song& song)
song.data = std::move(data);
coverArtManager covMgr(exe_path);
auto pathConfigContent = directory_manager::pathConfigContent(exe_path);
auto pathConfigContent = Manager::directory_manager::pathConfigContent(exe_path);
auto coverRootPath = pathConfigContent["cover_root_path"].get<std::string>();
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
auto stockCoverPath = directory_manager::configPath(exe_path);
auto stockCoverPath = Manager::directory_manager::configPath(exe_path);
stockCoverPath.append("/CoverArt.png");
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
song.coverArtId = cov.id;
auto songPath = directory_manager::create_directory_process(song, musicRootPath);
auto songPath = Manager::directory_manager::create_directory_process(song, musicRootPath);
songPath.append(song.title);
songPath.append(".mp3");
std::cout << "\n\ntemp path: " << song.songPath << std::endl;
@@ -53,7 +53,7 @@ void song_manager::saveSong(Model::Song& song)
songRepo.saveRecord(song);
}
void song_manager::deleteSong(Model::Song& song)
void Manager::song_manager::deleteSong(Model::Song& song)
{
coverArtRepository covRepo(exe_path);
songRepository songRepo(exe_path);
@@ -66,7 +66,7 @@ void song_manager::deleteSong(Model::Song& song)
cov = covRepo.retrieveRecord(cov, coverFilter::id);
covRepo.deleteRecord(cov);
auto paths = directory_manager::pathConfigContent(exe_path);
auto paths = Manager::directory_manager::pathConfigContent(exe_path);
const auto coverArtPath = paths["cover_root_path"].get<std::string>();
std::string stockCoverArtPath = coverArtPath;
stockCoverArtPath.append("CoverArt.png");
@@ -77,11 +77,11 @@ void song_manager::deleteSong(Model::Song& song)
}
fs::remove(song.songPath);
directory_manager::delete_directories(song, paths["root_music_path"].get<std::string>());
directory_manager::delete_directories(song, coverArtPath);
Manager::directory_manager::delete_directories(song, paths["root_music_path"].get<std::string>());
Manager::directory_manager::delete_directories(song, coverArtPath);
}
void song_manager::printSong(const Model::Song& song)
void Manager::song_manager::printSong(const Model::Song& song)
{
std::cout << "\n\nsong" << std::endl;
std::cout << "title: " << song.title << std::endl;
@@ -98,9 +98,9 @@ void song_manager::printSong(const Model::Song& song)
}
}
void song_manager::saveSongTemp(Model::Song& song)
void Manager::song_manager::saveSongTemp(Model::Song& song)
{
auto config = directory_manager::pathConfigContent(exe_path);
auto config = Manager::directory_manager::pathConfigContent(exe_path);
auto tmp_song = config["temp_root_path"].get<std::string>();
std::random_device dev;
+10 -10
View File
@@ -17,11 +17,11 @@
namespace fs = std::filesystem;
token_manager::token_manager()
Manager::token_manager::token_manager()
{
}
Model::loginResult token_manager::retrieve_token()
Model::loginResult Manager::token_manager::retrieve_token()
{
Model::loginResult lr;
lr.access_token = "dsfdsf";
@@ -29,7 +29,7 @@ Model::loginResult token_manager::retrieve_token()
return lr;
}
Model::loginResult token_manager::retrieve_token(std::string_view path)
Model::loginResult Manager::token_manager::retrieve_token(std::string_view path)
{
auto cred = parse_auth_credentials(path);
@@ -58,7 +58,7 @@ Model::loginResult token_manager::retrieve_token(std::string_view path)
return lr;
}
bool token_manager::is_token_valid(std::string& auth, Scope scope)
bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
{
auto authPair = fetch_auth_header(auth);
@@ -87,12 +87,12 @@ bool token_manager::is_token_valid(std::string& auth, Scope scope)
return false;
}
Model::auth_credentials token_manager::parse_auth_credentials(std::string_view path)
Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::string_view path)
{
auto exe_path = directory_manager::configPath(path);
auto exe_path = Manager::directory_manager::configPath(path);
exe_path.append("/authcredentials.json");
auto con = directory_manager::credentialConfigContent(exe_path);
auto con = Manager::directory_manager::credentialConfigContent(exe_path);
Model::auth_credentials auth;
auth.uri = "https://";
@@ -105,7 +105,7 @@ Model::auth_credentials token_manager::parse_auth_credentials(std::string_view p
return auth;
}
std::vector<std::string> token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
std::vector<std::string> Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
{
std::vector<std::string> scopes;
@@ -123,7 +123,7 @@ std::vector<std::string> token_manager::extract_scopes(const jwt::decoded_jwt&&
return scopes;
}
std::pair<bool, std::vector<std::string>> token_manager::fetch_auth_header(const std::string& auth)
std::pair<bool, std::vector<std::string>> Manager::token_manager::fetch_auth_header(const std::string& auth)
{
std::istringstream iss(auth);
std::vector<std::string> authHeader{std::istream_iterator<std::string>(iss),
@@ -142,7 +142,7 @@ std::pair<bool, std::vector<std::string>> token_manager::fetch_auth_header(const
return std::make_pair(foundBearer, authHeader);
}
bool token_manager::token_supports_scope(const std::vector<std::string> scopes, const std::string&& scope)
bool Manager::token_manager::token_supports_scope(const std::vector<std::string> scopes, const std::string&& scope)
{
return std::any_of(scopes.begin(), scopes.end(),
[&](std::string foundScope) {
+2 -2
View File
@@ -76,8 +76,8 @@ Model::Cover metadata_retriever::update_cover_art(const Model::Song& song, Model
} else {
auto frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(
frameList.front());
directory_manager dir;
auto img_path = dir.create_directory_process(song, cov.imagePath);
auto img_path = Manager::directory_manager::create_directory_process(song, cov.imagePath);
img_path.append(song.title);
img_path.append(".png");
cov.imagePath = img_path;