diff --git a/CMakeLists.txt b/CMakeLists.txt index 462216f..eed89b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,27 +9,43 @@ set(SOURCES src/appComponent.hpp src/controller/loginController.hpp src/controller/songController.hpp + src/database/albumRepository.cpp + src/database/artistRepository.cpp src/database/base_repository.cpp src/database/coverArtRepository.cpp + src/database/genreRepository.cpp src/database/songRepository.cpp + src/database/yearRepository.cpp src/dto/loginResultDto.hpp src/dto/songDto.hpp src/main.cpp + src/managers/albumManager.cpp + src/managers/artistManager.cpp src/managers/coverArtManager.cpp src/managers/directory_manager.cpp + src/managers/genreManager.cpp src/managers/song_manager.cpp src/managers/token_manager.cpp + src/managers/yearManager.cpp src/utilities/imageFile.cpp src/utilities/metadata_retriever.cpp ) set(HEADERS + include/database/albumRepository.h + include/database/artistRepository.h include/database/base_repository.h include/database/coverArtRepository.h + include/database/genreRepository.h include/database/songRepository.h + include/database/yearRepository.h + include/managers/albumManager.h + include/managers/artistManager.h include/managers/coverArtManager.h include/managers/directory_manager.h + include/managers/genreManager.h include/managers/song_manager.h include/managers/token_manager.h + include/managers/yearManager.h include/models/models.h include/utilities/imageFile.h include/utilities/metadata_retriever.h diff --git a/include/database/albumRepository.h b/include/database/albumRepository.h new file mode 100644 index 0000000..e69de29 diff --git a/include/database/artistRepository.h b/include/database/artistRepository.h new file mode 100644 index 0000000..f104a8a --- /dev/null +++ b/include/database/artistRepository.h @@ -0,0 +1,18 @@ +#ifndef ARTISTREPOSITORY_H_ +#define ARTISTREPOSITORY_H_ + +#include "database/base_repository.h" +#include "models/models.h" +#include "types/coverFilter.h" + +namespace Database +{ + class artistRepository : public base_repository + { + public: + artistRepository(const Model::BinaryPath&); + private: + }; +} + +#endif diff --git a/include/database/base_repository.h b/include/database/base_repository.h index dcc3527..ad63c95 100644 --- a/include/database/base_repository.h +++ b/include/database/base_repository.h @@ -7,22 +7,27 @@ #include "models/models.h" -class base_repository +namespace Database { -public: - base_repository(); - base_repository(const std::string&); -protected: - MYSQL* setup_mysql_connection(); - MYSQL* setup_mysql_connection(Model::database_connection); + class base_repository + { + public: + base_repository(); + base_repository(const std::string&); + base_repository(const BinaryPath&); + protected: + MYSQL* setup_mysql_connection(); + MYSQL* setup_mysql_connection(Model::database_connection); - MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&); + MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&); - Model::database_connection details; -private: - void intitalizeDetails(); + Model::database_connection details; + private: + void intitalizeDetails(); - std::string path; -}; + std::string path; + Model::BinaryPath m_binConf; + }; +} #endif diff --git a/include/database/genreRepository.h b/include/database/genreRepository.h new file mode 100644 index 0000000..e69de29 diff --git a/include/database/yearRepository.h b/include/database/yearRepository.h new file mode 100644 index 0000000..e69de29 diff --git a/include/managers/albumManager.h b/include/managers/albumManager.h new file mode 100644 index 0000000..e69de29 diff --git a/include/managers/artistManager.h b/include/managers/artistManager.h new file mode 100644 index 0000000..e69de29 diff --git a/include/managers/genreManager.h b/include/managers/genreManager.h new file mode 100644 index 0000000..e69de29 diff --git a/include/managers/token_manager.h b/include/managers/token_manager.h index e80df7b..9407674 100644 --- a/include/managers/token_manager.h +++ b/include/managers/token_manager.h @@ -20,10 +20,12 @@ namespace Manager Model::loginResult retrieve_token(); Model::loginResult retrieve_token(std::string_view); + Model::loginResult retrieve_token(const BinaryPath&); bool is_token_valid(std::string&, Scope); private: Model::auth_credentials parse_auth_credentials(std::string_view); + Model::auth_credentials parse_auth_credentials(const BinaryPath&); std::vector extract_scopes(const jwt::decoded_jwt&&); std::pair> fetch_auth_header(const std::string&); diff --git a/include/managers/yearManager.h b/include/managers/yearManager.h new file mode 100644 index 0000000..e69de29 diff --git a/include/models/models.h b/include/models/models.h index b755ed5..2d30e01 100644 --- a/include/models/models.h +++ b/include/models/models.h @@ -20,6 +20,16 @@ namespace Model std::string songPath; std::vector data; int coverArtId; + int artistId; + int albumId; + int genreId; + int yearId; + }; + + struct Artist + { + int id; + std::string artist; }; struct Album @@ -30,6 +40,19 @@ namespace Model std::vector songs; }; + struct Genre + { + int id; + std::string category; + + }; + + struct Year + { + int id; + int year; + }; + struct Cover { int id; @@ -39,16 +62,6 @@ namespace Model std::vector data; }; - struct LoginRes - { - int UserId; - char Username[1024]; - char Token[1024]; - char TokenType[1024]; - char Message[1024]; - int Expiration; - }; - struct loginResult { int user_id; @@ -76,6 +89,11 @@ namespace Model std::string password; std::string database; }; + + struct BinaryPath + { + std::string path; + }; } #endif diff --git a/src/controller/loginController.hpp b/src/controller/loginController.hpp index 02b57b4..4c0a0be 100644 --- a/src/controller/loginController.hpp +++ b/src/controller/loginController.hpp @@ -18,6 +18,9 @@ public: loginController(std::string p, OATPP_COMPONENT(std::shared_ptr, objectMapper)) : oatpp::web::server::api::ApiController(objectMapper), exe_path(p) { } + loginController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr, objectMapper)) + :oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) + { } #include OATPP_CODEGEN_BEGIN(ApiController) @@ -27,7 +30,8 @@ public: OATPP_LOGI("icarus", "logging in"); Manager::token_manager tok; - auto token = tok.retrieve_token(exe_path); + //auto token = tok.retrieve_token(exe_path); + auto token = tok.retrieve_token(bconf); auto logRes = loginResultDto::createShared(); logRes->id = 0; // TODO: change this later on to something meaningful @@ -43,6 +47,7 @@ public: #include OATPP_CODEGEN_END(ApiController) private: std::string exe_path; + Model::BinaryPath m_bConf; }; #endif diff --git a/src/controller/songController.hpp b/src/controller/songController.hpp index 1dbfee5..cb1718f 100644 --- a/src/controller/songController.hpp +++ b/src/controller/songController.hpp @@ -80,7 +80,7 @@ public: REQUEST(std::shared_ptr, request)) { std::cout << "starting process of retrieving songs" << std::endl; - songRepository songRepo(m_exe_path); + Database::songRepository songRepo(m_exe_path); auto songsDb = songRepo.retrieveRecords(); auto songs = oatpp::data::mapping::type::List::createShared(); @@ -107,7 +107,7 @@ public: ENDPOINT("GET", "/api/v1/song/{id}", songRecord, PATH(Int32, id)) { - songRepository songRepo(m_exe_path); + Database::songRepository songRepo(m_exe_path); Model::Song songDb; songDb.id = id; @@ -130,7 +130,7 @@ public: ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong, PATH(Int32, id)) { - songRepository songRepo(m_exe_path); + Database::songRepository songRepo(m_exe_path); Model::Song songDb; songDb.id = id; songDb = songRepo.retrieveRecord(songDb, songFilter::id); diff --git a/src/database/albumRepository.cpp b/src/database/albumRepository.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/database/artistRepository.cpp b/src/database/artistRepository.cpp new file mode 100644 index 0000000..4d5fb35 --- /dev/null +++ b/src/database/artistRepository.cpp @@ -0,0 +1,6 @@ +#include "database/artistRepository.h" + +Database::artistRepository::artistRepository(const Model::BinaryPath& binConf) + : base_repository(binConf) +{ +} diff --git a/src/database/genreRepository.cpp b/src/database/genreRepository.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/database/yearRepository.cpp b/src/database/yearRepository.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/main.cpp b/src/main.cpp index d395bb6..2ef6f01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,14 +17,15 @@ namespace fs = std::filesystem; -void run(const std::string& working_path) +//void run(const std::string& working_path) +void run(const Model::BinaryPath& bConf) { appComponent component; OATPP_COMPONENT(std::shared_ptr, router); - auto logController = std::make_shared(working_path); - auto sngController = std::make_shared(working_path); + auto logController = std::make_shared(bConf); + auto sngController = std::make_shared(bConf); logController->addEndpointsToRouter(router); sngController->addEndpointsToRouter(router); @@ -42,9 +43,12 @@ void run(const std::string& working_path) int main(int argc, char **argv) { oatpp::base::Environment::init(); - const std::string working_path = argv[0]; + //const std::string working_path = argv[0]; + Model::BinaryPath bConf; + bConf.path = argv[0] - run(working_path); + //run(working_path); + run(bConf); oatpp::base::Environment::destroy(); diff --git a/src/managers/albumManager.cpp b/src/managers/albumManager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/managers/artistManager.cpp b/src/managers/artistManager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/managers/coverArtManager.cpp b/src/managers/coverArtManager.cpp index e72b417..350a80f 100644 --- a/src/managers/coverArtManager.cpp +++ b/src/managers/coverArtManager.cpp @@ -16,7 +16,7 @@ Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::s cov = meta.update_cover_art(song, cov, stockCoverPath); cov.songTitle = song.title; - coverArtRepository covRepo(path); + Database::coverArtRepository covRepo(path); std::cout << "saving record to the database" << std::endl; covRepo.saveRecord(cov); std::cout << "retrieving record from database" << std::endl; diff --git a/src/managers/genreManager.cpp b/src/managers/genreManager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/managers/song_manager.cpp b/src/managers/song_manager.cpp index 4614e5c..c1244a1 100644 --- a/src/managers/song_manager.cpp +++ b/src/managers/song_manager.cpp @@ -49,14 +49,14 @@ void Manager::song_manager::saveSong(Model::Song& song) printSong(song); - songRepository songRepo(exe_path); + Database::songRepository songRepo(exe_path); songRepo.saveRecord(song); } void Manager::song_manager::deleteSong(Model::Song& song) { - coverArtRepository covRepo(exe_path); - songRepository songRepo(exe_path); + Database::coverArtRepository covRepo(exe_path); + Database::songRepository songRepo(exe_path); song = songRepo.retrieveRecord(song, songFilter::id); songRepo.deleteRecord(song); diff --git a/src/managers/token_manager.cpp b/src/managers/token_manager.cpp index 247e541..c4e04ec 100644 --- a/src/managers/token_manager.cpp +++ b/src/managers/token_manager.cpp @@ -104,6 +104,23 @@ Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::stri return auth; } +Model::auth_credentials Manager::token_manager::parse_auth_credentials(const BinaryPath& bConf) +{ + auto exePath = Manager::directory_manager::configPath(bConf); + exe_path.append("/auth_credentials.json"); + + auto con = Manager::directory_manager::credentialConfigContent(exePath); + + Model::auth_credentials auth; + auth.uri = "https://"; + auth.uri.append(con["domain"]); + auth.api_identifier = con["api_identifier"]; + auth.client_id = con["client_id"]; + auth.client_secret = con["client_secret"]; + auth.endpoint = "oauth/token"; + + return auth; +} std::vector Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded) { diff --git a/src/managers/yearManager.cpp b/src/managers/yearManager.cpp new file mode 100644 index 0000000..e69de29