From eb928d0f9ee9e5a1edc846a2c7f8778c8635c7a2 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 19 Dec 2020 11:51:15 -0500 Subject: [PATCH] Made some more changes --- CMakeLists.txt | 10 +- include/component/AppComponent.hpp | 7 +- include/controller/LoginController.hpp | 2 - include/controller/RegisterController.hpp | 25 +++-- include/controller/SongController.hpp | 9 +- include/dto/AlbumDto.hpp | 6 +- include/dto/ArtistDto.hpp | 6 +- include/dto/CoverArtDto.hpp | 6 +- include/dto/GenreDto.hpp | 6 +- include/dto/LoginResultDto.hpp | 16 ++-- include/dto/SongDto.hpp | 7 +- include/dto/YearDto.hpp | 6 +- include/dto/conversion/DtoConversions.h | 44 ++++----- include/verify/Initialization.h | 108 ++++++++++++++++++++-- src/Main.cpp | 36 ++++---- src/dto/conversion/DtoConversions.cpp | 101 -------------------- src/verify/Initialization.cpp | 98 -------------------- 17 files changed, 198 insertions(+), 295 deletions(-) delete mode 100644 src/dto/conversion/DtoConversions.cpp delete mode 100644 src/verify/Initialization.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2497bde..3c87ed7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ project(icarus) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 17) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + set(SOURCES src/callback/StreamCallback.cpp src/database/AlbumRepository.cpp @@ -15,7 +17,6 @@ set(SOURCES src/database/SongRepository.cpp src/database/UserRepository.cpp src/database/YearRepository.cpp - # src/dto/conversion/DtoConversions.cpp src/Main.cpp src/manager/AlbumManager.cpp src/manager/ArtistManager.cpp @@ -29,7 +30,6 @@ set(SOURCES src/utility/ImageFile.cpp src/utility/MetadataRetriever.cpp src/utility/PasswordEncryption.cpp - src/verify/Initialization.cpp ) @@ -46,7 +46,6 @@ set (BCRYPTLIB include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB}) -# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) add_library(bcrypt STATIC IMPORTED) @@ -59,7 +58,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/authcredentials.json ${CMAKE_BINARY_D configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin/database.json COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/paths.json COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Images/Stock/CoverArt.png ${CMAKE_BINARY_DIR}/bin/CoverArt.png COPYONLY) -# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build/icarus ${CMAKE_BINARY_DIR}/bin/icarus COPYONLY) find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h") @@ -67,10 +65,10 @@ find_package(nlohmann_json CONFIG REQUIRED) find_package(cpr CONFIG REQUIRED) find_package(oatpp CONFIG REQUIRED) + + add_executable(icarus ${SOURCES}) - - target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS}) target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp::oatpp tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) diff --git a/include/component/AppComponent.hpp b/include/component/AppComponent.hpp index 47de59a..f89c6a9 100644 --- a/include/component/AppComponent.hpp +++ b/include/component/AppComponent.hpp @@ -4,7 +4,6 @@ #include #include "oatpp/core/macro/component.hpp" -// #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/web/server/HttpConnectionHandler.hpp" @@ -15,8 +14,7 @@ namespace component { OATPP_CREATE_COMPONENT(std::shared_ptr, serverConnectionProvider)([&] { - // return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort(), oatpp::network::Address::IP_4}); - return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort(), oatpp::network::Address::IP_4}); + return oatpp::network::tcp::server::ConnectionProvider::createShared({"127.0.0.1", appPort(), oatpp::network::Address::IP_4}); }()); OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] @@ -39,8 +37,7 @@ namespace component { }()); private: template - // constexpr Val appPort() noexcept - Val appPort() noexcept + constexpr Val appPort() noexcept { return 5002; } diff --git a/include/controller/LoginController.hpp b/include/controller/LoginController.hpp index 5cf1c16..1b6c3d4 100644 --- a/include/controller/LoginController.hpp +++ b/include/controller/LoginController.hpp @@ -48,8 +48,6 @@ namespace controller return createDtoResponse(Status::CODE_401, logRes); } - std::cout << "user exists\n"; - manager::TokenManager tok; auto token = tok.retrieveToken(m_bConf); diff --git a/include/controller/RegisterController.hpp b/include/controller/RegisterController.hpp index 42862eb..ac3001c 100644 --- a/include/controller/RegisterController.hpp +++ b/include/controller/RegisterController.hpp @@ -6,6 +6,7 @@ #include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/component.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/web/server/api/ApiController.hpp" #include "dto/LoginResultDto.hpp" @@ -13,20 +14,30 @@ #include "manager/UserManager.h" #include "model/Models.h" -namespace controller { - class RegisterController : public oatpp::web::server::api::ApiController { +using namespace dto; + +namespace controller +{ + class RegisterController : public oatpp::web::server::api::ApiController + { public: RegisterController(const model::BinaryPath& bConf, - OATPP_COMPONENT(std::shared_ptr, objectMapper)) : - oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } + OATPP_COMPONENT(std::shared_ptr, objectMapper)) : + oatpp::web::server::api::ApiController(objectMapper), + m_bConf(bConf) + { + } #include OATPP_CODEGEN_BEGIN(ApiController) ENDPOINT("POST", "api/v1/register", registerUser, - // BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { - BODY_DTO(oatpp::data::mapping::type::ObjectWrapper, usr)) { + BODY_DTO(oatpp::Object, usr)) + { manager::UserManager usrMgr(m_bConf); - auto user = dto::conversion::DtoConversions::toUser(usr); + auto user = conversion::DtoConversions::toUser(usr); + + OATPP_LOGI("icarus", "Dto converted"); + if (usrMgr.doesUserExist(user)) { return createResponse(Status::CODE_401, "user already exists"); } diff --git a/include/controller/SongController.hpp b/include/controller/SongController.hpp index 579deff..a16551d 100644 --- a/include/controller/SongController.hpp +++ b/include/controller/SongController.hpp @@ -53,7 +53,6 @@ namespace controller // endpoint for uploading a song ENDPOINT("POST", "/api/v1/song/data", songUpload, - //AUTHORIZATION(std::shared_ptr, authObject), REQUEST(std::shared_ptr, request)) { auto authHeader = request->getHeader("Authorization"); @@ -69,13 +68,8 @@ namespace controller std::make_shared (request->getHeaders()); - // oatpp::web::mime::multipart::Reader mp_reader(mp.get()); oatpp::web::mime::multipart::Reader mp_reader = mp.get(); - /** - mp_reader.setPartReader("file", - oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize)); - */ mp_reader.setDefaultPartReader( oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024)); @@ -83,7 +77,6 @@ namespace controller request->transferBody(&mp_reader); auto file = mp->getNamedPart("file"); - // auto file = mp->readNextPartSimple(); OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null"); @@ -266,7 +259,7 @@ namespace controller songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id); - auto dSize = 1024; + constexpr auto dSize = 1024; auto callback = std::make_shared(songDb.songPath); auto db = std::make_shared( diff --git a/include/dto/AlbumDto.hpp b/include/dto/AlbumDto.hpp index 482b236..4f3a3c6 100644 --- a/include/dto/AlbumDto.hpp +++ b/include/dto/AlbumDto.hpp @@ -4,10 +4,12 @@ #include #include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class AlbumDto : public oatpp::DTO { + class AlbumDto : public oatpp::DTO + { DTO_INIT(AlbumDto, DTO) DTO_FIELD(Int32, id); diff --git a/include/dto/ArtistDto.hpp b/include/dto/ArtistDto.hpp index 44f848f..b19fa18 100644 --- a/include/dto/ArtistDto.hpp +++ b/include/dto/ArtistDto.hpp @@ -5,10 +5,12 @@ #include "oatpp/core/Types.hpp" #include "oatpp/core/macro/codegen.hpp" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class ArtistDto : public oatpp::DTO { + class ArtistDto : public oatpp::DTO + { DTO_INIT(ArtistDto, DTO) DTO_FIELD(Int32, id); diff --git a/include/dto/CoverArtDto.hpp b/include/dto/CoverArtDto.hpp index 75f7786..e4e6133 100644 --- a/include/dto/CoverArtDto.hpp +++ b/include/dto/CoverArtDto.hpp @@ -4,10 +4,12 @@ #include "oatpp/core/macro/codegen.hpp" #include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class CoverArtDto : public oatpp::DTO { + class CoverArtDto : public oatpp::DTO + { DTO_INIT(CoverArtDto, DTO) DTO_FIELD(Int32, id); diff --git a/include/dto/GenreDto.hpp b/include/dto/GenreDto.hpp index 490a1bb..01cad84 100644 --- a/include/dto/GenreDto.hpp +++ b/include/dto/GenreDto.hpp @@ -4,10 +4,12 @@ #include "oatpp/core/macro/codegen.hpp" #include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class GenreDto : public oatpp::DTO { + class GenreDto : public oatpp::DTO + { DTO_INIT(GenreDto, DTO) DTO_FIELD(Int32, id); diff --git a/include/dto/LoginResultDto.hpp b/include/dto/LoginResultDto.hpp index 0479e7f..b7b10b2 100644 --- a/include/dto/LoginResultDto.hpp +++ b/include/dto/LoginResultDto.hpp @@ -1,17 +1,17 @@ #ifndef LOGINRESULTDTO_H_ #define LOGINRESULTDTO_H_ -// #include -#include #include +#include #include "model/Models.h" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - // class LoginResultDto : public oatpp::data::mapping::type::Object { - class LoginResultDto : public oatpp::DTO { + class LoginResultDto : public oatpp::DTO + { DTO_INIT(LoginResultDto, DTO) DTO_FIELD(oatpp::Int32, id); @@ -22,7 +22,8 @@ namespace dto { DTO_FIELD(oatpp::String, message); }; - class RegisterResultDto : public oatpp::DTO { + class RegisterResultDto : public oatpp::DTO + { DTO_INIT(RegisterResultDto, DTO) DTO_FIELD(oatpp::String, username); @@ -30,7 +31,8 @@ namespace dto { DTO_FIELD(oatpp::String, message); }; - class UserDto : public oatpp::DTO { + class UserDto : public oatpp::DTO + { DTO_INIT(UserDto, DTO) DTO_FIELD(oatpp::Int32, userId); diff --git a/include/dto/SongDto.hpp b/include/dto/SongDto.hpp index 90df52f..20840db 100644 --- a/include/dto/SongDto.hpp +++ b/include/dto/SongDto.hpp @@ -2,15 +2,16 @@ #define SONGDTO_H_ #include -// #include #include #include "model/Models.h" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class SongDto : public oatpp::DTO { + class SongDto : public oatpp::DTO + { DTO_INIT(SongDto, DTO) DTO_FIELD(oatpp::Int32, id); diff --git a/include/dto/YearDto.hpp b/include/dto/YearDto.hpp index e2c190b..8235cdd 100644 --- a/include/dto/YearDto.hpp +++ b/include/dto/YearDto.hpp @@ -4,10 +4,12 @@ #include "oatpp/core/macro/codegen.hpp" #include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class YearDto : public oatpp::DTO { + class YearDto : public oatpp::DTO + { DTO_INIT(YearDto, DTO) DTO_FIELD(Int32, id); diff --git a/include/dto/conversion/DtoConversions.h b/include/dto/conversion/DtoConversions.h index 5e38009..ae88641 100644 --- a/include/dto/conversion/DtoConversions.h +++ b/include/dto/conversion/DtoConversions.h @@ -1,6 +1,10 @@ #ifndef DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_ +#include +#include +#include + #include #include #include @@ -18,8 +22,10 @@ using namespace model; using namespace dto; -namespace dto { namespace conversion { - class DtoConversions { +namespace dto::conversion +{ + class DtoConversions + { public: template> static D toLoginResultDto(const User &user, const Token &token) @@ -124,22 +130,18 @@ namespace dto { namespace conversion { static Song toSong(const D &songDto) { Song song; - int id = songDto->id; - song.id = (songDto->id.getPtr() == nullptr) ? 0 : id; - auto title = songDto->title.get(); - /** - song.title = (songDto->title == nullptr) ? "" : songDto->title; - song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str(); - song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str(); + song.id = (songDto->id.getPtr() == nullptr) ? 0 : *songDto->id; + song.title = (songDto->title == nullptr) ? "" : songDto->title->c_str(); + song.album = (songDto->album == nullptr) ? "" : songDto->album->c_str(); + song.artist = (songDto->artist == nullptr) ? "" : songDto->artist->c_str(); song.albumArtist = (songDto->album_artist == nullptr) ? - "" : songDto->album_artist.c_str(); - song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str(); - song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue(); - song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue(); - song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue(); + "" : songDto->album_artist->c_str(); + song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str(); + song.year = (songDto->year.getPtr() == nullptr) ? 0 : *songDto->year; + song.track = (songDto->track.getPtr() == nullptr) ? 0 : *songDto->track; + song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : *songDto->disc; song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ? - 0 : songDto->coverart_id.getValue(); - */ + 0 : *songDto->coverart_id; return song; @@ -149,20 +151,20 @@ namespace dto { namespace conversion { static User toUser(const D &userDto) { User user; - int id = userDto->userId; - /** - user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId.getValue(); + user.id = (userDto->userId.getPtr()) ? 0 : *userDto->userId; user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str(); user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str(); user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str(); user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str(); user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str(); user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str(); - */ + + + std::cout << "Over\n"; return user; } }; -}} +} #endif diff --git a/include/verify/Initialization.h b/include/verify/Initialization.h index 25d6a5b..a836e38 100644 --- a/include/verify/Initialization.h +++ b/include/verify/Initialization.h @@ -1,22 +1,114 @@ #ifndef INITIALIZATION_H_ #define INITIALIZATION_H_ +#include +#include #include +#include +#include +#include "database/BaseRepository.h" +#include "manager/DirectoryManager.h" +#include "manager/TokenManager.h" #include "model/Models.h" +#include "type/PathType.h" -namespace verify { - class Initialization { +namespace fs = std::filesystem; + +namespace verify +{ + template + class Initialization + { public: - static bool skipVerification(const std::string&); + static bool skipVerification(const std::string &argument) noexcept + { + return argument.compare("--noverify") == 0; + } - static void checkIcarus(const model::BinaryPath&); + static void checkIcarus(const Config &bConf) + { + auto auth = confirmConfigAuth(bConf); + auto database = confirmConfigDatabase(bConf); + auto path = confirmConfigPaths(bConf); + + if ((!auth) && (!database) && (!path)) { + failedConfirmation(); + } + + std::cout << "icarus check passed\n"; + } private: - static bool confirmConfigAuth(const model::BinaryPath&); - static bool confirmConfigDatabase(const model::BinaryPath&); - static bool confirmConfigPaths(const model::BinaryPath&); + static bool confirmConfigAuth(const Config &bConf) + { + manager::TokenManager tokMgr; - static void failedConfirmation(); + return tokMgr.testAuth(bConf); + } + + static bool confirmConfigDatabase(const Config &bConf) + { + database::BaseRepository baseRepo(bConf); + + return baseRepo.testConnection(); + } + static bool confirmConfigPaths(const Config &bConf) + { + using manager::DirectoryManager; + using namespace type; + + auto pathConfig = DirectoryManager::pathConfigContent(bConf); + const auto musicType = PathType::music; + const auto archiveType = PathType::archive; + const auto tempRootType = PathType::temp; + const auto coverArtType = PathType::coverArt; + + auto rootMusicPath = + pathConfig[DirectoryManager::retrievePathType(musicType)]; + auto archiveRootPath = + pathConfig + [DirectoryManager::retrievePathType(archiveType)]; + auto tempRootPath = + pathConfig + [DirectoryManager::retrievePathType(tempRootType)]; + + auto coverRootPath = + pathConfig + [DirectoryManager::retrievePathType(coverArtType)]; + + std::vector paths; + paths.reserve(4); + paths.emplace_back(std::move(rootMusicPath)); + paths.emplace_back(std::move(archiveRootPath)); + paths.emplace_back(std::move(tempRootPath)); + paths.emplace_back(std::move(coverRootPath)); + + return confirmMultiplePaths(paths); + } + + static void failedConfirmation() + { + std::cout << "configuration confirmation failed. check your settings\n"; + std::exit(-1); + } + + template> + static bool confirmMultiplePaths(const Container &con) + { + auto result = true; + + for (auto &path : con) + { + if (!fs::exists(path)) + { + std::cout << path << " is not properly configured\n"; + return false; + } + } + + + return result; + } }; } diff --git a/src/Main.cpp b/src/Main.cpp index 8fbbb36..71fddd2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,19 +1,13 @@ -#include #include -#include +#include #include #include #include -// #include -// #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -// #include "oatpp/web/server/HttpConnectionHandler.hpp" #include -// #include #include -// #include #include @@ -29,12 +23,11 @@ #include "model/Models.h" #include "verify/Initialization.h" -namespace fs = std::filesystem; -void run(const model::BinaryPath& bConf) { +void run(const model::BinaryPath& bConf) +{ component::AppComponent component; - // OATPP_COMPONENT(std::shared_ptr, router); auto router = oatpp::web::server::HttpRouter::createShared(); auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router); @@ -57,8 +50,6 @@ void run(const model::BinaryPath& bConf) { sngController->addEndpointsToRouter(router); yearController->addEndpointsToRouter(router); - // OATPP_COMPONENT(std::shared_ptr, connectionHandler); - OATPP_COMPONENT(std::shared_ptr, connectionProvider); oatpp::network::Server server(connectionProvider, connectionHandler); @@ -68,19 +59,26 @@ void run(const model::BinaryPath& bConf) { server.run(); } -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ oatpp::base::Environment::init(); model::BinaryPath bConf(std::move(argv[0])); - if (argc > 1) { - if (!verify::Initialization::skipVerification(argv[1])) { - verify::Initialization::checkIcarus(bConf); - } else { + if (argc > 1) + { + if (!verify::Initialization<>::skipVerification(argv[1])) + { + verify::Initialization<>::checkIcarus(bConf); + } + else + { std::cout << "skiping verifyication\n"; } - } else { - verify::Initialization::checkIcarus(bConf); + } + else + { + verify::Initialization<>::checkIcarus(bConf); } run(bConf); diff --git a/src/dto/conversion/DtoConversions.cpp b/src/dto/conversion/DtoConversions.cpp deleted file mode 100644 index 1391413..0000000 --- a/src/dto/conversion/DtoConversions.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "dto/conversion/DtoConversions.h" - - -namespace dto { namespace conversion { - // LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, - // dto::LoginResultDto DtoConversions::toLoginResultDto(const model::User& user, - - /** - oatpp::data::mapping::type::DTOWrapper DtoConversions::toLoginResultDto(const model::User& user, - } - */ - - - // dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto( - /** - dto::RegisterResultDto DtoConversions::toRegisterResultDto( - const model::RegisterResult& regRes) { - auto result = dto::RegisterResultDto::createShared(); - result->message = regRes.message.c_str(); - result->registered = regRes.registered; - result->username = regRes.username.c_str(); - - return result; - } - */ - - - // dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) { - /** - dto::AlbumDto DtoConversions::toAlbumDto(const model::Album& album) { - auto result = dto::AlbumDto::createShared(); - result->id = (album.id != 0) ? album.id : 0; - result->title = (!album.title.empty()) ? album.title.c_str() : ""; - result->artist = (!album.artist.empty()) ? album.artist.c_str() : ""; - result->year = (album.year != 0) ? album.year : 0; - - return result; - } - */ - - - // dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) { - /** - dto::SongDto DtoConversions::toSongDto(const model::Song& song) { - auto result = dto::SongDto::createShared(); - result->id = (song.id != 0) ? song.id : 0; - result->title = (!song.title.empty()) ? song.title.c_str() : ""; - result->album = (!song.album.empty()) ? song.album.c_str() : ""; - result->artist = (!song.artist.empty()) ? song.artist.c_str() : ""; - result->album_artist = (!song.albumArtist.empty()) ? song.albumArtist.c_str() : ""; - result->genre = (!song.genre.empty()) ? song.genre.c_str() : ""; - result->duration = (song.duration != 0) ? song.duration : 0; - result->year = (song.year != 0) ? song.year : 0; - result->track = (song.track != 0) ? song.track : 0; - result->disc = (song.disc != 0) ? song.disc : 0; - result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0; - - return result; - } - */ - - - // model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) { - /** - model::Song DtoConversions::toSong(dto::SongDto *songDto) { - model::Song song; - song.id = (songDto->id.getPtr() == nullptr) ? 0 : songDto->id->getValue(); - song.title = (songDto->title == nullptr) ? "" : songDto->title.c_str(); - song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str(); - song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str(); - song.albumArtist = (songDto->album_artist == nullptr) ? - "" : songDto->album_artist.c_str(); - song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str(); - song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue(); - song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue(); - song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue(); - song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ? - 0 : songDto->coverart_id.getValue(); - - return song; - } - */ - - - // model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) { - model::User DtoConversions::toUser(dto::UserDto &userDto) { - model::User user; - // TODO: Can't leave it like this - /** - user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue(); - user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str(); - user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str(); - user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str(); - user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str(); - user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str(); - user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str(); - */ - - return user; - } -}} diff --git a/src/verify/Initialization.cpp b/src/verify/Initialization.cpp deleted file mode 100644 index 3ce220e..0000000 --- a/src/verify/Initialization.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "verify/Initialization.h" - -#include -#include - -#include "database/BaseRepository.h" -#include "manager/DirectoryManager.h" -#include "manager/TokenManager.h" -#include "type/PathType.h" - -namespace fs = std::filesystem; - -namespace verify { - bool Initialization::skipVerification(const std::string& argument) { - return argument.compare("--noverify") == 0; - } - - - // verifies if the configuration settings are valid - void Initialization::checkIcarus(const model::BinaryPath& bConf) { - auto auth = confirmConfigAuth(bConf); - auto database = confirmConfigDatabase(bConf); - auto path = confirmConfigPaths(bConf); - - if ((!auth) && (!database) && (!path)) { - failedConfirmation(); - } - - std::cout << "icarus check passed\n"; - } - - - // verifies that the authorization settings are not the default values - bool Initialization::confirmConfigAuth(const model::BinaryPath& bConf) { - manager::TokenManager tokMgr; - - return tokMgr.testAuth(bConf); - } - - // verifies if database connectivity can be established - bool Initialization::confirmConfigDatabase(const model::BinaryPath& bConf) { - database::BaseRepository baseRepo(bConf); - - return baseRepo.testConnection(); - } - - // verifies if the paths found in the config files exists - bool Initialization::confirmConfigPaths(const model::BinaryPath& bConf) { - using manager::DirectoryManager; - auto pathConfig = DirectoryManager::pathConfigContent(bConf); - - const auto rootMusicPath = - pathConfig - [DirectoryManager::retrievePathType - (type::PathType::music)].get(); - const auto archiveRootPath = - pathConfig - [DirectoryManager::retrievePathType - (type::PathType::archive)].get(); - const auto tempRootPath = - pathConfig - [DirectoryManager::retrievePathType - (type::PathType::temp)].get(); - const auto coverRootPath = - pathConfig - [DirectoryManager::retrievePathType - (type::PathType::coverArt)].get(); - - if (!fs::exists(rootMusicPath)) { - std::cout << "root music path is not properly configured\n"; - return false; - } - - if (!fs::exists(archiveRootPath)) { - std::cout << "archive root path is not properly configured\n"; - return false; - } - - if (!fs::exists(tempRootPath)) { - std::cout << "temp root path is not properly configured\n"; - return false; - } - - if (!fs::exists(coverRootPath)) { - std::cout << "cover art root path is not properly configured\n"; - return false; - } - - return true; - } - - - // confirmation failed - void Initialization::failedConfirmation() { - std::cout << "configuration confirmation failed. check your settings\n"; - std::exit(-1); - } -}