From d16b8dc3c92e48f8287650a2c77e395b3b9f008a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 1 Sep 2019 14:14:46 -0400 Subject: [PATCH] Added Manager namespace --- include/managers/coverArtManager.h | 17 +++++++++------- include/managers/directory_manager.h | 30 +++++++++++++++------------- include/managers/song_manager.h | 23 +++++++++++---------- include/managers/token_manager.h | 27 ++++++++++++++----------- src/controller/loginController.hpp | 2 +- src/controller/songController.hpp | 6 +++--- src/database/base_repository.cpp | 2 +- src/managers/coverArtManager.cpp | 4 ++-- src/managers/directory_manager.cpp | 18 ++++++++--------- src/managers/song_manager.cpp | 24 +++++++++++----------- src/managers/token_manager.cpp | 20 +++++++++---------- src/utilities/metadata_retriever.cpp | 4 ++-- 12 files changed, 94 insertions(+), 83 deletions(-) diff --git a/include/managers/coverArtManager.h b/include/managers/coverArtManager.h index 58c4cec..9ba399f 100644 --- a/include/managers/coverArtManager.h +++ b/include/managers/coverArtManager.h @@ -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 diff --git a/include/managers/directory_manager.h b/include/managers/directory_manager.h index af3ca37..48a293d 100644 --- a/include/managers/directory_manager.h +++ b/include/managers/directory_manager.h @@ -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 diff --git a/include/managers/song_manager.h b/include/managers/song_manager.h index e12a87c..1309411 100644 --- a/include/managers/song_manager.h +++ b/include/managers/song_manager.h @@ -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 diff --git a/include/managers/token_manager.h b/include/managers/token_manager.h index eafc9a5..e80df7b 100644 --- a/include/managers/token_manager.h +++ b/include/managers/token_manager.h @@ -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 extract_scopes(const jwt::decoded_jwt&&); - std::pair> fetch_auth_header(const std::string&); + std::vector extract_scopes(const jwt::decoded_jwt&&); + std::pair> fetch_auth_header(const std::string&); - bool token_supports_scope(const std::vector, const std::string&&); -}; + bool token_supports_scope(const std::vector, const std::string&&); + }; +} #endif diff --git a/src/controller/loginController.hpp b/src/controller/loginController.hpp index 35460e9..02b57b4 100644 --- a/src/controller/loginController.hpp +++ b/src/controller/loginController.hpp @@ -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(); diff --git a/src/controller/songController.hpp b/src/controller/songController.hpp index 6c203a5..1dbfee5 100644 --- a/src/controller/songController.hpp +++ b/src/controller/songController.hpp @@ -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(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"); diff --git a/src/database/base_repository.cpp b/src/database/base_repository.cpp index c405461..30385e9 100644 --- a/src/database/base_repository.cpp +++ b/src/database/base_repository.cpp @@ -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(); details.password = databaseConfig["password"].get(); diff --git a/src/managers/coverArtManager.cpp b/src/managers/coverArtManager.cpp index f732b25..e72b417 100644 --- a/src/managers/coverArtManager.cpp +++ b/src/managers/coverArtManager.cpp @@ -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; diff --git a/src/managers/directory_manager.cpp b/src/managers/directory_manager.cpp index c8b8acc..4d765d0 100644 --- a/src/managers/directory_manager.cpp +++ b/src/managers/directory_manager.cpp @@ -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"<(); auto musicRootPath = pathConfigContent["root_music_path"].get(); - 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 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()); - directory_manager::delete_directories(song, coverArtPath); + Manager::directory_manager::delete_directories(song, paths["root_music_path"].get()); + 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::random_device dev; diff --git a/src/managers/token_manager.cpp b/src/managers/token_manager.cpp index c5c2e87..247e541 100644 --- a/src/managers/token_manager.cpp +++ b/src/managers/token_manager.cpp @@ -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 token_manager::extract_scopes(const jwt::decoded_jwt&& decoded) +std::vector Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded) { std::vector scopes; @@ -123,7 +123,7 @@ std::vector token_manager::extract_scopes(const jwt::decoded_jwt&& return scopes; } -std::pair> token_manager::fetch_auth_header(const std::string& auth) +std::pair> Manager::token_manager::fetch_auth_header(const std::string& auth) { std::istringstream iss(auth); std::vector authHeader{std::istream_iterator(iss), @@ -142,7 +142,7 @@ std::pair> token_manager::fetch_auth_header(const return std::make_pair(foundBearer, authHeader); } -bool token_manager::token_supports_scope(const std::vector scopes, const std::string&& scope) +bool Manager::token_manager::token_supports_scope(const std::vector scopes, const std::string&& scope) { return std::any_of(scopes.begin(), scopes.end(), [&](std::string foundScope) { diff --git a/src/utilities/metadata_retriever.cpp b/src/utilities/metadata_retriever.cpp index c39c532..d3ad3cb 100644 --- a/src/utilities/metadata_retriever.cpp +++ b/src/utilities/metadata_retriever.cpp @@ -76,8 +76,8 @@ Model::Cover metadata_retriever::update_cover_art(const Model::Song& song, Model } else { auto frame = dynamic_cast( 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;