Added manager classes for song metadata
This commit is contained in:
@@ -9,27 +9,43 @@ set(SOURCES
|
|||||||
src/appComponent.hpp
|
src/appComponent.hpp
|
||||||
src/controller/loginController.hpp
|
src/controller/loginController.hpp
|
||||||
src/controller/songController.hpp
|
src/controller/songController.hpp
|
||||||
|
src/database/albumRepository.cpp
|
||||||
|
src/database/artistRepository.cpp
|
||||||
src/database/base_repository.cpp
|
src/database/base_repository.cpp
|
||||||
src/database/coverArtRepository.cpp
|
src/database/coverArtRepository.cpp
|
||||||
|
src/database/genreRepository.cpp
|
||||||
src/database/songRepository.cpp
|
src/database/songRepository.cpp
|
||||||
|
src/database/yearRepository.cpp
|
||||||
src/dto/loginResultDto.hpp
|
src/dto/loginResultDto.hpp
|
||||||
src/dto/songDto.hpp
|
src/dto/songDto.hpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
|
src/managers/albumManager.cpp
|
||||||
|
src/managers/artistManager.cpp
|
||||||
src/managers/coverArtManager.cpp
|
src/managers/coverArtManager.cpp
|
||||||
src/managers/directory_manager.cpp
|
src/managers/directory_manager.cpp
|
||||||
|
src/managers/genreManager.cpp
|
||||||
src/managers/song_manager.cpp
|
src/managers/song_manager.cpp
|
||||||
src/managers/token_manager.cpp
|
src/managers/token_manager.cpp
|
||||||
|
src/managers/yearManager.cpp
|
||||||
src/utilities/imageFile.cpp
|
src/utilities/imageFile.cpp
|
||||||
src/utilities/metadata_retriever.cpp
|
src/utilities/metadata_retriever.cpp
|
||||||
)
|
)
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
|
include/database/albumRepository.h
|
||||||
|
include/database/artistRepository.h
|
||||||
include/database/base_repository.h
|
include/database/base_repository.h
|
||||||
include/database/coverArtRepository.h
|
include/database/coverArtRepository.h
|
||||||
|
include/database/genreRepository.h
|
||||||
include/database/songRepository.h
|
include/database/songRepository.h
|
||||||
|
include/database/yearRepository.h
|
||||||
|
include/managers/albumManager.h
|
||||||
|
include/managers/artistManager.h
|
||||||
include/managers/coverArtManager.h
|
include/managers/coverArtManager.h
|
||||||
include/managers/directory_manager.h
|
include/managers/directory_manager.h
|
||||||
|
include/managers/genreManager.h
|
||||||
include/managers/song_manager.h
|
include/managers/song_manager.h
|
||||||
include/managers/token_manager.h
|
include/managers/token_manager.h
|
||||||
|
include/managers/yearManager.h
|
||||||
include/models/models.h
|
include/models/models.h
|
||||||
include/utilities/imageFile.h
|
include/utilities/imageFile.h
|
||||||
include/utilities/metadata_retriever.h
|
include/utilities/metadata_retriever.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
|
||||||
@@ -7,11 +7,14 @@
|
|||||||
|
|
||||||
#include "models/models.h"
|
#include "models/models.h"
|
||||||
|
|
||||||
|
namespace Database
|
||||||
|
{
|
||||||
class base_repository
|
class base_repository
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
base_repository();
|
base_repository();
|
||||||
base_repository(const std::string&);
|
base_repository(const std::string&);
|
||||||
|
base_repository(const BinaryPath&);
|
||||||
protected:
|
protected:
|
||||||
MYSQL* setup_mysql_connection();
|
MYSQL* setup_mysql_connection();
|
||||||
MYSQL* setup_mysql_connection(Model::database_connection);
|
MYSQL* setup_mysql_connection(Model::database_connection);
|
||||||
@@ -23,6 +26,8 @@ private:
|
|||||||
void intitalizeDetails();
|
void intitalizeDetails();
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
Model::BinaryPath m_binConf;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,10 +20,12 @@ namespace Manager
|
|||||||
|
|
||||||
Model::loginResult retrieve_token();
|
Model::loginResult retrieve_token();
|
||||||
Model::loginResult retrieve_token(std::string_view);
|
Model::loginResult retrieve_token(std::string_view);
|
||||||
|
Model::loginResult retrieve_token(const BinaryPath&);
|
||||||
|
|
||||||
bool is_token_valid(std::string&, Scope);
|
bool is_token_valid(std::string&, Scope);
|
||||||
private:
|
private:
|
||||||
Model::auth_credentials parse_auth_credentials(std::string_view);
|
Model::auth_credentials parse_auth_credentials(std::string_view);
|
||||||
|
Model::auth_credentials parse_auth_credentials(const BinaryPath&);
|
||||||
|
|
||||||
std::vector<std::string> extract_scopes(const jwt::decoded_jwt&&);
|
std::vector<std::string> extract_scopes(const jwt::decoded_jwt&&);
|
||||||
std::pair<bool, std::vector<std::string>> fetch_auth_header(const std::string&);
|
std::pair<bool, std::vector<std::string>> fetch_auth_header(const std::string&);
|
||||||
|
|||||||
+28
-10
@@ -20,6 +20,16 @@ namespace Model
|
|||||||
std::string songPath;
|
std::string songPath;
|
||||||
std::vector<unsigned char> data;
|
std::vector<unsigned char> data;
|
||||||
int coverArtId;
|
int coverArtId;
|
||||||
|
int artistId;
|
||||||
|
int albumId;
|
||||||
|
int genreId;
|
||||||
|
int yearId;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Artist
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
std::string artist;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Album
|
struct Album
|
||||||
@@ -30,6 +40,19 @@ namespace Model
|
|||||||
std::vector<Song> songs;
|
std::vector<Song> songs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Genre
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
std::string category;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Year
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
int year;
|
||||||
|
};
|
||||||
|
|
||||||
struct Cover
|
struct Cover
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
@@ -39,16 +62,6 @@ namespace Model
|
|||||||
std::vector<unsigned char> data;
|
std::vector<unsigned char> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LoginRes
|
|
||||||
{
|
|
||||||
int UserId;
|
|
||||||
char Username[1024];
|
|
||||||
char Token[1024];
|
|
||||||
char TokenType[1024];
|
|
||||||
char Message[1024];
|
|
||||||
int Expiration;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct loginResult
|
struct loginResult
|
||||||
{
|
{
|
||||||
int user_id;
|
int user_id;
|
||||||
@@ -76,6 +89,11 @@ namespace Model
|
|||||||
std::string password;
|
std::string password;
|
||||||
std::string database;
|
std::string database;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BinaryPath
|
||||||
|
{
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public:
|
|||||||
loginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
loginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||||
: oatpp::web::server::api::ApiController(objectMapper), exe_path(p)
|
: oatpp::web::server::api::ApiController(objectMapper), exe_path(p)
|
||||||
{ }
|
{ }
|
||||||
|
loginController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||||
|
:oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||||
@@ -27,7 +30,8 @@ public:
|
|||||||
OATPP_LOGI("icarus", "logging in");
|
OATPP_LOGI("icarus", "logging in");
|
||||||
|
|
||||||
Manager::token_manager tok;
|
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();
|
auto logRes = loginResultDto::createShared();
|
||||||
logRes->id = 0; // TODO: change this later on to something meaningful
|
logRes->id = 0; // TODO: change this later on to something meaningful
|
||||||
@@ -43,6 +47,7 @@ public:
|
|||||||
#include OATPP_CODEGEN_END(ApiController)
|
#include OATPP_CODEGEN_END(ApiController)
|
||||||
private:
|
private:
|
||||||
std::string exe_path;
|
std::string exe_path;
|
||||||
|
Model::BinaryPath m_bConf;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
||||||
{
|
{
|
||||||
std::cout << "starting process of retrieving songs" << std::endl;
|
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 songsDb = songRepo.retrieveRecords();
|
||||||
auto songs = oatpp::data::mapping::type::List<songDto::ObjectWrapper>::createShared();
|
auto songs = oatpp::data::mapping::type::List<songDto::ObjectWrapper>::createShared();
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public:
|
|||||||
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
||||||
PATH(Int32, id)) {
|
PATH(Int32, id)) {
|
||||||
|
|
||||||
songRepository songRepo(m_exe_path);
|
Database::songRepository songRepo(m_exe_path);
|
||||||
Model::Song songDb;
|
Model::Song songDb;
|
||||||
songDb.id = id;
|
songDb.id = id;
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ public:
|
|||||||
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
||||||
PATH(Int32, id)) {
|
PATH(Int32, id)) {
|
||||||
|
|
||||||
songRepository songRepo(m_exe_path);
|
Database::songRepository songRepo(m_exe_path);
|
||||||
Model::Song songDb;
|
Model::Song songDb;
|
||||||
songDb.id = id;
|
songDb.id = id;
|
||||||
songDb = songRepo.retrieveRecord(songDb, songFilter::id);
|
songDb = songRepo.retrieveRecord(songDb, songFilter::id);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#include "database/artistRepository.h"
|
||||||
|
|
||||||
|
Database::artistRepository::artistRepository(const Model::BinaryPath& binConf)
|
||||||
|
: base_repository(binConf)
|
||||||
|
{
|
||||||
|
}
|
||||||
+9
-5
@@ -17,14 +17,15 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
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;
|
appComponent component;
|
||||||
|
|
||||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||||
|
|
||||||
auto logController = std::make_shared<loginController>(working_path);
|
auto logController = std::make_shared<loginController>(bConf);
|
||||||
auto sngController = std::make_shared<songController>(working_path);
|
auto sngController = std::make_shared<songController>(bConf);
|
||||||
logController->addEndpointsToRouter(router);
|
logController->addEndpointsToRouter(router);
|
||||||
sngController->addEndpointsToRouter(router);
|
sngController->addEndpointsToRouter(router);
|
||||||
|
|
||||||
@@ -42,9 +43,12 @@ void run(const std::string& working_path)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
oatpp::base::Environment::init();
|
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();
|
oatpp::base::Environment::destroy();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::s
|
|||||||
cov = meta.update_cover_art(song, cov, stockCoverPath);
|
cov = meta.update_cover_art(song, cov, stockCoverPath);
|
||||||
cov.songTitle = song.title;
|
cov.songTitle = song.title;
|
||||||
|
|
||||||
coverArtRepository covRepo(path);
|
Database::coverArtRepository covRepo(path);
|
||||||
std::cout << "saving record to the database" << std::endl;
|
std::cout << "saving record to the database" << std::endl;
|
||||||
covRepo.saveRecord(cov);
|
covRepo.saveRecord(cov);
|
||||||
std::cout << "retrieving record from database" << std::endl;
|
std::cout << "retrieving record from database" << std::endl;
|
||||||
|
|||||||
@@ -49,14 +49,14 @@ void Manager::song_manager::saveSong(Model::Song& song)
|
|||||||
|
|
||||||
printSong(song);
|
printSong(song);
|
||||||
|
|
||||||
songRepository songRepo(exe_path);
|
Database::songRepository songRepo(exe_path);
|
||||||
songRepo.saveRecord(song);
|
songRepo.saveRecord(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Manager::song_manager::deleteSong(Model::Song& song)
|
void Manager::song_manager::deleteSong(Model::Song& song)
|
||||||
{
|
{
|
||||||
coverArtRepository covRepo(exe_path);
|
Database::coverArtRepository covRepo(exe_path);
|
||||||
songRepository songRepo(exe_path);
|
Database::songRepository songRepo(exe_path);
|
||||||
|
|
||||||
song = songRepo.retrieveRecord(song, songFilter::id);
|
song = songRepo.retrieveRecord(song, songFilter::id);
|
||||||
songRepo.deleteRecord(song);
|
songRepo.deleteRecord(song);
|
||||||
|
|||||||
@@ -104,6 +104,23 @@ Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::stri
|
|||||||
|
|
||||||
return auth;
|
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<std::string> Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
|
std::vector<std::string> Manager::token_manager::extract_scopes(const jwt::decoded_jwt&& decoded)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user