Tidied up code, going to put up the coding convention later on

This commit is contained in:
amazing-username
2019-09-04 15:41:43 +00:00
parent dd995269df
commit d4e9b8c71f
73 changed files with 1334 additions and 1368 deletions
+48 -48
View File
@@ -6,56 +6,56 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(SOURCES
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/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
src/database/AlbumRepository.cpp
src/database/ArtistRepository.cpp
src/database/BaseRepository.cpp
src/database/CoverArtRepository.cpp
src/database/GenreRepository.cpp
src/database/SongRepository.cpp
src/database/YearRepository.cpp
src/Main.cpp
src/manager/AlbumManager.cpp
src/manager/ArtistManager.cpp
src/manager/CoverArtManager.cpp
src/manager/DirectoryManager.cpp
src/manager/GenreManager.cpp
src/manager/SongManager.cpp
src/manager/TokenManager.cpp
src/manager/YearManager.cpp
src/utility/ImageFile.cpp
src/utility/MetadataRetriever.cpp
)
set(HEADERS
include/component/appComponent.hpp
include/controller/loginController.hpp
include/controller/songController.hpp
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/dto/loginResultDto.hpp
include/dto/songDto.hpp
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
include/types/albumFilter.h
include/types/artistFilter.h
include/types/coverFilter.h
include/types/genreFilter.h
include/types/scopes.h
include/types/songFilter.h
include/types/yearFilter.h
include/component/AppComponent.hpp
include/controller/LoginController.hpp
include/controller/SongController.hpp
include/database/AlbumRepository.h
include/database/ArtistRepository.h
include/database/BaseRepository.h
include/database/CoverArtRepository.h
include/database/GenreRepository.h
include/database/SongRepository.h
include/database/YearRepository.h
include/dto/LoginResultDto.hpp
include/dto/SongDto.hpp
include/manager/AlbumManager.h
include/manager/ArtistManager.h
include/manager/CoverArtManager.h
include/manager/DirectoryManager.h
include/manager/GenreManager.h
include/manager/SongManager.h
include/manager/TokenManager.h
include/manager/YearManager.h
include/model/Models.h
include/utility/ImageFile.h
include/utility/MetadataRetriever.h
include/type/AlbumFilter.h
include/type/ArtistFilter.h
include/type/CoverFilter.h
include/type/GenreFilter.h
include/type/Scopes.h
include/type/SongFilter.h
include/type/YearFilter.h
)
set (TAGLIB
@@ -8,10 +8,10 @@
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/web/server/HttpConnectionHandler.hpp"
namespace Component
namespace component
{
class appComponent
class AppComponent
{
public:
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
@@ -9,35 +9,36 @@
#include "oatpp/core/macro/component.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "dto/loginResultDto.hpp"
#include "managers/token_manager.h"
#include "dto/LoginResultDto.hpp"
#include "manager/TokenManager.h"
#include "model/Models.h"
namespace Controller
namespace controller
{
class loginController : public oatpp::web::server::api::ApiController
class LoginController : public oatpp::web::server::api::ApiController
{
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)
{ }
loginController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
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)
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(Dto::userDto::ObjectWrapper, usr)) {
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
OATPP_LOGI("icarus", "logging in");
Manager::token_manager tok;
auto token = tok.retrieve_token(m_bConf);
manager::TokenManager tok;
auto token = tok.retrieveToken(m_bConf);
auto logRes = Dto::loginResultDto::createShared();
auto logRes = dto::LoginResultDto::createShared();
logRes->id = 0; // TODO: change this later on to something meaningful
logRes->username = usr->username->c_str();
logRes->token = token.access_token.c_str();
logRes->token_type = token.token_type.c_str();
logRes->token = token.accessToken.c_str();
logRes->token_type = token.tokenType.c_str();
logRes->expiration = token.expiration;
logRes->message = "Successful";
@@ -47,7 +48,7 @@ namespace Controller
#include OATPP_CODEGEN_END(ApiController)
private:
std::string exe_path;
Model::BinaryPath m_bConf;
model::BinaryPath m_bConf;
};
}
#endif
@@ -17,26 +17,26 @@
#include "oatpp/web/mime/multipart/Reader.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "database/songRepository.h"
#include "dto/songDto.hpp"
#include "managers/song_manager.h"
#include "managers/token_manager.h"
#include "models/models.h"
#include "types/scopes.h"
#include "types/songFilter.h"
#include "database/SongRepository.h"
#include "dto/SongDto.hpp"
#include "manager/SongManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h"
#include "type/Scopes.h"
#include "type/SongFilter.h"
namespace fs = std::filesystem;
namespace Controller
namespace controller
{
class songController : public oatpp::web::server::api::ApiController
class SongController : public oatpp::web::server::api::ApiController
{
public:
songController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
SongController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
{ }
songController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf)
{ }
@@ -52,8 +52,8 @@ namespace Controller
auto auth = authHeader->std_str();
Manager::token_manager tok;
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Type::Scope::upload), Status::CODE_403, "Not allowed");
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::upload), Status::CODE_403, "Not allowed");
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
@@ -72,11 +72,11 @@ namespace Controller
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
Model::Song sng;
model::Song sng;
sng.data = std::move(data);
Manager::song_manager s_mgr(m_bConf);
s_mgr.saveSong(sng);
manager::SongManager songMgr(m_bConf);
songMgr.saveSong(sng);
return createResponse(Status::CODE_200, "OK");
}
@@ -86,13 +86,13 @@ namespace Controller
REQUEST(std::shared_ptr<IncomingRequest>, request))
{
std::cout << "starting process of retrieving songs" << std::endl;
Database::songRepository songRepo(m_bConf);
database::SongRepository songRepo(m_bConf);
auto songsDb = songRepo.retrieveRecords();
auto songs = oatpp::data::mapping::type::List<Dto::songDto::ObjectWrapper>::createShared();
auto songs = oatpp::data::mapping::type::List<dto::SongDto::ObjectWrapper>::createShared();
std::cout << "creating object to send" << std::endl;
for (auto& songDb : songsDb) {
auto song = Dto::songDto::createShared();
auto song = dto::SongDto::createShared();
song->id = songDb.id;
song->title = songDb.title.c_str();
song->artist = songDb.artist.c_str();
@@ -113,16 +113,16 @@ namespace Controller
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
PATH(Int32, id)) {
Database::songRepository songRepo(m_bConf);
Model::Song songDb;
database::SongRepository songRepo(m_bConf);
model::Song songDb;
songDb.id = id;
OATPP_ASSERT_HTTP(songRepo.doesSongExist(songDb, Type::songFilter::id) , Status::CODE_403, "song does not exist");
OATPP_ASSERT_HTTP(songRepo.doesSongExist(songDb, type::SongFilter::id) , Status::CODE_403, "song does not exist");
std::cout << "song exists" << std::endl;
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
auto song = Dto::songDto::createShared();
auto song = dto::SongDto::createShared();
song->id = songDb.id;
song->title = songDb.title.c_str();
song->artist = songDb.artist.c_str();
@@ -139,10 +139,10 @@ namespace Controller
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
PATH(Int32, id)) {
Database::songRepository songRepo(m_bConf);
Model::Song songDb;
database::SongRepository songRepo(m_bConf);
model::Song songDb;
songDb.id = id;
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
std::ifstream fl(songDb.songPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
fl.seekg(0);
@@ -165,10 +165,10 @@ namespace Controller
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
Model::Song song;
model::Song song;
song.id = id;
Manager::song_manager sngMgr(m_bConf);
manager::SongManager sngMgr(m_bConf);
sngMgr.deleteSong(song);
return createResponse(Status::CODE_200, "OK");
@@ -179,7 +179,7 @@ namespace Controller
#include OATPP_CODEGEN_END(ApiController)
private:
std::string m_exe_path;
Model::BinaryPath m_bConf;
model::BinaryPath m_bConf;
const long m_dataSize = std::numeric_limits<long long int>::max();
};
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef ALBUMREPOSITORY_H_
#define ALBUMREPOSITORY_H_
#include <vector>
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/AlbumFilter.h"
namespace database
{
class AlbumRepository : public BaseRepository
{
public:
AlbumRepository(const model::BinaryPath&);
std::vector<model::Album> retrieveRecords();
model::Album retrieveRecord(model::Album&, type::AlbumFilter);
bool doesAlbumExists(const model::Album&, type::AlbumFilter);
void saveAlbum(const model::Album&);
private:
std::vector<model::Album> parseRecords(MYSQL_RES*);
// TODO: after parseRecord(MYSQL_STMT*) is implemented remove
// parseRecord(MYSQL_RES*)
model::Album parseRecord(MYSQL_RES*);
model::Album parseRecord(MYSQL_STMT*);
};
}
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef ARTISTREPOSITORY_H_
#define ARTISTREPOSITORY_H_
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/ArtistFilter.h"
namespace database
{
class ArtistRepository : public BaseRepository
{
public:
ArtistRepository(const model::BinaryPath&);
model::Artist retrieveRecord(model::Artist&, type::ArtistFilter);
bool doesArtistExist(const model::Artist&, type::ArtistFilter);
void saveRecord(const model::Artist&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
model::Artist parseRecord(MYSQL_RES*);
model::Artist parseRecord(MYSQL_STMT*);
};
}
#endif
+34
View File
@@ -0,0 +1,34 @@
#ifndef BASE_REPOSITORY_H_
#define BASE_REPOSITORY_H_
#include <string>
#include <mysql/mysql.h>
#include "model/Models.h"
namespace database
{
class BaseRepository
{
public:
BaseRepository();
BaseRepository(const std::string&);
BaseRepository(const model::BinaryPath&);
protected:
MYSQL* setupMysqlConnection();
MYSQL* setupMysqlConnection(model::DatabaseConnection);
MYSQL_RES* performMysqlQuery(MYSQL*, const std::string&);
model::DatabaseConnection details;
private:
void intitalizeDetails();
void initializeDetails(const model::BinaryPath&);
std::string path;
model::BinaryPath m_binConf;
};
}
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef COVERARTREPOSITORY_H_
#define COVERARTREPOSITORY_H_
#include <mysql/mysql.h>
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/CoverFilter.h"
namespace database
{
class CoverArtRepository : public BaseRepository
{
public:
CoverArtRepository(const std::string&);
CoverArtRepository(const model::BinaryPath&);
model::Cover retrieveRecord(model::Cover&, type::CoverFilter);
bool doesCoverArtExist(const model::Cover&, type::CoverFilter);
void deleteRecord(const model::Cover&);
void saveRecord(const model::Cover&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
model::Cover parseRecord(MYSQL_RES*);
model::Cover parseRecord(MYSQL_STMT*);
};
}
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef GENREREPOSITORY_H_
#define GENREREPOSITORY_H_
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/GenreFilter.h"
namespace database
{
class GenreRepository : public BaseRepository
{
public:
GenreRepository(const model::BinaryPath&);
model::Genre retrieveRecord(model::Genre&, type::GenreFilter);
bool doesGenreExist(const model::Genre&, type::GenreFilter);
void saveRecord(const model::Genre&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
model::Genre parseRecord(MYSQL_RES*);
model::Genre parseRecord(MYSQL_STMT*);
};
}
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef SONGREPOSITORY_H_
#define SONGREPOSITORY_H_
#include <memory>
#include <vector>
#include <mysql/mysql.h>
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/SongFilter.h"
namespace database
{
class SongRepository : public BaseRepository
{
public:
SongRepository(const std::string&);
SongRepository(const model::BinaryPath&);
std::vector<model::Song> retrieveRecords();
bool doesSongExist(const model::Song&, type::SongFilter);
model::Song retrieveRecord(model::Song&, type::SongFilter);
void deleteRecord(const model::Song&);
void saveRecord(const model::Song&);
private:
std::vector<model::Song> parseRecords(MYSQL_RES*); // TODO: to be removed
std::vector<model::Song> parseRecords(MYSQL_STMT*);
model::Song parseRecord(MYSQL_RES*); // TODO: to be removed
model::Song parseRecord(MYSQL_STMT*);
};
}
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef YEARREPOSITORY_H_
#define YEARREPOSITORY_H_
#include "database/BaseRepository.h"
#include "model/Models.h"
#include "type/YearFilter.h"
namespace database
{
class YearRepository : public BaseRepository
{
public:
YearRepository(const model::BinaryPath&);
model::Year retrieveRecord(model::Year&, type::YearFilter);
bool doesYearExist(const model::Year&, type::YearFilter);
void saveRecord(const model::Year&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
model::Year parseRecord(MYSQL_RES*);
model::Year parseRecord(MYSQL_STMT*);
};
}
#endif
-34
View File
@@ -1,34 +0,0 @@
#ifndef ALBUMREPOSITORY_H_
#define ALBUMREPOSITORY_H_
#include <vector>
#include "database/base_repository.h"
#include "models/models.h"
#include "types/albumFilter.h"
namespace Database
{
class albumRepository : public base_repository
{
public:
albumRepository(const Model::BinaryPath&);
std::vector<Model::Album> retrieveRecords();
Model::Album retrieveRecord(Model::Album&, Type::albumFilter);
bool doesAlbumExists(const Model::Album&, Type::albumFilter);
void saveAlbum(const Model::Album&);
private:
std::vector<Model::Album> parseRecords(MYSQL_RES*);
// TODO: after parseRecord(MYSQL_STMT*) is implemented remove
// parseRecord(MYSQL_RES*)
Model::Album parseRecord(MYSQL_RES*);
Model::Album parseRecord(MYSQL_STMT*);
};
}
#endif
-28
View File
@@ -1,28 +0,0 @@
#ifndef ARTISTREPOSITORY_H_
#define ARTISTREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
#include "types/artistFilter.h"
namespace Database
{
class artistRepository : public base_repository
{
public:
artistRepository(const Model::BinaryPath&);
Model::Artist retrieveRecord(Model::Artist&, Type::artistFilter);
bool doesArtistExist(const Model::Artist&, Type::artistFilter);
void saveRecord(const Model::Artist&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
Model::Artist parseRecord(MYSQL_RES*);
Model::Artist parseRecord(MYSQL_STMT*);
};
}
#endif
-34
View File
@@ -1,34 +0,0 @@
#ifndef BASE_REPOSITORY_H_
#define BASE_REPOSITORY_H_
#include <string>
#include <mysql/mysql.h>
#include "models/models.h"
namespace Database
{
class base_repository
{
public:
base_repository();
base_repository(const std::string&);
base_repository(const Model::BinaryPath&);
protected:
MYSQL* setup_mysql_connection();
MYSQL* setup_mysql_connection(Model::database_connection);
MYSQL_RES* perform_mysql_query(MYSQL*, const std::string&);
Model::database_connection details;
private:
void intitalizeDetails();
void initializeDetails(const Model::BinaryPath&);
std::string path;
Model::BinaryPath m_binConf;
};
}
#endif
-32
View File
@@ -1,32 +0,0 @@
#ifndef COVERARTREPOSITORY_H_
#define COVERARTREPOSITORY_H_
#include <mysql/mysql.h>
#include "database/base_repository.h"
#include "models/models.h"
#include "types/coverFilter.h"
namespace Database
{
class coverArtRepository : public base_repository
{
public:
coverArtRepository(const std::string&);
coverArtRepository(const Model::BinaryPath&);
Model::Cover retrieveRecord(Model::Cover&, Type::coverFilter);
bool doesCoverArtExist(const Model::Cover&, Type::coverFilter);
void deleteRecord(const Model::Cover&);
void saveRecord(const Model::Cover&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
Model::Cover parseRecord(MYSQL_RES*);
Model::Cover parseRecord(MYSQL_STMT*);
};
}
#endif
-28
View File
@@ -1,28 +0,0 @@
#ifndef GENREREPOSITORY_H_
#define GENREREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
#include "types/genreFilter.h"
namespace Database
{
class genreRepository : public base_repository
{
public:
genreRepository(const Model::BinaryPath&);
Model::Genre retrieveRecord(Model::Genre&, Type::genreFilter);
bool doesGenreExist(const Model::Genre&, Type::genreFilter);
void saveRecord(const Model::Genre&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
Model::Genre parseRecord(MYSQL_RES*);
Model::Genre parseRecord(MYSQL_STMT*);
};
}
#endif
-38
View File
@@ -1,38 +0,0 @@
#ifndef SONGREPOSITORY_H_
#define SONGREPOSITORY_H_
#include <memory>
#include <vector>
#include <mysql/mysql.h>
#include "database/base_repository.h"
#include "models/models.h"
#include "types/songFilter.h"
namespace Database
{
class songRepository : public base_repository
{
public:
songRepository(const std::string&);
songRepository(const Model::BinaryPath&);
std::vector<Model::Song> retrieveRecords();
bool doesSongExist(const Model::Song&, Type::songFilter);
Model::Song retrieveRecord(Model::Song&, Type::songFilter);
void deleteRecord(const Model::Song&);
void saveRecord(const Model::Song&);
private:
std::vector<Model::Song> parseRecords(MYSQL_RES*); // TODO: to be removed
std::vector<Model::Song> parseRecords(MYSQL_STMT*);
Model::Song parseRecord(MYSQL_RES*); // TODO: to be removed
Model::Song parseRecord(MYSQL_STMT*);
};
}
#endif
-28
View File
@@ -1,28 +0,0 @@
#ifndef YEARREPOSITORY_H_
#define YEARREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
#include "types/yearFilter.h"
namespace Database
{
class yearRepository : public base_repository
{
public:
yearRepository(const Model::BinaryPath&);
Model::Year retrieveRecord(Model::Year&, Type::yearFilter);
bool doesYearExist(const Model::Year&, Type::yearFilter);
void saveRecord(const Model::Year&);
private:
// TODO: After parseRecord(MYSQL_STMT*) is implemented
// remove parseRecord(MYSQL_RES*)
Model::Year parseRecord(MYSQL_RES*);
Model::Year parseRecord(MYSQL_STMT*);
};
}
#endif
@@ -4,13 +4,13 @@
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace Dto
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class loginResultDto : public oatpp::data::mapping::type::Object
class LoginResultDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(loginResultDto, Object)
DTO_INIT(LoginResultDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(String, username);
@@ -20,9 +20,9 @@ namespace Dto
DTO_FIELD(String, message);
};
class userDto : public oatpp::data::mapping::type::Object
class UserDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(userDto, Object)
DTO_INIT(UserDto, Object)
DTO_FIELD(String, username);
DTO_FIELD(String, password);
@@ -4,13 +4,13 @@
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace Dto
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class songDto : public oatpp::data::mapping::type::Object
class SongDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(songDto, Object)
DTO_INIT(SongDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(String, title);
+22
View File
@@ -0,0 +1,22 @@
#ifndef ALBUMMANAGER_H_
#define ALBUMMANAGER_H_
#include "model/Models.h"
namespace manager
{
class AlbumManager
{
public:
AlbumManager(const model::BinaryPath&);
model::Album retrieveAlbum(model::Album&);
model::Album saveAlbum(const model::Song&);
static void printAlbum(const model::Album&);
private:
model::BinaryPath m_bConf;
};
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef ARTISTMANAGER_H_
#define ARTISTMANAGER_H_
#include "model/Models.h"
namespace manager
{
class ArtistManager
{
public:
ArtistManager(const model::BinaryPath&);
model::Artist retrieveArtist(model::Artist&);
model::Artist saveArtist(const model::Song&);
static void printArtist(const model::Artist&);
private:
model::BinaryPath m_bConf;
};
}
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef COVERARTMANAGER_H_
#define COVERARTMANAGER_H_
#include <string>
#include "model/Models.h"
namespace manager
{
class CoverArtManager
{
public:
CoverArtManager(const std::string&);
CoverArtManager(const model::BinaryPath& bConf);
model::Cover saveCover(const model::Song&, std::string&, const std::string&);
private:
model::BinaryPath m_bConf;
std::string path;
};
}
#endif
+33
View File
@@ -0,0 +1,33 @@
#ifndef DIRECTORY_MANAGER_H_
#define DIRECTORY_MANAGER_H_
#include <string>
#include <string_view>
#include <nlohmann/json.hpp>
#include "model/Models.h"
namespace manager
{
class DirectoryManager
{
public:
static std::string createDirectoryProcess(model::Song, const std::string&);
static std::string configPath(std::string_view);
static std::string configPath(const model::BinaryPath&);
static std::string contentOfPath(const std::string&);
static nlohmann::json credentialConfigContent(const model::BinaryPath&);
static nlohmann::json databaseConfigContent(const model::BinaryPath&);
static nlohmann::json pathConfigContent(const model::BinaryPath&);
void deleteCoverArtFile(const std::string&, const std::string&);
static void deleteDirectories(model::Song, const std::string&);
private:
void deleteSong(const model::Song);
};
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef GENREMANAGER_H_
#define GENREMANAGER_H_
#include "model/Models.h"
namespace manager
{
class GenreManager
{
public:
GenreManager(const model::BinaryPath&);
model::Genre retrieveGenre(model::Genre&);
model::Genre saveGenre(const model::Song&);
static void printGenre(const model::Genre&);
private:
model::BinaryPath m_bConf;
};
}
#endif
+32
View File
@@ -0,0 +1,32 @@
#ifndef SONGMANAGER_H_
#define SONGMANAGER_H_
#include <iostream>
#include <string>
#include <nlohmann/json.hpp>
#include "model/Models.h"
namespace manager
{
class SongManager
{
public:
SongManager(std::string&);
SongManager(const model::BinaryPath&);
void saveSong(model::Song&);
void deleteSong(model::Song&);
static void printSong(const model::Song&);
private:
void saveSongTemp(model::Song&);
void saveMisc(model::Song&);
model::BinaryPath m_bConf;
std::string exe_path;
};
}
#endif
+37
View File
@@ -0,0 +1,37 @@
#ifndef TOKEN_MANAGER_H_
#define TOKEN_MANAGER_H_
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <jwt-cpp/jwt.h>
#include "model/Models.h"
#include "type/Scopes.h"
namespace manager
{
class TokenManager
{
public:
TokenManager();
model::LoginResult retrieveToken();
model::LoginResult retrieveToken(std::string_view);
model::LoginResult retrieveToken(const model::BinaryPath&);
bool isTokenValid(std::string&, type::Scope);
private:
model::AuthCredentials parseAuthCredentials(std::string_view);
model::AuthCredentials parseAuthCredentials(const model::BinaryPath&);
std::vector<std::string> extractScopes(const jwt::decoded_jwt&&);
std::pair<bool, std::vector<std::string>> fetchAuthHeader(const std::string&);
bool tokenSupportsScope(const std::vector<std::string>, const std::string&&);
};
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef YEARMANAGER_H_
#define YEARMANAGER_H_
#include "model/Models.h"
namespace manager
{
class YearManager
{
public:
YearManager(const model::BinaryPath&);
model::Year retrieveYear(model::Year&);
model::Year saveYear(const model::Song&);
static void printYear(const model::Year&);
private:
model::BinaryPath m_bConf;
};
}
#endif
-22
View File
@@ -1,22 +0,0 @@
#ifndef ALBUMMANAGER_H_
#define ALBUMMANAGER_H_
#include "models/models.h"
namespace Manager
{
class albumManager
{
public:
albumManager(const Model::BinaryPath&);
Model::Album retrieveAlbum(Model::Album&);
Model::Album saveAlbum(const Model::Song&);
static void printAlbum(const Model::Album&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
-22
View File
@@ -1,22 +0,0 @@
#ifndef ARTISTMANAGER_H_
#define ARTISTMANAGER_H_
#include "models/models.h"
namespace Manager
{
class artistManager
{
public:
artistManager(const Model::BinaryPath&);
Model::Artist retrieveArtist(Model::Artist&);
Model::Artist saveArtist(const Model::Song&);
static void printArtist(const Model::Artist&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
-23
View File
@@ -1,23 +0,0 @@
#ifndef COVERARTMANAGER_H_
#define COVERARTMANAGER_H_
#include <string>
#include "models/models.h"
namespace Manager
{
class coverArtManager
{
public:
coverArtManager(const std::string&);
coverArtManager(const Model::BinaryPath& bConf);
Model::Cover saveCover(const Model::Song&, std::string&, const std::string&);
private:
Model::BinaryPath m_bConf;
std::string path;
};
}
#endif
-36
View File
@@ -1,36 +0,0 @@
#ifndef DIRECTORY_MANAGER_H_
#define DIRECTORY_MANAGER_H_
#include <string>
#include <string_view>
#include <nlohmann/json.hpp>
#include "models/models.h"
namespace Manager
{
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 configPath(const Model::BinaryPath&);
static std::string contentOfPath(const std::string&);
//static nlohmann::json credentialConfigContent(const std::string&);
static nlohmann::json credentialConfigContent(const Model::BinaryPath&);
//static nlohmann::json databaseConfigContent(const std::string&);
static nlohmann::json databaseConfigContent(const Model::BinaryPath&);
//static nlohmann::json pathConfigContent(const std::string&);
static nlohmann::json pathConfigContent(const Model::BinaryPath&);
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);
};
}
#endif
-22
View File
@@ -1,22 +0,0 @@
#ifndef GENREMANAGER_H_
#define GENREMANAGER_H_
#include "models/models.h"
namespace Manager
{
class genreManager
{
public:
genreManager(const Model::BinaryPath&);
Model::Genre retrieveGenre(Model::Genre&);
Model::Genre saveGenre(const Model::Song&);
static void printGenre(const Model::Genre&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
-32
View File
@@ -1,32 +0,0 @@
#ifndef SONGMANAGER_H_
#define SONGMANAGER_H_
#include <iostream>
#include <string>
#include <nlohmann/json.hpp>
#include "models/models.h"
namespace Manager
{
class song_manager
{
public:
song_manager(std::string&);
song_manager(const Model::BinaryPath&);
void saveSong(Model::Song&);
void deleteSong(Model::Song&);
static void printSong(const Model::Song&);
private:
void saveSongTemp(Model::Song&);
void saveMisc(Model::Song&);
Model::BinaryPath m_bConf;
std::string exe_path;
};
}
#endif
-37
View File
@@ -1,37 +0,0 @@
#ifndef TOKEN_MANAGER_H_
#define TOKEN_MANAGER_H_
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include <jwt-cpp/jwt.h>
#include "models/models.h"
#include "types/scopes.h"
namespace Manager
{
class token_manager
{
public:
token_manager();
Model::loginResult retrieve_token();
Model::loginResult retrieve_token(std::string_view);
Model::loginResult retrieve_token(const Model::BinaryPath&);
bool is_token_valid(std::string&, Type::Scope);
private:
Model::auth_credentials parse_auth_credentials(std::string_view);
Model::auth_credentials parse_auth_credentials(const Model::BinaryPath&);
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&&);
};
}
#endif
-22
View File
@@ -1,22 +0,0 @@
#ifndef YEARMANAGER_H_
#define YEARMANAGER_H_
#include "models/models.h"
namespace Manager
{
class yearManager
{
public:
yearManager(const Model::BinaryPath&);
Model::Year retrieveYear(Model::Year&);
Model::Year saveYear(const Model::Song&);
static void printYear(const Model::Year&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
@@ -4,7 +4,7 @@
#include <string>
#include <vector>
namespace Model
namespace model
{
struct Song
{
@@ -62,27 +62,27 @@ namespace Model
std::vector<unsigned char> data;
};
struct loginResult
struct LoginResult
{
int user_id;
int userId;
std::string username;
std::string access_token;
std::string token_type;
std::string accessToken;
std::string tokenType;
std::string message;
int expiration;
};
struct auth_credentials
struct AuthCredentials
{
std::string domain;
std::string api_identifier;
std::string client_id;
std::string client_secret;
std::string apiIdentifier;
std::string clientId;
std::string clientSecret;
std::string uri;
std::string endpoint;
};
struct database_connection
struct DatabaseConnection
{
std::string server;
std::string username;
@@ -1,9 +1,9 @@
#ifndef ALBUMFILTER_H_
#define ALBUMFILTER_H_
namespace Type
namespace type
{
enum class albumFilter
enum class AlbumFilter
{
id = 0,
title,
@@ -1,9 +1,9 @@
#ifndef ARTISTFILTER_H_
#define ARTISTFILTER_H_
namespace Type
namespace type
{
enum class artistFilter
enum class ArtistFilter
{
id = 0,
artist
@@ -1,9 +1,9 @@
#ifndef COVERFILTER_H_
#define COVERFILTER_H_
namespace Type
namespace type
{
enum class coverFilter
enum class CoverFilter
{
id = 0,
songTitle,
@@ -1,9 +1,9 @@
#ifndef GENREFILTER_H_
#define GENREFILTER_H_
namespace Type
namespace type
{
enum class genreFilter
enum class GenreFilter
{
id = 0,
category
@@ -1,7 +1,7 @@
#ifndef SCOPES_H_
#define SCOPES_H_
namespace Type
namespace type
{
enum class Scope
{
@@ -1,9 +1,9 @@
#ifndef SONGFILTER_H_
#define SONGFILTER_H_
namespace Type
namespace type
{
enum class songFilter
enum class SongFilter
{
id = 0,
title,
@@ -1,9 +1,9 @@
#ifndef YEARFILTER_H_
#define YEARFILTER_H_
namespace Type
namespace type
{
enum class yearFilter
enum class YearFilter
{
id = 0,
year
-22
View File
@@ -1,22 +0,0 @@
#ifndef METADATA_RETRIEVER_H_
#define METADATA_RETRIEVER_H_
#include <iostream>
#include <string>
#include "models/models.h"
namespace Utility
{
class metadata_retriever
{
public:
Model::Song retrieve_metadata(std::string&);
Model::Cover update_cover_art(const Model::Song&, Model::Cover& cov, const std::string&);
void update_metadata(Model::Song updated_song, const Model::Song old_song);
private:
};
}
#endif
@@ -13,12 +13,12 @@
#include <tpropertymap.h>
#include <id3v2tag.h>
namespace Utility
namespace utility
{
class imageFile : public TagLib::File
class ImageFile : public TagLib::File
{
public:
imageFile(const char *file);
ImageFile(const char *file);
TagLib::ByteVector data();
+22
View File
@@ -0,0 +1,22 @@
#ifndef METADATA_RETRIEVER_H_
#define METADATA_RETRIEVER_H_
#include <iostream>
#include <string>
#include "model/Models.h"
namespace utility
{
class MetadataRetriever
{
public:
model::Song retrieveMetadata(std::string&);
model::Cover updateCoverArt(const model::Song&, model::Cover&, const std::string&);
void updateMetadata(model::Song&, const model::Song&);
private:
};
}
#endif
+10 -10
View File
@@ -9,23 +9,23 @@
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
#include "oatpp/web/server/HttpConnectionHandler.hpp"
#include "component/appComponent.hpp"
#include "controller/loginController.hpp"
#include "controller/songController.hpp"
#include "database/base_repository.h"
#include "models/models.h"
#include "component/AppComponent.hpp"
#include "controller/LoginController.hpp"
#include "controller/SongController.hpp"
//#include "database/base_repository.h"
#include "model/Models.h"
namespace fs = std::filesystem;
//void run(const std::string& working_path)
void run(const Model::BinaryPath& bConf)
void run(const model::BinaryPath& bConf)
{
Component::appComponent component;
component::AppComponent component;
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
auto logController = std::make_shared<Controller::loginController>(bConf);
auto sngController = std::make_shared<Controller::songController>(bConf);
auto logController = std::make_shared<controller::LoginController>(bConf);
auto sngController = std::make_shared<controller::SongController>(bConf);
logController->addEndpointsToRouter(router);
sngController->addEndpointsToRouter(router);
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
{
oatpp::base::Environment::init();
Model::BinaryPath bConf(argv[0]);
model::BinaryPath bConf(argv[0]);
run(bConf);
@@ -1,4 +1,4 @@
#include "database/albumRepository.h"
#include "database/AlbumRepository.h"
#include <iostream>
#include <memory>
@@ -6,32 +6,32 @@
#include <string>
#include <cstring>
Database::albumRepository::albumRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
database::AlbumRepository::AlbumRepository(const model::BinaryPath& bConf)
: BaseRepository(bConf)
{ }
// TODO: implement this later on
std::vector<Model::Album> Database::albumRepository::retrieveRecords()
std::vector<model::Album> database::AlbumRepository::retrieveRecords()
{
std::vector<Model::Album> albums;
std::vector<model::Album> albums;
return albums;
}
Model::Album Database::albumRepository::retrieveRecord(Model::Album& album, Type::albumFilter filter)
model::Album database::AlbumRepository::retrieveRecord(model::Album& album, type::AlbumFilter filter)
{
std::cout << "retrieving album record" << std::endl;
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
qry << "SELECT alb.* FROM Album alb WHERE ";
std::unique_ptr<char*> param;
switch (filter) {
case Type::albumFilter::id:
case type::AlbumFilter::id:
qry << "alb.AlbumId = " << album.id;
break;
case Type::albumFilter::title:
case type::AlbumFilter::title:
param = std::make_unique<char*>(new char[album.title.size()]);
mysql_real_escape_string(conn, *param, album.title.c_str(), album.title.size());
qry << "alb.Title = '" << *param << "'";
@@ -43,7 +43,7 @@ Model::Album Database::albumRepository::retrieveRecord(Model::Album& album, Type
qry << " ORDER BY AlbumId DESC LIMIT 1";
const std::string query = qry.str();
auto results = perform_mysql_query(conn, query);
auto results = performMysqlQuery(conn, query);
album = parseRecord(results);
@@ -53,7 +53,7 @@ Model::Album Database::albumRepository::retrieveRecord(Model::Album& album, Type
return album;
}
bool Database::albumRepository::doesAlbumExists(const Model::Album& album, Type::albumFilter filter)
bool database::AlbumRepository::doesAlbumExists(const model::Album& album, type::AlbumFilter filter)
{
// TODO: continue working on this part.
// Reason: there should be a check to see if an album record already exists
@@ -63,7 +63,7 @@ bool Database::albumRepository::doesAlbumExists(const Model::Album& album, Type:
// record for songs on the same album. After fixing this, do the
// same for Artist, Genre, and Year records
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto stmt = mysql_stmt_init(conn);
MYSQL_BIND params[1];
@@ -74,7 +74,7 @@ bool Database::albumRepository::doesAlbumExists(const Model::Album& album, Type:
auto titleLength = album.title.size();
switch (filter) {
case Type::albumFilter::id:
case type::AlbumFilter::id:
qry << "AlbumId = ?";
params[0].buffer_type = MYSQL_TYPE_LONG;
@@ -82,7 +82,7 @@ bool Database::albumRepository::doesAlbumExists(const Model::Album& album, Type:
params[0].length = 0;
params[0].is_null = 0;
break;
case Type::albumFilter::title:
case type::AlbumFilter::title:
qry << "Title = ?";
params[0].buffer_type = MYSQL_TYPE_STRING;
@@ -112,11 +112,11 @@ bool Database::albumRepository::doesAlbumExists(const Model::Album& album, Type:
return (rowCount > 0) ? true : false;
}
void Database::albumRepository::saveAlbum(const Model::Album& album)
void database::AlbumRepository::saveAlbum(const model::Album& album)
{
std::cout << "beginning to insert album record" << std::endl;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
MYSQL_STMT *stmt = mysql_stmt_init(conn);
const std::string query = "INSERT INTO Album(Title, Year) VALUES(?, ?)";
@@ -148,17 +148,17 @@ void Database::albumRepository::saveAlbum(const Model::Album& album)
// TODO: implement this
std::vector<Model::Album> Database::albumRepository::parseRecords(MYSQL_RES* results)
std::vector<model::Album> database::AlbumRepository::parseRecords(MYSQL_RES* results)
{
std::vector<Model::Album> albums;
std::vector<model::Album> albums;
return albums;
}
Model::Album Database::albumRepository::parseRecord(MYSQL_RES* results)
model::Album database::AlbumRepository::parseRecord(MYSQL_RES* results)
{
std::cout << "parsing album record" << std::endl;
Model::Album album;
model::Album album;
auto fieldNum = mysql_num_fields(results);
auto row = mysql_fetch_row(results);
@@ -180,10 +180,10 @@ Model::Album Database::albumRepository::parseRecord(MYSQL_RES* results)
return album;
}
Model::Album Database::albumRepository::parseRecord(MYSQL_STMT *stmt)
model::Album database::AlbumRepository::parseRecord(MYSQL_STMT *stmt)
{
// TODO: implement this
Model::Album album;
model::Album album;
return album;
}
@@ -1,4 +1,4 @@
#include "database/artistRepository.h"
#include "database/ArtistRepository.h"
#include <iostream>
#include <memory>
@@ -6,25 +6,25 @@
#include <string>
#include <cstring>
Database::artistRepository::artistRepository(const Model::BinaryPath& binConf)
: base_repository(binConf)
database::ArtistRepository::ArtistRepository(const model::BinaryPath& binConf)
: BaseRepository(binConf)
{
}
Model::Artist Database::artistRepository::retrieveRecord(Model::Artist& artist, Type::artistFilter filter)
model::Artist database::ArtistRepository::retrieveRecord(model::Artist& artist, type::ArtistFilter filter)
{
std::cout << "retrieving artist record" << std::endl;
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
qry << "SELECT art.* FROM Artist art WHERE ";
std::unique_ptr<char*> param;
switch (filter) {
case Type::artistFilter::id:
case type::ArtistFilter::id:
qry << "art.ArtistId = " << artist.id;
break;
case Type::artistFilter::artist:
case type::ArtistFilter::artist:
param = std::make_unique<char*>(new char[artist.artist.size()]);
mysql_real_escape_string(conn, *param, artist.artist.c_str(), artist.artist.size());
qry << "art.Artist ='" << *param << "'";
@@ -36,7 +36,7 @@ Model::Artist Database::artistRepository::retrieveRecord(Model::Artist& artist,
qry << " ORDER BY ArtistId DESC LIMIT 1";
const auto query = qry.str();
auto results = perform_mysql_query(conn, query);
auto results = performMysqlQuery(conn, query);
artist = parseRecord(results);
@@ -47,18 +47,18 @@ Model::Artist Database::artistRepository::retrieveRecord(Model::Artist& artist,
return artist;
}
bool Database::artistRepository::doesArtistExist(const Model::Artist& artist, Type::artistFilter filter)
bool database::ArtistRepository::doesArtistExist(const model::Artist& artist, type::ArtistFilter filter)
{
// TODO: implement this
return false;
}
void Database::artistRepository::saveRecord(const Model::Artist& artist)
void database::ArtistRepository::saveRecord(const model::Artist& artist)
{
std::cout << "inserting artist record" << std::endl;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
MYSQL_STMT *stmt = mysql_stmt_init(conn);
const std::string query = "INSERT INTO Artist(Artist) VALUES(?)";
@@ -84,10 +84,10 @@ void Database::artistRepository::saveRecord(const Model::Artist& artist)
}
Model::Artist Database::artistRepository::parseRecord(MYSQL_RES* results)
model::Artist database::ArtistRepository::parseRecord(MYSQL_RES* results)
{
std::cout << "parsing artist record" << std::endl;
Model::Artist artist;
model::Artist artist;
auto fieldNum = mysql_num_fields(results);
auto row = mysql_fetch_row(results);
@@ -108,10 +108,10 @@ Model::Artist Database::artistRepository::parseRecord(MYSQL_RES* results)
return artist;
}
Model::Artist Database::artistRepository::parseRecord(MYSQL_STMT *stmt)
model::Artist database::ArtistRepository::parseRecord(MYSQL_STMT *stmt)
{
// TODO: implement this
Model::Artist art;
model::Artist art;
return art;
}
@@ -1,24 +1,24 @@
#include "database/base_repository.h"
#include "database/BaseRepository.h"
#include <iostream>
#include <nlohmann/json.hpp>
#include "managers/directory_manager.h"
#include "manager/DirectoryManager.h"
Database::base_repository::base_repository()
database::BaseRepository::BaseRepository()
{ }
Database::base_repository::base_repository(const std::string& path) : path(path)
database::BaseRepository::BaseRepository(const std::string& path) : path(path)
{
intitalizeDetails();
}
Database::base_repository::base_repository(const Model::BinaryPath& bConf)
database::BaseRepository::BaseRepository(const model::BinaryPath& bConf)
{
initializeDetails(bConf);
}
MYSQL* Database::base_repository::setup_mysql_connection()
MYSQL* database::BaseRepository::setupMysqlConnection()
{
MYSQL *conn = mysql_init(nullptr);
@@ -29,7 +29,7 @@ MYSQL* Database::base_repository::setup_mysql_connection()
return conn;
}
MYSQL* Database::base_repository::setup_mysql_connection(Model::database_connection details)
MYSQL* database::BaseRepository::setupMysqlConnection(model::DatabaseConnection details)
{
MYSQL *connection = mysql_init(NULL);
@@ -41,7 +41,7 @@ MYSQL* Database::base_repository::setup_mysql_connection(Model::database_connect
return connection;
}
MYSQL_RES* Database::base_repository::perform_mysql_query(MYSQL *conn, const std::string& query)
MYSQL_RES* database::BaseRepository::performMysqlQuery(MYSQL *conn, const std::string& query)
{
// send the query to the database
if (mysql_query(conn, query.c_str()))
@@ -53,18 +53,18 @@ MYSQL_RES* Database::base_repository::perform_mysql_query(MYSQL *conn, const std
return mysql_use_result(conn);
}
void Database::base_repository::intitalizeDetails()
void database::BaseRepository::intitalizeDetails()
{
auto databaseConfig = Manager::directory_manager::databaseConfigContent(path);
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(path);
details.database = databaseConfig["database"].get<std::string>();
details.password = databaseConfig["password"].get<std::string>();
details.server = databaseConfig["server"].get<std::string>();
details.username = databaseConfig["username"].get<std::string>();
}
void Database::base_repository::initializeDetails(const Model::BinaryPath& bConf)
void database::BaseRepository::initializeDetails(const model::BinaryPath& bConf)
{
auto databaseConfig = Manager::directory_manager::databaseConfigContent(bConf);
auto databaseConfig = manager::DirectoryManager::databaseConfigContent(bConf);
details.database = databaseConfig["database"].get<std::string>();
details.server = databaseConfig["server"].get<std::string>();
@@ -1,33 +1,33 @@
#include "database/coverArtRepository.h"
#include "database/CoverArtRepository.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <cstring>
Database::coverArtRepository::coverArtRepository(const std::string& path) : base_repository(path)
database::CoverArtRepository::CoverArtRepository(const std::string& path) : BaseRepository(path)
{ }
Database::coverArtRepository::coverArtRepository(const Model::BinaryPath& bConf) : base_repository(bConf)
database::CoverArtRepository::CoverArtRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
{ }
Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, Type::coverFilter filter = Type::coverFilter::id)
model::Cover database::CoverArtRepository::retrieveRecord(model::Cover& cov, type::CoverFilter filter = type::CoverFilter::id)
{
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
qry << "SELECT * FROM CoverArt WHERE ";
std::unique_ptr<char*> param;
switch (filter) {
case Type::coverFilter::id:
case type::CoverFilter::id:
qry << "CoverArtId = " << cov.id;
break;
case Type::coverFilter::songTitle:
case type::CoverFilter::songTitle:
param = std::make_unique<char*>(new char[cov.songTitle.size()]);
mysql_real_escape_string(conn, *param, cov.songTitle.c_str(), cov.songTitle.size());
qry << "SongTitle = '" << *param << "'";
break;
case Type::coverFilter::imagePath:
case type::CoverFilter::imagePath:
param = std::make_unique<char*>(new char[cov.imagePath.size()]);
mysql_real_escape_string(conn, *param, cov.imagePath.c_str(), cov.imagePath.size());
qry << "ImagePath = '" << *param << "'";
@@ -35,7 +35,7 @@ Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, Typ
}
const std::string query = qry.str();
auto results = perform_mysql_query(conn, query);
auto results = performMysqlQuery(conn, query);
std::cout << "the query has been performed" << std::endl;
auto covDb = parseRecord(results);
@@ -46,25 +46,25 @@ Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, Typ
return covDb;
}
bool Database::coverArtRepository::doesCoverArtExist(const Model::Cover& cover, Type::coverFilter filter)
bool database::CoverArtRepository::doesCoverArtExist(const model::Cover& cover, type::CoverFilter filter)
{
// TODO: implement this
return false;
}
void Database::coverArtRepository::deleteRecord(const Model::Cover& cov)
void database::CoverArtRepository::deleteRecord(const model::Cover& cov)
{
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
const std::string query("DELETE FROM CoverArt WHERE CoverArtId = " + std::to_string(cov.id));
auto result = perform_mysql_query(conn, query);
auto result = performMysqlQuery(conn, query);
mysql_close(conn);
}
void Database::coverArtRepository::saveRecord(const Model::Cover& cov)
void database::CoverArtRepository::saveRecord(const model::Cover& cov)
{
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
MYSQL_STMT *stmt;
MYSQL_BIND params[2];
@@ -100,10 +100,10 @@ void Database::coverArtRepository::saveRecord(const Model::Cover& cov)
std::cout << "done" << std::endl;
}
Model::Cover Database::coverArtRepository::parseRecord(MYSQL_RES *results)
model::Cover database::CoverArtRepository::parseRecord(MYSQL_RES *results)
{
std::cout << "parsing record" << std::endl;
Model::Cover cov;
model::Cover cov;
auto fieldNum = mysql_num_fields(results);
MYSQL_ROW row = mysql_fetch_row(results);
@@ -126,11 +126,11 @@ Model::Cover Database::coverArtRepository::parseRecord(MYSQL_RES *results)
return cov;
}
Model::Cover Database::coverArtRepository::parseRecord(MYSQL_STMT *stmt)
model::Cover database::CoverArtRepository::parseRecord(MYSQL_STMT *stmt)
{
// TODO: implement this
Model::Cover cover;
model::Cover cover;
return cover;
}
@@ -1,28 +1,28 @@
#include "database/genreRepository.h"
#include "database/GenreRepository.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <cstring>
Database::genreRepository::genreRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
database::GenreRepository::GenreRepository(const model::BinaryPath& bConf)
: BaseRepository(bConf)
{ }
Model::Genre Database::genreRepository::retrieveRecord(Model::Genre& genre, Type::genreFilter filter)
model::Genre database::GenreRepository::retrieveRecord(model::Genre& genre, type::GenreFilter filter)
{
std::cout << "retrieving genre record" << std::endl;
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
qry << "SELECT gnr.* FROM Genre gnr WHERE ";
std::unique_ptr<char*> param;
switch (filter) {
case Type::genreFilter::id:
case type::GenreFilter::id:
qry << "gnr.GenreId = " << genre.id;
break;
case Type::genreFilter::category:
case type::GenreFilter::category:
param = std::make_unique<char*>(new char[genre.category.size()]);
mysql_real_escape_string(conn, *param, genre.category.c_str(), genre.category.size());
qry << "gnr.Category ='" << *param << "'";
@@ -34,7 +34,7 @@ Model::Genre Database::genreRepository::retrieveRecord(Model::Genre& genre, Type
qry << " ORDER BY GenreId DESC LIMIT 1";
const auto query = qry.str();
auto results = perform_mysql_query(conn, query);
auto results = performMysqlQuery(conn, query);
genre = parseRecord(results);
@@ -45,18 +45,18 @@ Model::Genre Database::genreRepository::retrieveRecord(Model::Genre& genre, Type
return genre;
}
bool Database::genreRepository::doesGenreExist(const Model::Genre& genre, Type::genreFilter filter)
bool database::GenreRepository::doesGenreExist(const model::Genre& genre, type::GenreFilter filter)
{
// TODO: implement this
return false;
}
void Database::genreRepository::saveRecord(const Model::Genre& genre)
void database::GenreRepository::saveRecord(const model::Genre& genre)
{
std::cout << "inserting genre record" << std::endl;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
MYSQL_STMT *stmt = mysql_stmt_init(conn);
const std::string query("INSERT INTO Genre(Category) VALUES(?)");
@@ -81,10 +81,10 @@ void Database::genreRepository::saveRecord(const Model::Genre& genre)
std::cout << "inserted record" << std::endl;
}
Model::Genre Database::genreRepository::parseRecord(MYSQL_RES* results)
model::Genre database::GenreRepository::parseRecord(MYSQL_RES* results)
{
std::cout << "parsing genre record" << std::endl;
Model::Genre genre;
model::Genre genre;
auto fieldNum = mysql_num_fields(results);
auto row = mysql_fetch_row(results);
@@ -104,11 +104,11 @@ Model::Genre Database::genreRepository::parseRecord(MYSQL_RES* results)
return genre;
}
Model::Genre Database::genreRepository::parseRecord(MYSQL_STMT *stmt)
model::Genre database::GenreRepository::parseRecord(MYSQL_STMT *stmt)
{
// TODO: implement this
Model::Genre genre;
model::Genre genre;
return genre;
}
@@ -1,21 +1,21 @@
#include "database/songRepository.h"
#include "database/SongRepository.h"
#include <iostream>
#include <memory>
#include <sstream>
#include <cstring>
#include "types/songFilter.h"
#include "type/SongFilter.h"
Database::songRepository::songRepository(const std::string& path) : base_repository(path)
database::SongRepository::SongRepository(const std::string& path) : BaseRepository(path)
{ }
Database::songRepository::songRepository(const Model::BinaryPath& bConf) : base_repository(bConf)
database::SongRepository::SongRepository(const model::BinaryPath& bConf) : BaseRepository(bConf)
{ }
std::vector<Model::Song> Database::songRepository::retrieveRecords()
std::vector<model::Song> database::SongRepository::retrieveRecords()
{
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto stmt = mysql_stmt_init(conn);
const std::string query = "SELECT * FROM Song";
@@ -30,10 +30,10 @@ std::vector<Model::Song> Database::songRepository::retrieveRecords()
return songs;
}
Model::Song Database::songRepository::retrieveRecord(Model::Song& song, Type::songFilter filter)
model::Song database::SongRepository::retrieveRecord(model::Song& song, type::SongFilter filter)
{
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto stmt = mysql_stmt_init(conn);
MYSQL_BIND params[1];
@@ -43,7 +43,7 @@ Model::Song Database::songRepository::retrieveRecord(Model::Song& song, Type::so
auto titleLength = song.title.size();
switch (filter) {
case Type::songFilter::id:
case type::SongFilter::id:
qry << "SongId = ?";
params[0].buffer_type = MYSQL_TYPE_LONG;
@@ -51,7 +51,7 @@ Model::Song Database::songRepository::retrieveRecord(Model::Song& song, Type::so
params[0].length = 0;
params[0].is_null = 0;;
break;
case Type::songFilter::title:
case type::SongFilter::title:
qry << "Title = ?";
params[0].buffer_type = MYSQL_TYPE_STRING;
@@ -81,11 +81,11 @@ Model::Song Database::songRepository::retrieveRecord(Model::Song& song, Type::so
return song;
}
bool Database::songRepository::doesSongExist(const Model::Song& song, Type::songFilter filter)
bool database::SongRepository::doesSongExist(const model::Song& song, type::SongFilter filter)
{
std::cout << "checking to see if song exists" << std::endl;
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto stmt = mysql_stmt_init(conn);
MYSQL_BIND params[1];
@@ -95,7 +95,7 @@ bool Database::songRepository::doesSongExist(const Model::Song& song, Type::song
auto titleLength = song.title.size();
switch (filter) {
case Type::songFilter::id:
case type::SongFilter::id:
qry << "SongId = ?";
params[0].buffer_type = MYSQL_TYPE_LONG;
@@ -103,7 +103,7 @@ bool Database::songRepository::doesSongExist(const Model::Song& song, Type::song
params[0].length = 0;
params[0].is_null = 0;
break;
case Type::songFilter::title:
case type::SongFilter::title:
qry << "Title = ?";
params[0].buffer_type = MYSQL_TYPE_STRING;
@@ -134,22 +134,22 @@ bool Database::songRepository::doesSongExist(const Model::Song& song, Type::song
return (rowCount > 0) ? true : false;
}
void Database::songRepository::deleteRecord(const Model::Song& song)
void database::SongRepository::deleteRecord(const model::Song& song)
{
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto status = 0;
const std::string query("DELETE FROM Song WHERE SongId = " + std::to_string(song.id));
auto result = perform_mysql_query(conn, query);
auto result = performMysqlQuery(conn, query);
mysql_close(conn);
}
void Database::songRepository::saveRecord(const Model::Song& song)
void database::SongRepository::saveRecord(const model::Song& song)
{
std::cout << "beginning to insert song record" << std::endl;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
auto status = 0;
MYSQL_STMT *stmt = mysql_stmt_init(conn);
@@ -248,16 +248,16 @@ void Database::songRepository::saveRecord(const Model::Song& song)
}
// TODO: delete this, not being used
std::vector<Model::Song> Database::songRepository::parseRecords(MYSQL_RES* results)
std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_RES* results)
{
auto fieldNum = mysql_num_fields(results);
auto numRows = mysql_num_rows(results);
std::vector<Model::Song> songs;
std::vector<model::Song> songs;
songs.reserve(numRows);
for (MYSQL_ROW row = nullptr; (row = mysql_fetch_row(results)) != nullptr; ) {
Model::Song song;
model::Song song;
for (auto i = 0; i != fieldNum; ++i) {
/**
@@ -351,19 +351,17 @@ std::vector<Model::Song> Database::songRepository::parseRecords(MYSQL_RES* resul
}
songs.push_back(song);
//std::cout << "added" << std::endl;
}
//std::cout << "completely" << std::endl;
return songs;
}
std::vector<Model::Song> Database::songRepository::parseRecords(MYSQL_STMT *stmt)
std::vector<model::Song> database::SongRepository::parseRecords(MYSQL_STMT *stmt)
{
::mysql_stmt_store_result(stmt);
auto c = ::mysql_stmt_num_rows(stmt);
std::cout << "number of results " << c << std::endl;
std::vector<Model::Song> songs;
std::vector<model::Song> songs;
songs.reserve(c);
auto status = 0;
@@ -378,7 +376,7 @@ std::vector<Model::Song> Database::songRepository::parseRecords(MYSQL_STMT *stmt
if (::mysql_stmt_field_count(stmt) > 0) {
Model::Song song;
model::Song song;
auto res = ::mysql_stmt_result_metadata(stmt);
auto fields = ::mysql_fetch_fields(res);
auto strLen = 1024;
@@ -498,9 +496,9 @@ std::vector<Model::Song> Database::songRepository::parseRecords(MYSQL_STMT *stmt
// TODO: delete this, not being used anymore
Model::Song Database::songRepository::parseRecord(MYSQL_RES* results)
model::Song database::SongRepository::parseRecord(MYSQL_RES* results)
{
Model::Song song;
model::Song song;
auto fieldNum = mysql_num_fields(results);
auto row = mysql_fetch_row(results);
@@ -549,9 +547,9 @@ Model::Song Database::songRepository::parseRecord(MYSQL_RES* results)
return song;
}
Model::Song Database::songRepository::parseRecord(MYSQL_STMT *stmt)
model::Song database::SongRepository::parseRecord(MYSQL_STMT *stmt)
{
Model::Song song;
model::Song song;
auto status = 0;
auto time = 0;
auto valAmt = 15;
@@ -667,7 +665,6 @@ Model::Song Database::songRepository::parseRecord(MYSQL_STMT *stmt)
status = ::mysql_stmt_next_result(stmt);
}
std::cout << "okay!!!!" << std::endl;
std::cout << "done parsing record" << std::endl;
return song;
@@ -1,4 +1,4 @@
#include "database/yearRepository.h"
#include "database/YearRepository.h"
#include <iostream>
#include <memory>
@@ -7,23 +7,23 @@
#include <cstring>
Database::yearRepository::yearRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
database::YearRepository::YearRepository(const model::BinaryPath& bConf)
: BaseRepository(bConf)
{ }
Model::Year Database::yearRepository::retrieveRecord(Model::Year& year, Type::yearFilter filter)
model::Year database::YearRepository::retrieveRecord(model::Year& year, type::YearFilter filter)
{
std::cout << "retrieving year record" << std::endl;
std::stringstream qry;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
qry << "SELECT yr.* FROM Year yr WHERE ";
switch (filter) {
case Type::yearFilter::id:
case type::YearFilter::id:
qry << "yr.YearId = " << year.id;
break;
case Type::yearFilter::year:
case type::YearFilter::year:
qry << "yr.Year = " << year.year;
break;
default:
@@ -33,7 +33,7 @@ Model::Year Database::yearRepository::retrieveRecord(Model::Year& year, Type::ye
qry << " ORDER BY yr.YearId DESC LIMIT 1";
const auto query = qry.str();
auto results = perform_mysql_query(conn, query);
auto results = performMysqlQuery(conn, query);
year = parseRecord(results);
@@ -44,18 +44,18 @@ Model::Year Database::yearRepository::retrieveRecord(Model::Year& year, Type::ye
return year;
}
bool Database::yearRepository::doesYearExist(const Model::Year& year, Type::yearFilter filter)
bool database::YearRepository::doesYearExist(const model::Year& year, type::YearFilter filter)
{
// TODO: implement this
return false;
}
void Database::yearRepository::saveRecord(const Model::Year& year)
void database::YearRepository::saveRecord(const model::Year& year)
{
std::cout << "saving year record" << std::endl;
auto conn = setup_mysql_connection();
auto conn = setupMysqlConnection();
MYSQL_STMT *stmt = mysql_stmt_init(conn);
const std::string query("INSERT INTO Year(Year) VALUES(?)");
@@ -79,10 +79,10 @@ void Database::yearRepository::saveRecord(const Model::Year& year)
std::cout << "saved record" << std::endl;
}
Model::Year Database::yearRepository::parseRecord(MYSQL_RES *results)
model::Year database::YearRepository::parseRecord(MYSQL_RES *results)
{
std::cout << "parsing year record" << std::endl;
Model::Year year;
model::Year year;
auto fieldNum = mysql_num_fields(results);
auto row = mysql_fetch_row(results);
@@ -102,11 +102,11 @@ Model::Year Database::yearRepository::parseRecord(MYSQL_RES *results)
return year;
}
Model::Year Database::yearRepository::parseRecord(MYSQL_STMT *stmt)
model::Year database::YearRepository::parseRecord(MYSQL_STMT *stmt)
{
// TODO: imeplement this
Model::Year year;
model::Year year;
return year;
}
+45
View File
@@ -0,0 +1,45 @@
#include "manager/AlbumManager.h"
#include <iostream>
#include "database/AlbumRepository.h"
#include "model/Models.h"
#include "type/AlbumFilter.h"
manager::AlbumManager::AlbumManager(const model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
model::Album manager::AlbumManager::retrieveAlbum(model::Album& album)
{
database::AlbumRepository albRepo(m_bConf);
album = std::move(albRepo.retrieveRecord(album, type::AlbumFilter::title));
return album;
}
model::Album manager::AlbumManager::saveAlbum(const model::Song& song)
{
model::Album album;
album.title = song.album;
album.year = song.year;
database::AlbumRepository albRepo(m_bConf);
if (!albRepo.doesAlbumExists(album, type::AlbumFilter::title)) {
albRepo.saveAlbum(album);
} else {
std::cout << "album record already exists in the database" << std::endl;
}
return album;
}
void manager::AlbumManager::printAlbum(const model::Album& album)
{
std::cout << "\nalbum record" << std::endl;
std::cout << "id: " << album.id << std::endl;
std::cout << "title: " << album.title << std::endl;
std::cout << "year: " << album.year << std::endl;
}
+41
View File
@@ -0,0 +1,41 @@
#include "manager/ArtistManager.h"
#include <iostream>
#include "database/ArtistRepository.h"
#include "type/ArtistFilter.h"
manager::ArtistManager::ArtistManager(const model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
model::Artist manager::ArtistManager::retrieveArtist(model::Artist& artist)
{
database::ArtistRepository artRepo(m_bConf);
artist = artRepo.retrieveRecord(artist, type::ArtistFilter::artist);
return artist;
}
model::Artist manager::ArtistManager::saveArtist(const model::Song& song)
{
model::Artist artist;
artist.artist = song.artist;
database::ArtistRepository artRepo(m_bConf);
if (!artRepo.doesArtistExist(artist, type::ArtistFilter::artist)) {
artRepo.saveRecord(artist);
} else {
std::cout << "artist already exists" << std::endl;
}
return artist;
}
void manager::ArtistManager::printArtist(const model::Artist& artist)
{
std::cout << "\nartist record" << std::endl;
std::cout << "id: " << artist.id << std::endl;
std::cout << "artist: " << artist.artist << std::endl;
}
+34
View File
@@ -0,0 +1,34 @@
#include "manager/CoverArtManager.h"
#include "database/CoverArtRepository.h"
#include "type/CoverFilter.h"
#include "utility/MetadataRetriever.h"
manager::CoverArtManager::CoverArtManager(const std::string& configPath) : path(configPath)
{ }
manager::CoverArtManager::CoverArtManager(const model::BinaryPath& bConf) : m_bConf(bConf)
{ }
model::Cover manager::CoverArtManager::saveCover(const model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
{
utility::MetadataRetriever meta;
model::Cover cov;
cov.imagePath = rootPath;
cov = meta.updateCoverArt(song, cov, stockCoverPath);
cov.songTitle = song.title;
database::CoverArtRepository covRepo(m_bConf);
if (!covRepo.doesCoverArtExist(cov, type::CoverFilter::songTitle)) {
std::cout << "saving image record to the database" << std::endl;
covRepo.saveRecord(cov);
} else {
std::cout << "cover art record already exists" << std::endl;
}
std::cout << "retrieving image record from database" << std::endl;
cov = covRepo.retrieveRecord(cov, type::CoverFilter::songTitle);
return cov;
}
+128
View File
@@ -0,0 +1,128 @@
#include <iostream>
#include <filesystem>
#include <fstream>
#include <sstream>
#include "manager/DirectoryManager.h"
namespace fs = std::filesystem;
std::string manager::DirectoryManager::createDirectoryProcess(model::Song song, const std::string& rootPath)
{
auto currPath = fs::path(rootPath);
if (fs::exists(currPath)) {
std::cout << "path exists" << std::endl;
} else {
std::cout << "creating path" << std::endl;
fs::create_directory(currPath);
}
auto artPath = fs::path(currPath.string() + song.artist);
if (fs::exists(artPath)) {
std::cout << "artist path exists" << std::endl;
} else {
std::cout << "creating artist path" << std::endl;
fs::create_directory(artPath);
}
auto albPath = fs::path(artPath.string() + "/" + song.album);
if (fs::exists(albPath)) {
std::cout << "album path exists" << std::endl;
} else {
std::cout << "creating album path" << std::endl;
fs::create_directory(albPath);
}
return albPath.string() + "/";
}
std::string manager::DirectoryManager::configPath(std::string_view path)
{
return fs::canonical(path).parent_path().string();
}
std::string manager::DirectoryManager::configPath(const model::BinaryPath& bConf)
{
return fs::canonical(bConf.path).parent_path().string();
}
std::string manager::DirectoryManager::contentOfPath(const std::string& path)
{
std::fstream a(path, std::ios::in);
std::stringstream s;
s << a.rdbuf();
a.close();
return s.str();
}
nlohmann::json manager::DirectoryManager::credentialConfigContent(const model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/authcredentials.json");
return nlohmann::json::parse(contentOfPath(path));
}
nlohmann::json manager::DirectoryManager::databaseConfigContent(const model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/database.json");
return nlohmann::json::parse(contentOfPath(path));
}
nlohmann::json manager::DirectoryManager::pathConfigContent(const model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/paths.json");
return nlohmann::json::parse(contentOfPath(path));
}
void manager::DirectoryManager::deleteCoverArtFile(const std::string& covPath, const std::string& stockCoverPath)
{
if (covPath.compare(stockCoverPath) == 0) {
std::cout << "cover has stock cover art, will not deleted" << std::endl;
} else {
std::cout << "deleting song path" << std::endl;
auto cov = fs::path(covPath);
fs::remove(cov);
}
}
void manager::DirectoryManager::deleteDirectories(model::Song song, const std::string& rootPath)
{
std::cout << "checking to for empty directories to delete" << std::endl;
const std::string art(rootPath + std::string("/") + song.artist);
const std::string alb(art + "/" + song.album);
auto albPath = fs::path(alb);
if (!fs::exists(albPath)) {
std::cout << "directory does not exists" << std::endl;
} else if (fs::is_empty(albPath)) {
fs::remove(albPath);
}
auto artPath = fs::path(art);
if (!fs::exists(artPath)) {
std::cout << "directory does not exists" << std::endl;
return;
} else if (fs::is_empty(artPath)) {
fs::remove(artPath);
}
std::cout << "deleted empty directory or directories" << std::endl;
}
void manager::DirectoryManager::deleteSong(const model::Song song)
{
std::cout << "deleting song" << std::endl;
auto songPath = fs::path(song.songPath);
if (!fs::exists(songPath)) {
std::cout << "song does not exists" << std::endl;
return;
}
fs::remove(songPath);
std::cout << "deleted song" << std::endl;
}
+41
View File
@@ -0,0 +1,41 @@
#include "manager/GenreManager.h"
#include <iostream>
#include "database/GenreRepository.h"
#include "type/GenreFilter.h"
manager::GenreManager::GenreManager(const model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
model::Genre manager::GenreManager::retrieveGenre(model::Genre& genre)
{
database::GenreRepository gnrRepo(m_bConf);
genre = gnrRepo.retrieveRecord(genre, type::GenreFilter::category);
return genre;
}
model::Genre manager::GenreManager::saveGenre(const model::Song& song)
{
model::Genre genre;
genre.category = song.genre;
database::GenreRepository gnrRepo(m_bConf);
if (!gnrRepo.doesGenreExist(genre, type::GenreFilter::category)) {
gnrRepo.saveRecord(genre);
} else {
std::cout << "genre record already exists" << std::endl;
}
return genre;
}
void manager::GenreManager::printGenre(const model::Genre& genre)
{
std::cout << "genre record" << std::endl;
std::cout << "id: " << genre.id << std::endl;
std::cout << "category: " << genre.category << std::endl;
}
@@ -1,4 +1,4 @@
#include "managers/song_manager.h"
#include "manager/SongManager.h"
#include <fstream>
#include <filesystem>
@@ -6,60 +6,60 @@
#include <nlohmann/json.hpp>
#include "database/coverArtRepository.h"
#include "database/songRepository.h"
#include "managers/albumManager.h"
#include "managers/artistManager.h"
#include "managers/coverArtManager.h"
#include "managers/directory_manager.h"
#include "managers/genreManager.h"
#include "managers/yearManager.h"
#include "utilities/metadata_retriever.h"
#include "database/CoverArtRepository.h"
#include "database/SongRepository.h"
#include "manager/AlbumManager.h"
#include "manager/ArtistManager.h"
#include "manager/CoverArtManager.h"
#include "manager/DirectoryManager.h"
#include "manager/GenreManager.h"
#include "manager/YearManager.h"
#include "utility/MetadataRetriever.h"
namespace fs = std::filesystem;
Manager::song_manager::song_manager(std::string& x_path)
manager::SongManager::SongManager(std::string& x_path)
: exe_path(x_path)
{ }
Manager::song_manager::song_manager(const Model::BinaryPath& bConf)
manager::SongManager::SongManager(const model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
void Manager::song_manager::saveSong(Model::Song& song)
void manager::SongManager::saveSong(model::Song& song)
{
saveSongTemp(song);
Utility::metadata_retriever meta;
utility::MetadataRetriever meta;
auto data = std::move(song.data);
song = meta.retrieve_metadata(song.songPath);
song = meta.retrieveMetadata(song.songPath);
song.data = std::move(data);
saveMisc(song);
printSong(song);
Database::songRepository songRepo(m_bConf);
database::SongRepository songRepo(m_bConf);
songRepo.saveRecord(song);
}
void Manager::song_manager::deleteSong(Model::Song& song)
void manager::SongManager::deleteSong(model::Song& song)
{
// TODO: handle what happens to miscellanes records
// like Album, Artist, Genre, etc. when a song
// is deleted
Database::coverArtRepository covRepo(m_bConf);
Database::songRepository songRepo(m_bConf);
database::CoverArtRepository covRepo(m_bConf);
database::SongRepository songRepo(m_bConf);
song = songRepo.retrieveRecord(song, Type::songFilter::id);
song = songRepo.retrieveRecord(song, type::SongFilter::id);
songRepo.deleteRecord(song);
Model::Cover cov;
model::Cover cov;
cov.id = song.coverArtId;
cov = covRepo.retrieveRecord(cov, Type::coverFilter::id);
cov = covRepo.retrieveRecord(cov, type::CoverFilter::id);
covRepo.deleteRecord(cov);
auto paths = Manager::directory_manager::pathConfigContent(m_bConf);
auto paths = manager::DirectoryManager::pathConfigContent(m_bConf);
const auto coverArtPath = paths["cover_root_path"].get<std::string>();
std::string stockCoverArtPath = coverArtPath;
stockCoverArtPath.append("CoverArt.png");
@@ -70,11 +70,11 @@ void Manager::song_manager::deleteSong(Model::Song& song)
}
fs::remove(song.songPath);
Manager::directory_manager::delete_directories(song, paths["root_music_path"].get<std::string>());
Manager::directory_manager::delete_directories(song, coverArtPath);
manager::DirectoryManager::deleteDirectories(song, paths["root_music_path"].get<std::string>());
manager::DirectoryManager::deleteDirectories(song, coverArtPath);
}
void Manager::song_manager::printSong(const Model::Song& song)
void manager::SongManager::printSong(const model::Song& song)
{
std::cout << "\nsong" << std::endl;
std::cout << "title: " << song.title << std::endl;
@@ -93,37 +93,37 @@ void Manager::song_manager::printSong(const Model::Song& song)
std::cout << "year id: " << song.yearId << std::endl;
}
void Manager::song_manager::saveSongTemp(Model::Song& song)
void manager::SongManager::saveSongTemp(model::Song& song)
{
auto config = Manager::directory_manager::pathConfigContent(m_bConf);
auto config = manager::DirectoryManager::pathConfigContent(m_bConf);
auto tmp_song = config["temp_root_path"].get<std::string>();
auto tmpSongPath = config["temp_root_path"].get<std::string>();
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");
tmpSongPath.append(std::to_string(dist(rng)));
tmpSongPath.append(".mp3");
std::fstream s(tmp_song, std::fstream::binary | std::fstream::out);
std::fstream s(tmpSongPath, std::fstream::binary | std::fstream::out);
s.write((char*)&song.data[0], song.data.size());
s.close();
song.songPath = tmp_song;
song.songPath = tmpSongPath;
}
void Manager::song_manager::saveMisc(Model::Song& song)
void manager::SongManager::saveMisc(model::Song& song)
{
coverArtManager covMgr(m_bConf);
auto pathConfigContent = Manager::directory_manager::pathConfigContent(m_bConf);
CoverArtManager covMgr(m_bConf);
auto pathConfigContent = manager::DirectoryManager::pathConfigContent(m_bConf);
auto coverRootPath = pathConfigContent["cover_root_path"].get<std::string>();
auto musicRootPath = pathConfigContent["root_music_path"].get<std::string>();
auto stockCoverPath = Manager::directory_manager::configPath(m_bConf);
auto stockCoverPath = manager::DirectoryManager::configPath(m_bConf);
stockCoverPath.append("/CoverArt.png");
auto cov = covMgr.saveCover(song, coverRootPath, stockCoverPath);
auto songPath = Manager::directory_manager::create_directory_process(song, musicRootPath);
auto songPath = manager::DirectoryManager::createDirectoryProcess(song, musicRootPath);
songPath.append(song.title);
songPath.append(".mp3");
if (fs::exists(songPath)) {
@@ -135,25 +135,25 @@ void Manager::song_manager::saveMisc(Model::Song& song)
fs::remove(song.songPath);
song.songPath = std::move(songPath);
albumManager albMgr(m_bConf);
AlbumManager albMgr(m_bConf);
auto album = albMgr.saveAlbum(song);
album = albMgr.retrieveAlbum(album);
Manager::albumManager::printAlbum(album);
manager::AlbumManager::printAlbum(album);
artistManager artMgr(m_bConf);
ArtistManager artMgr(m_bConf);
auto artist = artMgr.saveArtist(song);
artist = artMgr.retrieveArtist(artist);
Manager::artistManager::printArtist(artist);
manager::ArtistManager::printArtist(artist);
genreManager gnrMgr(m_bConf);
GenreManager gnrMgr(m_bConf);
auto genre = gnrMgr.saveGenre(song);
genre = gnrMgr.retrieveGenre(genre);
Manager::genreManager::printGenre(genre);
manager::GenreManager::printGenre(genre);
yearManager yrMgr(m_bConf);
YearManager yrMgr(m_bConf);
auto year = yrMgr.saveYear(song);
year = yrMgr.retrieveYear(year);
Manager::yearManager::printYear(year);
manager::YearManager::printYear(year);
song.coverArtId = cov.id;
song.albumId = album.id;
+196
View File
@@ -0,0 +1,196 @@
#include "manager/TokenManager.h"
#include <iostream>
#include <iterator>
#include <fstream>
#include <filesystem>
#include <string>
#include <string_view>
#include <sstream>
#include <cstdlib>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include "manager/DirectoryManager.h"
namespace fs = std::filesystem;
manager::TokenManager::TokenManager()
{
}
model::LoginResult manager::TokenManager::retrieveToken()
{
model::LoginResult lr;
lr.accessToken = "dsfdsf";
lr.tokenType = "demo";
return lr;
}
model::LoginResult manager::TokenManager::retrieveToken(std::string_view path)
{
auto cred = parseAuthCredentials(path);
nlohmann::json reqObj;
reqObj["client_id"] = cred.clientId;
reqObj["client_secret"] = cred.clientSecret;
reqObj["audience"] = cred.apiIdentifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri};
uri.append("/");
uri.append(cred.endpoint);
auto r = cpr::Post(cpr::Url{uri},
cpr::Body{reqObj.dump()},
cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}});
auto postRes = nlohmann::json::parse(r.text);
model::LoginResult lr;
lr.accessToken = postRes["access_token"].get<std::string>();
lr.tokenType = postRes["token_type"].get<std::string>();
lr.expiration = postRes["expires_in"].get<int>();
return lr;
}
model::LoginResult manager::TokenManager::retrieveToken(const model::BinaryPath& bConf)
{
auto cred = parseAuthCredentials(bConf);
nlohmann::json reqObj;
reqObj["client_id"] = cred.clientId;
reqObj["client_secret"] = cred.clientSecret;
reqObj["audience"] = cred.apiIdentifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri};
uri.append("/");
uri.append(cred.endpoint);
auto r = cpr::Post(cpr::Url{uri},
cpr::Body{reqObj.dump()},
cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}});
auto postRes = nlohmann::json::parse(r.text);
model::LoginResult lr;
lr.accessToken = postRes["access_token"].get<std::string>();
lr.tokenType = postRes["token_type"].get<std::string>();
lr.expiration = postRes["expires_in"].get<int>();
return lr;
}
bool manager::TokenManager::isTokenValid(std::string& auth, type::Scope scope)
{
auto authPair = fetchAuthHeader(auth);
if (!std::get<0>(authPair)) {
std::cout << "no Bearer found" << std::endl;
return std::get<0>(authPair);
}
auto authHeader = std::get<1>(authPair);
auto token = authHeader.at(authHeader.size()-1);
auto scopes = extractScopes(jwt::decode(token));
switch (scope) {
case type::Scope::upload:
return tokenSupportsScope(scopes, "upload:songs");
break;
case type::Scope::download:
return tokenSupportsScope(scopes, "download:songs");
default:
break;
}
return false;
}
model::AuthCredentials manager::TokenManager::parseAuthCredentials(std::string_view path)
{
auto exe_path = manager::DirectoryManager::configPath(path);
exe_path.append("/authcredentials.json");
auto con = manager::DirectoryManager::credentialConfigContent(exe_path);
model::AuthCredentials auth;
auth.uri = "https://";
auth.uri.append(con["domain"]);
auth.apiIdentifier = con["api_identifier"];
auth.clientId = con["client_id"];
auth.clientSecret = con["client_secret"];
auth.endpoint = "oauth/token";
return auth;
}
model::AuthCredentials manager::TokenManager::parseAuthCredentials(const model::BinaryPath& bConf)
{
auto exePath = manager::DirectoryManager::configPath(bConf);
exePath.append("/authcredentials.json");
auto con = manager::DirectoryManager::credentialConfigContent(exePath);
model::AuthCredentials auth;
auth.uri = "https://";
auth.uri.append(con["domain"]);
auth.apiIdentifier = con["api_identifier"];
auth.clientId = con["client_id"];
auth.clientSecret = con["client_secret"];
auth.endpoint = "oauth/token";
return auth;
}
std::vector<std::string> manager::TokenManager::extractScopes(const jwt::decoded_jwt&& decoded)
{
std::vector<std::string> scopes;
for (auto d : decoded.get_payload_claims()) {
if (d.first.compare("scope") == 0) {
std::cout << "found scope" << std::endl;
std::string allScopes(d.second.to_json().get<std::string>());
std::istringstream iss(allScopes);
scopes.assign(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>());
}
}
return scopes;
}
std::pair<bool, std::vector<std::string>> manager::TokenManager::fetchAuthHeader(const std::string& auth)
{
std::istringstream iss(auth);
std::vector<std::string> authHeader{std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>()
};
bool foundBearer = false;
if (std::any_of(authHeader.begin(), authHeader.end(),
[](std::string word) {
return (word.compare("Bearer") == 0);
})) {
std::cout << "Bearer found" << std::endl;
foundBearer = true;
}
return std::make_pair(foundBearer, authHeader);
}
bool manager::TokenManager::tokenSupportsScope(const std::vector<std::string> scopes, const std::string&& scope)
{
return std::any_of(scopes.begin(), scopes.end(),
[&](std::string foundScope) {
return (foundScope.compare(scope) == 0);
});
}
+41
View File
@@ -0,0 +1,41 @@
#include "manager/YearManager.h"
#include <iostream>
#include "database/YearRepository.h"
#include "type/YearFilter.h"
manager::YearManager::YearManager(const model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
model::Year manager::YearManager::retrieveYear(model::Year& year)
{
database::YearRepository yearRepo(m_bConf);
year = yearRepo.retrieveRecord(year, type::YearFilter::year);
return year;
}
model::Year manager::YearManager::saveYear(const model::Song& song)
{
model::Year year;
year.year = song.year;
database::YearRepository yearRepo(m_bConf);
if (!yearRepo.doesYearExist(year, type::YearFilter::year)) {
yearRepo.saveRecord(year);
} else {
std::cout << "year record already exists in the database" << std::endl;
}
return year;
}
void manager::YearManager::printYear(const model::Year& year)
{
std::cout << "\nyear record" << std::endl;
std::cout << "id: " << year.id << std::endl;
std::cout << "year: " << year.year << std::endl;
}
-45
View File
@@ -1,45 +0,0 @@
#include "managers/albumManager.h"
#include <iostream>
#include "database/albumRepository.h"
#include "models/models.h"
#include "types/albumFilter.h"
Manager::albumManager::albumManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
Model::Album Manager::albumManager::retrieveAlbum(Model::Album& album)
{
Database::albumRepository albRepo(m_bConf);
album = std::move(albRepo.retrieveRecord(album, Type::albumFilter::title));
return album;
}
Model::Album Manager::albumManager::saveAlbum(const Model::Song& song)
{
Model::Album album;
album.title = song.album;
album.year = song.year;
Database::albumRepository albRepo(m_bConf);
if (!albRepo.doesAlbumExists(album, Type::albumFilter::title)) {
albRepo.saveAlbum(album);
} else {
std::cout << "album record already exists in the database" << std::endl;
}
return album;
}
void Manager::albumManager::printAlbum(const Model::Album& album)
{
std::cout << "\nalbum record" << std::endl;
std::cout << "id: " << album.id << std::endl;
std::cout << "title: " << album.title << std::endl;
std::cout << "year: " << album.year << std::endl;
}
-41
View File
@@ -1,41 +0,0 @@
#include "managers/artistManager.h"
#include <iostream>
#include "database/artistRepository.h"
#include "types/artistFilter.h"
Manager::artistManager::artistManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
Model::Artist Manager::artistManager::retrieveArtist(Model::Artist& artist)
{
Database::artistRepository artRepo(m_bConf);
artist = artRepo.retrieveRecord(artist, Type::artistFilter::artist);
return artist;
}
Model::Artist Manager::artistManager::saveArtist(const Model::Song& song)
{
Model::Artist artist;
artist.artist = song.artist;
Database::artistRepository artRepo(m_bConf);
if (!artRepo.doesArtistExist(artist, Type::artistFilter::artist)) {
artRepo.saveRecord(artist);
} else {
std::cout << "artist already exists" << std::endl;
}
return artist;
}
void Manager::artistManager::printArtist(const Model::Artist& artist)
{
std::cout << "\nartist record" << std::endl;
std::cout << "id: " << artist.id << std::endl;
std::cout << "artist: " << artist.artist << std::endl;
}
-34
View File
@@ -1,34 +0,0 @@
#include "managers/coverArtManager.h"
#include "database/coverArtRepository.h"
#include "types/coverFilter.h"
#include "utilities/metadata_retriever.h"
Manager::coverArtManager::coverArtManager(const std::string& configPath) : path(configPath)
{ }
Manager::coverArtManager::coverArtManager(const Model::BinaryPath& bConf) : m_bConf(bConf)
{ }
Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
{
Utility::metadata_retriever meta;
Model::Cover cov;
cov.imagePath = rootPath;
cov = meta.update_cover_art(song, cov, stockCoverPath);
cov.songTitle = song.title;
Database::coverArtRepository covRepo(m_bConf);
if (!covRepo.doesCoverArtExist(cov, Type::coverFilter::songTitle)) {
std::cout << "saving image record to the database" << std::endl;
covRepo.saveRecord(cov);
} else {
std::cout << "cover art record already exists" << std::endl;
}
std::cout << "retrieving image record from database" << std::endl;
cov = covRepo.retrieveRecord(cov, Type::coverFilter::songTitle);
return cov;
}
-155
View File
@@ -1,155 +0,0 @@
#include <iostream>
#include <filesystem>
#include <fstream>
#include <sstream>
#include "managers/directory_manager.h"
namespace fs = std::filesystem;
std::string Manager::directory_manager::create_directory_process(Model::Song song, const std::string& root_path)
{
auto curr_path = fs::path(root_path);
if (fs::exists(curr_path)) {
std::cout<<"path exists"<<std::endl;
} else {
std::cout<<"creating path"<<std::endl;
fs::create_directory(curr_path);
}
auto art_path = fs::path(curr_path.string() + song.artist);
if (fs::exists(art_path)) {
std::cout<<"artist path exists"<<std::endl;
} else {
std::cout<<"creating artist path"<<std::endl;
fs::create_directory(art_path);
}
auto alb_path = fs::path(art_path.string() + "/" + song.album);
if (fs::exists(alb_path)) {
std::cout<<"album path exists"<<std::endl;
} else {
std::cout<<"creating album path"<<std::endl;
fs::create_directory(alb_path);
}
return alb_path.string() + "/";
}
std::string Manager::directory_manager::configPath(std::string_view path)
{
return fs::canonical(path).parent_path().string();
}
std::string Manager::directory_manager::configPath(const Model::BinaryPath& bConf)
{
return fs::canonical(bConf.path).parent_path().string();
}
std::string Manager::directory_manager::contentOfPath(const std::string& path)
{
std::fstream a(path, std::ios::in);
std::stringstream s;
s << a.rdbuf();
a.close();
return s.str();
}
/**
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 Manager::directory_manager::credentialConfigContent(const Model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/authcredentials.json");
return nlohmann::json::parse(contentOfPath(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 Manager::directory_manager::databaseConfigContent(const Model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/database.json");
return nlohmann::json::parse(contentOfPath(path));
}
/**
nlohmann::json Manager::directory_manager::pathConfigContent(const std::string& exe_path)
{
auto path = configPath(exe_path);
path.append("/paths.json");
return nlohmann::json::parse(contentOfPath(path));
}
*/
nlohmann::json Manager::directory_manager::pathConfigContent(const Model::BinaryPath& bConf)
{
auto path = configPath(bConf);
path.append("/paths.json");
return nlohmann::json::parse(contentOfPath(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;
} else {
std::cout << "deleting song path" << std::endl;
auto cov = fs::path(cov_path);
fs::remove(cov);
}
}
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};
const std::string alb{art + "/" + song.album};
auto alb_path = fs::path(alb);
if (!fs::exists(alb_path)) {
std::cout<<"directory does not exists"<<std::endl;
} else if (fs::is_empty(alb_path)) {
fs::remove(alb_path);
}
auto art_path = fs::path(art);
if (!fs::exists(art_path)) {
std::cout<<"directory does not exists"<<std::endl;
return;
} else if (fs::is_empty(art_path)) {
fs::remove(art_path);
}
std::cout<<"deleted empty directory or directories"<<std::endl;
}
void Manager::directory_manager::delete_song(const Model::Song song)
{
std::cout<<"deleting song"<<std::endl;
auto song_path = fs::path(song.songPath);
if (!fs::exists(song_path)) {
std::cout<<"song does not exists"<<std::endl;
return;
}
fs::remove(song_path);
std::cout<<"deleted song"<<std::endl;
}
-41
View File
@@ -1,41 +0,0 @@
#include "managers/genreManager.h"
#include <iostream>
#include "database/genreRepository.h"
#include "types/genreFilter.h"
Manager::genreManager::genreManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
Model::Genre Manager::genreManager::retrieveGenre(Model::Genre& genre)
{
Database::genreRepository gnrRepo(m_bConf);
genre = gnrRepo.retrieveRecord(genre, Type::genreFilter::category);
return genre;
}
Model::Genre Manager::genreManager::saveGenre(const Model::Song& song)
{
Model::Genre genre;
genre.category = song.genre;
Database::genreRepository gnrRepo(m_bConf);
if (!gnrRepo.doesGenreExist(genre, Type::genreFilter::category)) {
gnrRepo.saveRecord(genre);
} else {
std::cout << "genre record already exists" << std::endl;
}
return genre;
}
void Manager::genreManager::printGenre(const Model::Genre& genre)
{
std::cout << "genre record" << std::endl;
std::cout << "id: " << genre.id << std::endl;
std::cout << "category: " << genre.category << std::endl;
}
-196
View File
@@ -1,196 +0,0 @@
#include "managers/token_manager.h"
#include <iostream>
#include <iterator>
#include <fstream>
#include <filesystem>
#include <string>
#include <string_view>
#include <sstream>
#include <cstdlib>
#include <cpr/cpr.h>
#include <nlohmann/json.hpp>
#include "managers/directory_manager.h"
namespace fs = std::filesystem;
Manager::token_manager::token_manager()
{
}
Model::loginResult Manager::token_manager::retrieve_token()
{
Model::loginResult lr;
lr.access_token = "dsfdsf";
lr.token_type = "demo";
return lr;
}
Model::loginResult Manager::token_manager::retrieve_token(std::string_view path)
{
auto cred = parse_auth_credentials(path);
nlohmann::json reqObj;
reqObj["client_id"] = cred.client_id;
reqObj["client_secret"] = cred.client_secret;
reqObj["audience"] = cred.api_identifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri};
uri.append("/");
uri.append(cred.endpoint);
auto r = cpr::Post(cpr::Url{uri},
cpr::Body{reqObj.dump()},
cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}});
auto post_res = nlohmann::json::parse(r.text);
Model::loginResult lr;
lr.access_token = post_res["access_token"].get<std::string>();
lr.token_type = post_res["token_type"].get<std::string>();
lr.expiration = post_res["expires_in"].get<int>();
return lr;
}
Model::loginResult Manager::token_manager::retrieve_token(const Model::BinaryPath& bConf)
{
auto cred = parse_auth_credentials(bConf);
nlohmann::json reqObj;
reqObj["client_id"] = cred.client_id;
reqObj["client_secret"] = cred.client_secret;
reqObj["audience"] = cred.api_identifier;
reqObj["grant_type"] = "client_credentials";
std::string uri{cred.uri};
uri.append("/");
uri.append(cred.endpoint);
auto r = cpr::Post(cpr::Url{uri},
cpr::Body{reqObj.dump()},
cpr::Header{{"Content-Type", "application/json"},
{"Connection", "keep-alive"}});
auto post_res = nlohmann::json::parse(r.text);
Model::loginResult lr;
lr.access_token = post_res["access_token"].get<std::string>();
lr.token_type = post_res["token_type"].get<std::string>();
lr.expiration = post_res["expires_in"].get<int>();
return lr;
}
bool Manager::token_manager::is_token_valid(std::string& auth, Type::Scope scope)
{
auto authPair = fetch_auth_header(auth);
if (!std::get<0>(authPair)) {
std::cout << "no Bearer found" << std::endl;
return std::get<0>(authPair);
}
auto authHeader = std::get<1>(authPair);
auto token = authHeader.at(authHeader.size()-1);
auto scopes = extract_scopes(jwt::decode(token));
switch (scope) {
case Type::Scope::upload:
return token_supports_scope(scopes, "upload:songs");
break;
case Type::Scope::download:
return token_supports_scope(scopes, "download:songs");
default:
break;
}
return false;
}
Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::string_view path)
{
auto exe_path = Manager::directory_manager::configPath(path);
exe_path.append("/authcredentials.json");
auto con = Manager::directory_manager::credentialConfigContent(exe_path);
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;
}
Model::auth_credentials Manager::token_manager::parse_auth_credentials(const Model::BinaryPath& bConf)
{
auto exePath = Manager::directory_manager::configPath(bConf);
exePath.append("/authcredentials.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> scopes;
for (auto d : decoded.get_payload_claims()) {
if (d.first.compare("scope") == 0) {
std::cout << "found scope" << std::endl;
std::string all_scopes(d.second.to_json().get<std::string>());
std::istringstream iss(all_scopes);
scopes.assign(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>());
}
}
return scopes;
}
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),
std::istream_iterator<std::string>()
};
bool foundBearer = false;
if (std::any_of(authHeader.begin(), authHeader.end(),
[](std::string word) {
return (word.compare("Bearer") == 0);
})) {
std::cout << "Bearer found" << std::endl;
foundBearer = true;
}
return std::make_pair(foundBearer, authHeader);
}
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) {
return (foundScope.compare(scope) == 0);
});
}
-41
View File
@@ -1,41 +0,0 @@
#include "managers/yearManager.h"
#include <iostream>
#include "database/yearRepository.h"
#include "types/yearFilter.h"
Manager::yearManager::yearManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
Model::Year Manager::yearManager::retrieveYear(Model::Year& year)
{
Database::yearRepository yearRepo(m_bConf);
year = yearRepo.retrieveRecord(year, Type::yearFilter::year);
return year;
}
Model::Year Manager::yearManager::saveYear(const Model::Song& song)
{
Model::Year year;
year.year = song.year;
Database::yearRepository yearRepo(m_bConf);
if (!yearRepo.doesYearExist(year, Type::yearFilter::year)) {
yearRepo.saveRecord(year);
} else {
std::cout << "year record already exists in the database" << std::endl;
}
return year;
}
void Manager::yearManager::printYear(const Model::Year& year)
{
std::cout << "\nyear record" << std::endl;
std::cout << "id: " << year.id << std::endl;
std::cout << "year: " << year.year << std::endl;
}
-10
View File
@@ -1,10 +0,0 @@
#include "utilities/imageFile.h"
Utility::imageFile::imageFile(const char *file) : TagLib::File(file)
{
}
TagLib::ByteVector Utility::imageFile::data()
{
return readBlock(length());
}
+10
View File
@@ -0,0 +1,10 @@
#include "utility/ImageFile.h"
utility::ImageFile::ImageFile(const char *file) : TagLib::File(file)
{
}
TagLib::ByteVector utility::ImageFile::data()
{
return readBlock(length());
}
@@ -11,16 +11,16 @@
#include <mpegfile.h>
#include <tag.h>
#include "managers/directory_manager.h"
#include "utilities/imageFile.h"
#include "utilities/metadata_retriever.h"
#include "manager/DirectoryManager.h"
#include "utility/ImageFile.h"
#include "utility/MetadataRetriever.h"
namespace fs = std::filesystem;
Model::Song Utility::metadata_retriever::retrieve_metadata(std::string& song_path)
model::Song utility::MetadataRetriever::retrieveMetadata(std::string& songPath)
{
TagLib::FileRef file(song_path.c_str());
Model::Song song;
TagLib::FileRef file(songPath.c_str());
model::Song song;
song.title = file.tag()->title().toCString();
song.artist = file.tag()->artist().toCString();
song.album = file.tag()->album().toCString();
@@ -28,12 +28,12 @@ Model::Song Utility::metadata_retriever::retrieve_metadata(std::string& song_pat
song.year = file.tag()->year();
song.track = file.tag()->track();
song.duration = file.audioProperties()->lengthInSeconds();
song.songPath = song_path;
song.songPath = songPath;
// TODO: Move over to this eventually since at the moment
// I am only targetting mp3 files
// Used to retrieve disc
TagLib::MPEG::File sameFile(song_path.c_str());
TagLib::MPEG::File sameFile(songPath.c_str());
auto tag = sameFile.ID3v2Tag();
auto frame = tag->frameList("TPOS");
@@ -48,7 +48,7 @@ Model::Song Utility::metadata_retriever::retrieve_metadata(std::string& song_pat
return song;
}
Model::Cover Utility::metadata_retriever::update_cover_art(const Model::Song& song, Model::Cover& cov, const std::string& stockCoverPath)
model::Cover utility::MetadataRetriever::updateCoverArt(const model::Song& song, model::Cover& cov, const std::string& stockCoverPath)
{
TagLib::MPEG::File sngF(song.songPath.c_str());
auto tag = sngF.ID3v2Tag();
@@ -62,11 +62,11 @@ Model::Cover Utility::metadata_retriever::update_cover_art(const Model::Song& so
fs::copy(stockCoverPath, cov.imagePath);
}
imageFile stock_img(cov.imagePath.c_str());
ImageFile stockImg(cov.imagePath.c_str());
TagLib::ID3v2::AttachedPictureFrame *pic =
new TagLib::ID3v2::AttachedPictureFrame;
pic->setPicture(stock_img.data());
pic->setPicture(stockImg.data());
pic->setType(TagLib::ID3v2::AttachedPictureFrame::FrontCover);
tag->addFrame(pic);
@@ -77,42 +77,40 @@ Model::Cover Utility::metadata_retriever::update_cover_art(const Model::Song& so
auto frame = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(
frameList.front());
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;
auto imgPath = manager::DirectoryManager::createDirectoryProcess(song, cov.imagePath);
imgPath.append(song.title);
imgPath.append(".png");
cov.imagePath = imgPath;
std::cout << cov.imagePath << std::endl;
std::fstream img_save(cov.imagePath, std::ios::out |
std::fstream imgSave(cov.imagePath, std::ios::out |
std::ios::binary);
img_save.write(frame->picture().data(), frame->picture().size());
img_save.close();
imgSave.write(frame->picture().data(), frame->picture().size());
imgSave.close();
std::cout << "saved to " << cov.imagePath << std::endl;
}
return cov;
}
void Utility::metadata_retriever::update_metadata(Model::Song sng_updated, const Model::Song sng_old)
void utility::MetadataRetriever::updateMetadata(model::Song& sngUpdated, const model::Song& sngOld)
{
std::cout<<"updating metadata"<<std::endl;
TagLib::FileRef file(sng_old.songPath.c_str());
TagLib::FileRef file(sngOld.songPath.c_str());
if (sng_updated.title.size() > 0) {
file.tag()->setTitle(sng_updated.title);
if (sngUpdated.title.size() > 0) {
file.tag()->setTitle(sngUpdated.title);
}
if (sng_updated.artist.size() > 0) {
file.tag()->setArtist(sng_updated.artist);
if (sngUpdated.artist.size() > 0) {
file.tag()->setArtist(sngUpdated.artist);
}
if (sng_updated.album.size() > 0) {
file.tag()->setAlbum(sng_updated.album);
if (sngUpdated.album.size() > 0) {
file.tag()->setAlbum(sngUpdated.album);
}
if (sng_updated.genre.size() > 0) {
file.tag()->setGenre(sng_updated.genre);
if (sngUpdated.genre.size() > 0) {
file.tag()->setGenre(sngUpdated.genre);
}
if (sng_updated.year > 0) {
file.tag()->setYear(sng_updated.year);
if (sngUpdated.year > 0) {
file.tag()->setYear(sngUpdated.year);
}
// TODO: functionality to update the track number and disc number