diff --git a/.gitmodules b/.gitmodules index 4455ce3..cf103f8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,21 +1,12 @@ -[submodule "Libs/cpr"] - path = 3rdparty/cpr - url = https://github.com/whoshuu/cpr.git -[submodule "3rdparty/taglib"] - path = 3rdparty/taglib - url = https://github.com/taglib/taglib -[submodule "3rdparty/oatpp"] - path = 3rdparty/oatpp - url = https://github.com/oatpp/oatpp [submodule "build/3rdparty/jwt-cpp"] path = build/3rdparty/jwt-cpp url = https://github.com/Thalhammer/jwt-cpp -[submodule "3rdparty/jwt-cpp"] - path = 3rdparty/jwt-cpp - url = https://github.com/Thalhammer/jwt-cpp [submodule "3rdparty/ormpp"] path = 3rdparty/ormpp url = https://github.com/qicosmos/ormpp [submodule "3rdparty/libbcrypt"] path = 3rdparty/libbcrypt url = https://github.com/rg3/libbcrypt +[submodule "3rdparty/vcpkg"] + path = 3rdparty/vcpkg + url = https://github.com/microsoft/vcpkg diff --git a/3rdparty/cpr b/3rdparty/cpr deleted file mode 160000 index 07d784c..0000000 --- a/3rdparty/cpr +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 07d784ccfe6760fc6da47c24f7326e64d8e11460 diff --git a/3rdparty/jwt-cpp b/3rdparty/jwt-cpp deleted file mode 160000 index 65b632b..0000000 --- a/3rdparty/jwt-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 65b632b674da7fcc189adf7336c652108188aa29 diff --git a/3rdparty/oatpp b/3rdparty/oatpp deleted file mode 160000 index 27c4644..0000000 --- a/3rdparty/oatpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 27c46444dbac6af79172b1600c7fcc99ff6df42b diff --git a/3rdparty/taglib b/3rdparty/taglib deleted file mode 160000 index e36a9ca..0000000 --- a/3rdparty/taglib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e36a9cabb9882e61276161c23834d966d62073b7 diff --git a/3rdparty/vcpkg b/3rdparty/vcpkg new file mode 160000 index 0000000..ec6fe06 --- /dev/null +++ b/3rdparty/vcpkg @@ -0,0 +1 @@ +Subproject commit ec6fe06e8da05a8157dc8581fa96b36b571c1bd5 diff --git a/CMakeLists.txt b/CMakeLists.txt index de6886e..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,111 +30,22 @@ set(SOURCES src/utility/ImageFile.cpp src/utility/MetadataRetriever.cpp src/utility/PasswordEncryption.cpp - src/verify/Initialization.cpp -) -set(HEADERS - include/callback/StreamCallback.h - include/component/AppComponent.hpp - include/controller/AlbumController.hpp - include/controller/ArtistController.hpp - include/controller/CoverArtController.hpp - include/controller/GenreController.hpp - include/controller/LoginController.hpp - include/controller/RegisterController.hpp - include/controller/SongController.hpp - include/controller/YearController.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/UserRepository.h - include/database/YearRepository.h - include/dto/AlbumDto.hpp - include/dto/ArtistDto.hpp - include/dto/CoverArtDto.hpp - include/dto/GenreDto.hpp - include/dto/LoginResultDto.hpp - include/dto/SongDto.hpp - include/dto/YearDto.hpp - include/dto/conversion/DtoConversions.h - 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/UserManager.h - include/manager/YearManager.h - include/model/Models.h - include/utility/ImageFile.h - include/utility/MetadataRetriever.h - include/utility/PasswordEncryption.h - include/type/AlbumFilter.h - include/type/ArtistFilter.h - include/type/CoverFilter.h - include/type/GenreFilter.h - include/type/PathType.h - include/type/SaltFilter.h - include/type/Scopes.h - include/type/SongChanged.h - include/type/SongFilter.h - include/type/SongUpload.h - include/type/UserFilter.h - include/type/YearFilter.h - include/verify/Initialization.h ) -set (TAGLIB - ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib/3rdparty + +set(ICARUS_INCLUDE_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/include" ) set (BCRYPTLIB ${CMAKE_SOURCE_DIR}/3rdparty/libbcrypt ) -set(TAGLIB_HEADERS - "${CMAKE_SOURCE_DIR}/build/3rdparty/taglib" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/ape" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/asf" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/dsdiff" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/dsf" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/flac" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/it" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mod" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mp4" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpc" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg/id3v2" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg/id3v2/frames" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/ogg" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/riff" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/s3m" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/toolkit" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/trueaudio" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/wavpack" - "${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/xm" -) - -set(JWT_CPP_INCLUDE - ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/jwt-cpp/include -) - - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() #find_library(BCRYPT bcrypt ${BCRYPTLIB}) -include_directories(include ${CPR_INCLUDE_DIRS} ${TAGLIB} ${TAGLIB_HEADERS} ${BCRYPTLIB}) +include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB}) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cpr) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) add_library(bcrypt STATIC IMPORTED) @@ -147,6 +59,16 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin 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) -add_executable(icarus ${SOURCES} ${HEADERS}) -target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE}) -target_link_libraries(icarus "-lstdc++fs" tag oatpp mysqlclient ${CONAN_LIBS} ${CPR_LIBRARIES} bcrypt) +find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h") + +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/README.md b/README.md index d2b848f..360ce1a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ One can interface with Icarus the music server either by: * [cpr](https://www.github.com/whoshuu/cpr) * [TagLib](https://github.com/taglib/taglib) * [jwt-cpp](https://github.com/Thalhammer/jwt-cpp) +* libmariadb * [libbcrypt](https://github.com/rg3/libbcrypt) * [oatpp](https://github.com/oatpp/oatpp) @@ -149,14 +150,19 @@ From this point the database has been successfully created. Metadata and song fi ## Building and Running ``` git clone --recursive https://github.com/kdeng00/icarus -cd 3rdparty/libbcrypt/ + +cd icarus/3rdparty/vcpkg +./bootstrap-vcpkg.sh +./vcpkg install nlohmann-json cpr taglib jwt-cpp libmariadb + +cd ../3rdparty/libbcrypt/ make + cd ../.. mkdir build cd build -conan install .. cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SYSTEM_CURL=ON -DBUILD_CPR_TESTS=OFF -DOATPP_BUILD_TESTS=OFF -make +cmake --build . bin/icarus ``` Runs the server on localhost port 5002 diff --git a/Scripts/Migrations/Linux/AddUpdate.sh b/Scripts/Migrations/Linux/AddUpdate.sh deleted file mode 100755 index 04e72bd..0000000 --- a/Scripts/Migrations/Linux/AddUpdate.sh +++ /dev/null @@ -1,26 +0,0 @@ -echo "Adding migrations..." -echo "Adding User migration" -dotnet ef migrations add User --context UserContext -echo "Adding Song migration" -dotnet ef migrations add Song --context SongContext -echo "Adding Album migration" -dotnet ef migrations add Album --context AlbumContext -echo "Adding Artist migration" -dotnet ef migrations add Artist --context ArtistContext -echo "Adding Genre migration" -dotnet ef migrations add Genre --context GenreContext -echo "Adding Year migration" -dotnet ef migrations add Year --context YearContext -echo "Adding Cover art migration" -dotnet ef migrations add CoverArt --context CoverArtContext - -echo "Updating migrations.." -echo "Updating User migration" -dotnet ef database update --context UserContext -echo "Updating Song migration" -echo "Updating Album migration" -echo "Updating Artist migration" -echo "Updating Genre migration" -echo "Updating Year migration" -echo "Updating Cover art migration" -dotnet ef database update --context SongContext diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index 579327d..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,5 +0,0 @@ -[requires] -jsonformoderncpp/3.7.3@vthiery/stable - -[generators] -cmake diff --git a/include/component/AppComponent.hpp b/include/component/AppComponent.hpp index e24368a..f89c6a9 100644 --- a/include/component/AppComponent.hpp +++ b/include/component/AppComponent.hpp @@ -4,7 +4,7 @@ #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" @@ -12,28 +12,35 @@ namespace component { class AppComponent { public: OATPP_CREATE_COMPONENT(std::shared_ptr, - serverConnectionProvider)([&] { - return oatpp::network::server::SimpleTCPConnectionProvider:: - createShared(appPort()); + serverConnectionProvider)([&] + { + return oatpp::network::tcp::server::ConnectionProvider::createShared({"127.0.0.1", appPort(), oatpp::network::Address::IP_4}); }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] { + OATPP_CREATE_COMPONENT(std::shared_ptr, httpRouter)([] + { return oatpp::web::server::HttpRouter::createShared(); }()); - OATPP_CREATE_COMPONENT(std::shared_ptr, - serverConnectionHandler)([] { + OATPP_CREATE_COMPONENT(std::shared_ptr, + serverConnectionHandler)([] + { OATPP_COMPONENT(std::shared_ptr, router); return oatpp::web::server::HttpConnectionHandler::createShared(router); }()); OATPP_CREATE_COMPONENT(std::shared_ptr, - apiObjectMapper)([] { + apiObjectMapper)([] + { return oatpp::parser::json::mapping::ObjectMapper::createShared(); }()); private: - constexpr int appPort() noexcept { return 5002; } + template + constexpr Val appPort() noexcept + { + return 5002; + } }; } diff --git a/include/controller/AlbumController.hpp b/include/controller/AlbumController.hpp index 2a5ca04..b0388be 100644 --- a/include/controller/AlbumController.hpp +++ b/include/controller/AlbumController.hpp @@ -1,7 +1,6 @@ #ifndef ALBUMCONTROLLER_H_ #define ALBUMCONTROLLER_H_ -#include #include #include #include @@ -16,6 +15,7 @@ #include "oatpp/web/mime/multipart/InMemoryPartReader.hpp" #include "oatpp/web/mime/multipart/Reader.hpp" #include "oatpp/web/server/api/ApiController.hpp" +#include "oatpp/core/Types.hpp" #include "database/AlbumRepository.h" #include "dto/AlbumDto.hpp" @@ -26,69 +26,87 @@ #include "type/Scopes.h" #include "type/AlbumFilter.h" -namespace fs = std::filesystem; +using namespace dto; -namespace controller { - class AlbumController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class AlbumController : public oatpp::web::server::api::ApiController + { public: - AlbumController(const model::BinaryPath& bConf, - OATPP_COMPONENT(std::shared_ptr, objectMapper)) - : oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } + AlbumController(const model::BinaryPath& bConf, + OATPP_COMPONENT(std::shared_ptr, objectMapper)) : + oatpp::web::server::api::ApiController(objectMapper), + m_bConf(bConf) + { + } - #include OATPP_CODEGEN_BEGIN(ApiController) + #include OATPP_CODEGEN_BEGIN(ApiController) - // endpoint for retrieving all album records in json format - ENDPOINT("GET", "/api/v1/album", albumRecords, - REQUEST(std::shared_ptr, request)) { - auto authHeader = request->getHeader("Authorization"); - OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); - auto auth = authHeader->std_str(); - manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, + // endpoint for retrieving all album records in json format + ENDPOINT("GET", "/api/v1/album", albumRecords, + REQUEST(std::shared_ptr, request)) + { + auto authHeader = request->getHeader("Authorization"); + + OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + + auto auth = authHeader->std_str(); + + manager::TokenManager tok; + + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed"); - std::cout << "starting process of retrieving album\n"; - database::AlbumRepository albRepo(m_bConf); - auto albsDb = albRepo.retrieveRecords(); - auto albums = oatpp::data::mapping::type:: - List::createShared(); + std::cout << "starting process of retrieving album\n"; - for (auto& albDb : albsDb) { - auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb); + database::AlbumRepository albRepo(m_bConf); - albums->pushBack(alb); - } + auto albsDb = albRepo.retrieveRecords(); - return createDtoResponse(Status::CODE_200, albums); - } + auto albums = oatpp::Vector>::createShared(); + albums->reserve(albsDb.size()); - // endpoint for retrieving single album record by the album id in json format - ENDPOINT("GET", "/api/v1/album/{id}", albumRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { - auto authHeader = request->getHeader("Authorization"); - OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); - auto auth = authHeader->std_str(); - manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, + for (auto& albDb : albsDb) { + auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb); + + albums->push_back(alb); + } + + return createDtoResponse(Status::CODE_200, albums); + } + + // endpoint for retrieving single album record by the album id in json format + ENDPOINT("GET", "/api/v1/album/{id}", albumRecord, + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { + auto authHeader = request->getHeader("Authorization"); + + OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + + auto auth = authHeader->std_str(); + + manager::TokenManager tok; + + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed"); - database::AlbumRepository albRepo(m_bConf); - model::Album albDb(id); + database::AlbumRepository albRepo(m_bConf); + model::Album albDb(id); - OATPP_ASSERT_HTTP(albRepo.doesAlbumExists(albDb, + OATPP_ASSERT_HTTP(albRepo.doesAlbumExists(albDb, type::AlbumFilter::id) , Status::CODE_403, "album does not exist"); - std::cout << "album exists\n"; - albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id); + std::cout << "album exists\n"; + albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id); - auto album = dto::conversion::DtoConversions::toAlbumDto(albDb); + auto album = dto::conversion::DtoConversions::toAlbumDto(albDb); - return createDtoResponse(Status::CODE_200, album); - } + return createDtoResponse(Status::CODE_200, album); + } - #include OATPP_CODEGEN_END(ApiController) + #include OATPP_CODEGEN_END(ApiController) private: - model::BinaryPath m_bConf; + model::BinaryPath m_bConf; }; } #endif diff --git a/include/controller/ArtistController.hpp b/include/controller/ArtistController.hpp index 4db305a..f81abba 100644 --- a/include/controller/ArtistController.hpp +++ b/include/controller/ArtistController.hpp @@ -19,6 +19,7 @@ #include "database/ArtistRepository.h" #include "dto/ArtistDto.hpp" +#include "dto/conversion/DtoConversions.h" #include "manager/ArtistManager.h" #include "manager/TokenManager.h" #include "model/Models.h" @@ -27,37 +28,47 @@ namespace fs = std::filesystem; -namespace controller { - class ArtistController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class ArtistController : public oatpp::web::server::api::ApiController + { public: ArtistController(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 for retrieving all artist records in json format ENDPOINT("GET", "/api/v1/artist", artistRecords, - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); + OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); auto auth = authHeader->std_str(); + manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::retrieveArtist), Status::CODE_403, "Not allowed"); + type::Scope::retrieveArtist), + Status::CODE_403, + "Not allowed"); std::cout << "starting process of retrieving artist\n"; + database::ArtistRepository artRepo(m_bConf); auto artsDb = artRepo.retrieveRecords(); - auto artists = oatpp::data::mapping::type:: - List::createShared(); + auto artists = oatpp::Vector>::createShared(); + artists->reserve(artsDb.size()); + for (auto& artDb : artsDb) { - auto art = dto::ArtistDto::createShared(); - art->id = artDb.id; - art->artist = artDb.artist.c_str(); + auto art = dto::conversion::DtoConversions::toArtistDto(artDb); - artists->pushBack(art); + artists->push_back(art); } return createDtoResponse(Status::CODE_200, artists); @@ -65,13 +76,18 @@ namespace controller { // endpoint for retrieving single artist record by the artist id in json format ENDPOINT("GET", "/api/v1/artist/{id}", artistRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); + manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::retrieveArtist), Status::CODE_403, "Not allowed"); + type::Scope::retrieveArtist), + Status::CODE_403, + "Not allowed"); database::ArtistRepository artRepo(m_bConf); model::Artist artDb(id); @@ -80,11 +96,10 @@ namespace controller { type::ArtistFilter::id) , Status::CODE_403, "artist does not exist"); std::cout << "artist exist\n"; + artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id); - auto artist = dto::ArtistDto::createShared(); - artist->id = artDb.id; - artist->artist = artDb.artist.c_str(); + auto artist = dto::conversion::DtoConversions::toArtistDto(artDb); return createDtoResponse(Status::CODE_200, artist); } diff --git a/include/controller/CoverArtController.hpp b/include/controller/CoverArtController.hpp index 10e2039..0e9e2bb 100644 --- a/include/controller/CoverArtController.hpp +++ b/include/controller/CoverArtController.hpp @@ -1,7 +1,6 @@ #ifndef COVERARTCONTROLLER_H_ #define COVERARTCONTROLLER_H_ -#include #include #include #include @@ -19,44 +18,51 @@ #include "database/CoverArtRepository.h" #include "dto/CoverArtDto.hpp" +#include "dto/conversion/DtoConversions.h" #include "manager/CoverArtManager.h" +#include "manager/TokenManager.h" #include "model/Models.h" #include "type/Scopes.h" #include "type/CoverFilter.h" -namespace fs = std::filesystem; -namespace controller { - class CoverArtController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class CoverArtController : public oatpp::web::server::api::ApiController + { public: CoverArtController(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 for retrieving all cover art records in json format ENDPOINT("GET", "/api/v1/coverart", coverArtRecords, - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::downloadCoverArt), Status::CODE_403, "Not allowed"); + type::Scope::downloadCoverArt), + Status::CODE_403, "Not allowed"); std::cout << "starting process of retrieving cover art\n"; database::CoverArtRepository covRepo(m_bConf); auto covsDb = covRepo.retrieveRecords(); - auto coverArts = oatpp::data::mapping::type:: - List::createShared(); + auto coverArts = oatpp::Vector>::createShared(); + coverArts->reserve(covsDb.size()); for (auto& covDb : covsDb) { - auto cov = dto::CoverArtDto::createShared(); - cov->id = covDb.id; - cov->songTitle = covDb.songTitle.c_str(); + auto cov = dto::conversion::DtoConversions::toCoverDto(covDb); - coverArts->pushBack(cov); + coverArts->push_back(cov); } return createDtoResponse(Status::CODE_200, coverArts); @@ -64,39 +70,45 @@ namespace controller { // endpoint for retrieving single cover art record by the cover art id in json format ENDPOINT("GET", "/api/v1/coverart/{id}", coverArtRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::downloadCoverArt), Status::CODE_403, "Not allowed"); + type::Scope::downloadCoverArt), + Status::CODE_403, + "Not allowed"); database::CoverArtRepository covRepo(m_bConf); model::Cover covDb; covDb.id = id; OATPP_ASSERT_HTTP(covRepo.doesCoverArtExist(covDb, - type::CoverFilter::id) , Status::CODE_403, "song does not exist"); + type::CoverFilter::id), + Status::CODE_403, "song does not exist"); std::cout << "cover art exists\n"; covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id); - auto coverArt = dto::CoverArtDto::createShared(); - coverArt->id = covDb.id; - coverArt->songTitle = covDb.songTitle.c_str(); + auto coverArt = dto::conversion::DtoConversions::toCoverDto(covDb); return createDtoResponse(Status::CODE_200, coverArt); } ENDPOINT("GET", "/api/v1/coverart/download/{id}", downloadCoverArt, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::downloadCoverArt), Status::CODE_403, "Not allowed"); + type::Scope::downloadCoverArt), + Status::CODE_403, "Not allowed"); database::CoverArtRepository covRepo(m_bConf); model::Cover covDb; diff --git a/include/controller/GenreController.hpp b/include/controller/GenreController.hpp index 327a26a..66ae142 100644 --- a/include/controller/GenreController.hpp +++ b/include/controller/GenreController.hpp @@ -1,7 +1,6 @@ #ifndef GENRECONTROLLER_H_ #define GENRECONTROLLER_H_ -#include #include #include #include @@ -19,45 +18,51 @@ #include "database/GenreRepository.h" #include "dto/GenreDto.hpp" +#include "dto/conversion/DtoConversions.h" #include "manager/GenreManager.h" +#include "manager/TokenManager.h" #include "manager/YearManager.h" #include "model/Models.h" #include "type/Scopes.h" #include "type/GenreFilter.h" -namespace fs = std::filesystem; - -namespace controller { - class GenreController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class GenreController : public oatpp::web::server::api::ApiController + { public: GenreController(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 for retrieving all genre records in json format ENDPOINT("GET", "/api/v1/genre", genreRecords, - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveGenre), Status::CODE_403, "Not allowed"); std::cout << "starting process of retrieving genre\n"; + database::GenreRepository gnrRepo(m_bConf); auto gnrsDb = gnrRepo.retrieveRecords(); - auto genres = oatpp::data::mapping::type:: - List::createShared(); + auto genres = oatpp::Vector>::createShared(); + genres->reserve(gnrsDb.size()); for (auto& gnrDb : gnrsDb) { - auto gnr = dto::GenreDto::createShared(); - gnr->id = gnrDb.id; - gnr->category = gnrDb.category.c_str(); + auto gnr = dto::conversion::DtoConversions::toGenreDto(gnrDb); - genres->pushBack(gnr); + genres->push_back(gnr); } return createDtoResponse(Status::CODE_200, genres); @@ -65,9 +70,11 @@ namespace controller { // endpoint for retrieving single genre record by the genre id in json format ENDPOINT("GET", "/api/v1/genre/{id}", genreRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, @@ -82,9 +89,7 @@ namespace controller { std::cout << "genre exist\n"; gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id); - auto genre = dto::GenreDto::createShared(); - genre->id = gnrDb.id; - genre->category= gnrDb.category.c_str(); + auto genre = dto::conversion::DtoConversions::toGenreDto(gnrDb); return createDtoResponse(Status::CODE_200, genre); } diff --git a/include/controller/LoginController.hpp b/include/controller/LoginController.hpp index 359b2fe..1b6c3d4 100644 --- a/include/controller/LoginController.hpp +++ b/include/controller/LoginController.hpp @@ -9,23 +9,30 @@ #include "oatpp/core/macro/component.hpp" #include "oatpp/web/server/api/ApiController.hpp" +#include "dto/conversion/DtoConversions.h" #include "dto/LoginResultDto.hpp" #include "dto/conversion/DtoConversions.h" #include "manager/TokenManager.h" #include "manager/UserManager.h" #include "model/Models.h" -namespace controller { - class LoginController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class LoginController : public oatpp::web::server::api::ApiController + { public: LoginController(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/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { + ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(oatpp::Object, usr)) + { OATPP_LOGI("icarus", "logging in"); manager::UserManager usrMgr(m_bConf); @@ -33,13 +40,14 @@ namespace controller { if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) { auto logRes = dto::LoginResultDto::createShared(); + logRes->message = "invalid credentials"; + std::cout << "user does not exist\n"; + 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 2e3d479..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,19 +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::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 fad2a5c..a16551d 100644 --- a/include/controller/SongController.hpp +++ b/include/controller/SongController.hpp @@ -16,6 +16,8 @@ #include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/component.hpp" #include "oatpp/web/mime/multipart/InMemoryPartReader.hpp" +#include "oatpp/web/mime/multipart/Multipart.hpp" +#include "oatpp/web/mime/multipart/PartList.hpp" #include "oatpp/web/mime/multipart/Reader.hpp" #include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp" #include "oatpp/web/server/api/ApiController.hpp" @@ -31,36 +33,46 @@ #include "type/SongFilter.h" #include "type/SongUpload.h" -namespace fs = std::filesystem; -namespace controller { - class SongController : public oatpp::web::server::api::ApiController { +using namespace dto; + + +namespace controller +{ + class SongController : public oatpp::web::server::api::ApiController + { public: - SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr, objectMapper)) - : oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } + SongController(const model::BinaryPath& bConf, + OATPP_COMPONENT(std::shared_ptr, objectMapper)) : + oatpp::web::server::api::ApiController(objectMapper), + m_bConf(bConf) + { + } #include OATPP_CODEGEN_BEGIN(ApiController) // endpoint for uploading a song ENDPOINT("POST", "/api/v1/song/data", songUpload, - //AUTHORIZATION(std::shared_ptr, authObject), - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); - manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::upload), Status::CODE_403, "Not allowed"); + type::Scope::upload), + Status::CODE_403, "Not allowed"); auto mp = - std::make_shared + 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.setDefaultPartReader( + oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024)); - mp_reader.setPartReader("file", - oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize)); request->transferBody(&mp_reader); @@ -78,6 +90,7 @@ namespace controller { manager::SongManager songMgr(m_bConf); const auto result = songMgr.saveSong(sng); + if (!result.first) { switch (result.second) { case type::SongUpload::AlreadyExist: @@ -94,23 +107,28 @@ namespace controller { // endpoint for retrieving all song records in json format ENDPOINT("GET", "/api/v1/song", songRecords, - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveSong), Status::CODE_403, "Not allowed"); + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveSong), + Status::CODE_403, "Not allowed"); std::cout << "starting process of retrieving songs\n"; database::SongRepository songRepo(m_bConf); auto songsDb = songRepo.retrieveRecords(); - auto songs = oatpp::data::mapping::type::List::createShared(); + auto songs = oatpp::Vector>::createShared(); + std::cout << "creating object to send\n"; + for (auto& songDb : songsDb) { auto song = dto::conversion::DtoConversions::toSongDto(songDb); - songs->pushBack(song); + songs->push_back(song); } return createDtoResponse(Status::CODE_200, songs); @@ -118,12 +136,15 @@ namespace controller { // endpoint for retrieving song record by the song id in json format ENDPOINT("GET", "/api/v1/song/{id}", songRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveSong), Status::CODE_403, "Not allowed"); + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveSong), + Status::CODE_403, "Not allowed"); database::SongRepository songRepo(m_bConf); model::Song songDb(id); @@ -141,16 +162,20 @@ namespace controller { } ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::download), Status::CODE_403, "Not allowed"); + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::download), + Status::CODE_403, "Not allowed"); + database::SongRepository songRepo(m_bConf); model::Song songDb(id); + if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { return songDoesNotExist(); } @@ -166,11 +191,13 @@ namespace controller { } ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate, - REQUEST(std::shared_ptr, request), - BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), + BODY_DTO(oatpp::Object, songDto), PATH(Int32, id)) + { songDto->id = id; auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, @@ -179,6 +206,7 @@ namespace controller { auto updatedSong = dto::conversion::DtoConversions::toSong(songDto); manager::SongManager songMgr(m_bConf); auto result = songMgr.updateSong(updatedSong); + if (!result) { return songDoesNotExist(); } @@ -188,18 +216,21 @@ namespace controller { // endpoint to delete a song ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::deleteSong), Status::CODE_403, "Not allowed"); + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::deleteSong), + Status::CODE_403, "Not allowed"); model::Song song(id); manager::SongManager sngMgr(m_bConf); auto result = sngMgr.deleteSong(song); + if (!result) { return songDoesNotExist(); } @@ -209,23 +240,26 @@ namespace controller { // endpoint for streaming a song ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; - OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::stream), Status::CODE_403, "Not allowed"); + OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::stream), + Status::CODE_403, "Not allowed"); database::SongRepository songRepo(m_bConf); model::Song songDb(id); + if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { return songDoesNotExist(); } 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( @@ -242,8 +276,8 @@ namespace controller { #include OATPP_CODEGEN_END(ApiController) private: std::shared_ptr - songDoesNotExist() { - + songDoesNotExist() + { return createResponse(Status::CODE_404, "Song not found"); } diff --git a/include/controller/YearController.hpp b/include/controller/YearController.hpp index 90c4892..548ffd8 100644 --- a/include/controller/YearController.hpp +++ b/include/controller/YearController.hpp @@ -1,7 +1,6 @@ #ifndef YEARCONTROLLER_H_ #define YEARCONTROLLER_H_ -#include #include #include #include @@ -18,45 +17,53 @@ #include "oatpp/web/server/api/ApiController.hpp" #include "database/YearRepository.h" +#include "dto/conversion/DtoConversions.h" #include "dto/YearDto.hpp" +#include "manager/TokenManager.h" #include "manager/YearManager.h" #include "model/Models.h" #include "type/Scopes.h" #include "type/YearFilter.h" -namespace fs = std::filesystem; -namespace controller { - class YearController : public oatpp::web::server::api::ApiController { +namespace controller +{ + class YearController : public oatpp::web::server::api::ApiController + { public: YearController(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 for retrieving all year records in json format ENDPOINT("GET", "/api/v1/year", yearRecords, - REQUEST(std::shared_ptr, request)) { + REQUEST(std::shared_ptr, request)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::retrieveYear), Status::CODE_403, "Not allowed"); + type::Scope::retrieveYear), + Status::CODE_403, "Not allowed"); std::cout << "starting process of retrieving year\n"; + database::YearRepository yrRepo(m_bConf); auto yrsDb = yrRepo.retrieveRecords(); - auto yearRecs = oatpp::data::mapping::type:: - List::createShared(); + auto yearRecs = oatpp::Vector>::createShared(); + yearRecs->reserve(yrsDb.size()); - for (auto& yrDb : yrsDb) { - auto yr = dto::YearDto::createShared(); - yr->id = yrDb.id; - yr->year = yrDb.year; + for (auto &yrDb : yrsDb) { + auto yr = dto::conversion::DtoConversions::toYearDto(yrDb); - yearRecs->pushBack(yr); + yearRecs->push_back(yr); } return createDtoResponse(Status::CODE_200, yearRecs); @@ -64,26 +71,28 @@ namespace controller { // endpoint for retrieving single year record by the year id in json format ENDPOINT("GET", "/api/v1/year/{id}", yearRecord, - REQUEST(std::shared_ptr, request), PATH(Int32, id)) { + REQUEST(std::shared_ptr, request), PATH(Int32, id)) + { auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); + auto auth = authHeader->std_str(); manager::TokenManager tok; OATPP_ASSERT_HTTP(tok.isTokenValid(auth, - type::Scope::retrieveYear), Status::CODE_403, "Not allowed"); + type::Scope::retrieveYear), + Status::CODE_403, "Not allowed"); database::YearRepository yrRepo(m_bConf); model::Year yrDb(id); OATPP_ASSERT_HTTP(yrRepo.doesYearExist(yrDb, - type::YearFilter::id) , Status::CODE_403, "year does not exist"); + type::YearFilter::id), + Status::CODE_403, "year does not exist"); std::cout << "year exist\n"; yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id); - auto year = dto::YearDto::createShared(); - year->id = yrDb.id; - year->year= yrDb.year; + auto year = dto::conversion::DtoConversions::toYearDto(yrDb); return createDtoResponse(Status::CODE_200, year); } diff --git a/include/dto/AlbumDto.hpp b/include/dto/AlbumDto.hpp index 8eff244..4f3a3c6 100644 --- a/include/dto/AlbumDto.hpp +++ b/include/dto/AlbumDto.hpp @@ -1,14 +1,16 @@ #ifndef ALBUMDTO_H_ #define ALBUMDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +#include +#include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class AlbumDto : public oatpp::data::mapping::type::Object { - DTO_INIT(AlbumDto, Object) + class AlbumDto : public oatpp::DTO + { + DTO_INIT(AlbumDto, DTO) DTO_FIELD(Int32, id); DTO_FIELD(String, title); diff --git a/include/dto/ArtistDto.hpp b/include/dto/ArtistDto.hpp index 7d4c8ba..b19fa18 100644 --- a/include/dto/ArtistDto.hpp +++ b/include/dto/ArtistDto.hpp @@ -1,14 +1,17 @@ #ifndef ARTISTDTO_H_ #define ARTISTDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" +// #include "oatpp/core/data/mapping/type/Object.hpp" +#include "oatpp/core/Types.hpp" #include "oatpp/core/macro/codegen.hpp" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class ArtistDto : public oatpp::data::mapping::type::Object { - DTO_INIT(ArtistDto, Object) + class ArtistDto : public oatpp::DTO + { + DTO_INIT(ArtistDto, DTO) DTO_FIELD(Int32, id); DTO_FIELD(String, artist); diff --git a/include/dto/CoverArtDto.hpp b/include/dto/CoverArtDto.hpp index 22dca2c..e4e6133 100644 --- a/include/dto/CoverArtDto.hpp +++ b/include/dto/CoverArtDto.hpp @@ -1,14 +1,16 @@ #ifndef COVERARTDTO_H_ #define COVERARTDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class CoverArtDto : public oatpp::data::mapping::type::Object { - DTO_INIT(CoverArtDto, Object) + class CoverArtDto : public oatpp::DTO + { + DTO_INIT(CoverArtDto, DTO) DTO_FIELD(Int32, id); DTO_FIELD(String, songTitle); diff --git a/include/dto/GenreDto.hpp b/include/dto/GenreDto.hpp index f1b6753..01cad84 100644 --- a/include/dto/GenreDto.hpp +++ b/include/dto/GenreDto.hpp @@ -1,14 +1,16 @@ #ifndef GENREDTO_H_ #define GENREDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class GenreDto : public oatpp::data::mapping::type::Object { - DTO_INIT(GenreDto, Object) + class GenreDto : public oatpp::DTO + { + DTO_INIT(GenreDto, DTO) DTO_FIELD(Int32, id); DTO_FIELD(String, category); diff --git a/include/dto/LoginResultDto.hpp b/include/dto/LoginResultDto.hpp index 1f0548e..b7b10b2 100644 --- a/include/dto/LoginResultDto.hpp +++ b/include/dto/LoginResultDto.hpp @@ -1,43 +1,47 @@ #ifndef LOGINRESULTDTO_H_ #define LOGINRESULTDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +#include +#include #include "model/Models.h" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class LoginResultDto : public oatpp::data::mapping::type::Object { - DTO_INIT(LoginResultDto, Object) + class LoginResultDto : public oatpp::DTO + { + DTO_INIT(LoginResultDto, DTO) - DTO_FIELD(Int32, id); - DTO_FIELD(String, username); - DTO_FIELD(String, token); - DTO_FIELD(String, token_type); - DTO_FIELD(Int32, expiration); - DTO_FIELD(String, message); + DTO_FIELD(oatpp::Int32, id); + DTO_FIELD(oatpp::String, username); + DTO_FIELD(oatpp::String, token); + DTO_FIELD(oatpp::String, token_type); + DTO_FIELD(oatpp::Int32, expiration); + DTO_FIELD(oatpp::String, message); }; - class RegisterResultDto : public oatpp::data::mapping::type::Object { - DTO_INIT(RegisterResultDto, Object) + class RegisterResultDto : public oatpp::DTO + { + DTO_INIT(RegisterResultDto, DTO) - DTO_FIELD(String, username); - DTO_FIELD(Boolean, registered); - DTO_FIELD(String, message); + DTO_FIELD(oatpp::String, username); + DTO_FIELD(oatpp::Boolean, registered); + DTO_FIELD(oatpp::String, message); }; - class UserDto : public oatpp::data::mapping::type::Object { - DTO_INIT(UserDto, Object) + class UserDto : public oatpp::DTO + { + DTO_INIT(UserDto, DTO) - DTO_FIELD(Int32, userId); - DTO_FIELD(String, firstname); - DTO_FIELD(String, lastname); - DTO_FIELD(String, phone); - DTO_FIELD(String, email); - DTO_FIELD(String, username); - DTO_FIELD(String, password); + DTO_FIELD(oatpp::Int32, userId); + DTO_FIELD(oatpp::String, firstname); + DTO_FIELD(oatpp::String, lastname); + DTO_FIELD(oatpp::String, phone); + DTO_FIELD(oatpp::String, email); + DTO_FIELD(oatpp::String, username); + DTO_FIELD(oatpp::String, password); }; #include OATPP_CODEGEN_END(DTO) diff --git a/include/dto/SongDto.hpp b/include/dto/SongDto.hpp index 050dee0..20840db 100644 --- a/include/dto/SongDto.hpp +++ b/include/dto/SongDto.hpp @@ -1,28 +1,30 @@ #ifndef SONGDTO_H_ #define SONGDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +#include +#include #include "model/Models.h" -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class SongDto : public oatpp::data::mapping::type::Object { - DTO_INIT(SongDto, Object) + class SongDto : public oatpp::DTO + { + DTO_INIT(SongDto, DTO) - DTO_FIELD(Int32, id); - DTO_FIELD(String, title); - DTO_FIELD(String, artist); - DTO_FIELD(String, album_artist); - DTO_FIELD(String, album); - DTO_FIELD(String, genre); - DTO_FIELD(Int32, track); - DTO_FIELD(Int32, disc); - DTO_FIELD(Int32, year); - DTO_FIELD(Int32, duration); - DTO_FIELD(Int32, coverart_id); + DTO_FIELD(oatpp::Int32, id); + DTO_FIELD(oatpp::String, title); + DTO_FIELD(oatpp::String, artist); + DTO_FIELD(oatpp::String, album_artist); + DTO_FIELD(oatpp::String, album); + DTO_FIELD(oatpp::String, genre); + DTO_FIELD(oatpp::Int32, track); + DTO_FIELD(oatpp::Int32, disc); + DTO_FIELD(oatpp::Int32, year); + DTO_FIELD(oatpp::Int32, duration); + DTO_FIELD(oatpp::Int32, coverart_id); }; #include OATPP_CODEGEN_END(DTO) diff --git a/include/dto/YearDto.hpp b/include/dto/YearDto.hpp index 915c270..8235cdd 100644 --- a/include/dto/YearDto.hpp +++ b/include/dto/YearDto.hpp @@ -1,14 +1,16 @@ #ifndef YEARDTO_H_ #define YEARDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include -namespace dto { +namespace dto +{ #include OATPP_CODEGEN_BEGIN(DTO) - class YearDto : public oatpp::data::mapping::type::Object { - DTO_INIT(YearDto, Object) + class YearDto : public oatpp::DTO + { + DTO_INIT(YearDto, DTO) DTO_FIELD(Int32, id); DTO_FIELD(Int32, year); diff --git a/include/dto/conversion/DtoConversions.h b/include/dto/conversion/DtoConversions.h index d22b9d1..ae88641 100644 --- a/include/dto/conversion/DtoConversions.h +++ b/include/dto/conversion/DtoConversions.h @@ -1,27 +1,170 @@ #ifndef DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_ +#include +#include +#include + +#include +#include +#include +#include + #include "dto/AlbumDto.hpp" +#include "dto/ArtistDto.hpp" +#include "dto/CoverArtDto.hpp" +#include "dto/GenreDto.hpp" #include "dto/LoginResultDto.hpp" #include "dto/SongDto.hpp" +#include "dto/YearDto.hpp" #include "model/Models.h" -namespace dto { namespace conversion { - class DtoConversions { +using namespace model; +using namespace dto; + +namespace dto::conversion +{ + class DtoConversions + { public: - static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); + template> + static D toLoginResultDto(const User &user, const Token &token) + { + auto logRes = LoginResultDto::createShared(); + logRes->id = (user.id != 0) ? user.id : 0; + logRes->username = (!user.username.empty()) ? user.username.c_str() : "None"; + logRes->token = (!token.accessToken.empty()) ? token.accessToken.c_str() : "None"; + logRes->token_type = (!token.tokenType.empty()) ? token.tokenType.c_str() : "None"; + logRes->expiration = (token.expiration != 0) ? token.expiration : 0; - static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( - const model::RegisterResult&); + return logRes; + } - static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); + template> + static D toRegisterResultDto( + const model::RegisterResult ®Res) + { + auto result = RegisterResultDto::createShared(); + result->message = (!regRes.message.empty()) ? regRes.message.c_str() : "None"; + result->registered = regRes.registered; + result->username = (!regRes.username.empty()) ? regRes.username.c_str() : "None"; - static dto::SongDto::ObjectWrapper toSongDto(const model::Song&); + return result; + } - static model::Song toSong(dto::SongDto::ObjectWrapper&); + template> + static D toAlbumDto(const Album &album) + { + auto result = 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; - static model::User toUser(dto::UserDto::ObjectWrapper&); + return result; + } + + template> + static D toArtistDto(const Artist &artist) + { + auto result = ArtistDto::createShared(); + result->id = (artist.id != 0) ? artist.id : 0; + result->artist = (!artist.artist.empty()) ? artist.artist.c_str() : "None"; + + return result; + } + + + template> + static D toCoverDto(const Cover &cover) + { + auto result = CoverArtDto::createShared(); + result->id = cover.id != 0 ? cover.id : 0; + result->songTitle = (!cover.songTitle.empty()) ? cover.songTitle.c_str() : "None"; + + return result; + } + + template> + static D toGenreDto(const Genre &genre) + { + auto result = GenreDto::createShared(); + result->id = (genre.id != 0) ? genre.id : 0; + result->category = (!genre.category.empty()) ? genre.category.c_str() : "None"; + + return result; + } + + + template> + static D toSongDto(const model::Song &song) + { + auto result = 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; + } + + template> + static D toYearDto(const Year &year) + { + auto result = YearDto::createShared(); + result->id = (year.id != 0) ? year.id : 0; + result->year = (year.year != 0) ? year.year : 0; + + return result; + } + + + template> + static Song toSong(const D &songDto) + { + Song song; + 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; + 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; + + return song; + + } + + template> + static User toUser(const D &userDto) + { + User user; + 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/utility/ImageFile.h b/include/utility/ImageFile.h index 8d890a9..71f7129 100644 --- a/include/utility/ImageFile.h +++ b/include/utility/ImageFile.h @@ -3,15 +3,16 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace utility { class ImageFile : public TagLib::File { diff --git a/include/utility/MetadataRetriever.h b/include/utility/MetadataRetriever.h index 683021c..9e564d0 100644 --- a/include/utility/MetadataRetriever.h +++ b/include/utility/MetadataRetriever.h @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "model/Models.h" 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 f502e80..71fddd2 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,13 +1,15 @@ -#include #include -#include +#include #include #include #include -#include -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -#include "oatpp/web/server/HttpConnectionHandler.hpp" + +#include + +#include +#include + #include "component/AppComponent.hpp" #include "controller/ArtistController.hpp" @@ -21,12 +23,14 @@ #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); auto albumController = std::make_shared(bConf); auto artistController = std::make_shared(bConf); @@ -46,30 +50,35 @@ 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 server(connectionProvider, connectionHandler); + oatpp::network::Server server(connectionProvider, connectionHandler); OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData()); 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 8c57822..0000000 --- a/src/dto/conversion/DtoConversions.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "dto/conversion/DtoConversions.h" - -namespace dto { namespace conversion { - LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, - const model::Token& token) { - auto logRes = dto::LoginResultDto::createShared(); - logRes->username = user.username.c_str(); - logRes->token = token.accessToken.c_str(); - logRes->token_type = token.tokenType.c_str(); - logRes->expiration = token.expiration; - - return logRes; - } - - - dto::RegisterResultDto::ObjectWrapper 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) { - 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) { - 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 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 user; - 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/manager/TokenManager.cpp b/src/manager/TokenManager.cpp index bff3121..e56ea78 100644 --- a/src/manager/TokenManager.cpp +++ b/src/manager/TokenManager.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -11,8 +10,6 @@ #include "manager/DirectoryManager.h" -namespace fs = std::filesystem; - namespace manager { model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf) { auto cred = parseAuthCredentials(bConf); @@ -93,7 +90,9 @@ namespace manager { cpr::Response TokenManager::sendRequest(std::string_view uri, nlohmann::json& obj) { - auto resp = cpr::Post(cpr::Url{uri}, cpr::Body{obj.dump()}, + const std::string uriString(uri.begin(), uri.end()); + + auto resp = cpr::Post(cpr::Url(uriString), cpr::Body{obj.dump()}, cpr::Header{{"Content-type", "application/json"}, {"Connection", "keep-alive"}}); 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); - } -}