From 992b8300c9ff29d7a0d52425d91d714b2e2a7ced Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Thu, 17 Dec 2020 23:40:10 -0500 Subject: [PATCH 01/10] Added vcpkg --- .gitmodules | 3 +++ 3rdparty/vcpkg | 1 + 2 files changed, 4 insertions(+) create mode 160000 3rdparty/vcpkg diff --git a/.gitmodules b/.gitmodules index 4455ce3..6fb8739 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [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/vcpkg b/3rdparty/vcpkg new file mode 160000 index 0000000..ec6fe06 --- /dev/null +++ b/3rdparty/vcpkg @@ -0,0 +1 @@ +Subproject commit ec6fe06e8da05a8157dc8581fa96b36b571c1bd5 -- 2.47.3 From bb687ec6e7aca6813e8d2a0ae8ac076503dc3253 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 01:22:15 -0500 Subject: [PATCH 02/10] Removing taglib submodule and adding it to vcpkg --- .gitmodules | 3 --- 3rdparty/taglib | 1 - CMakeLists.txt | 35 +++-------------------------- include/utility/ImageFile.h | 19 ++++++++-------- include/utility/MetadataRetriever.h | 11 ++++----- 5 files changed, 19 insertions(+), 50 deletions(-) delete mode 160000 3rdparty/taglib diff --git a/.gitmodules b/.gitmodules index 6fb8739..5a581cd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [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 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/CMakeLists.txt b/CMakeLists.txt index de6886e..33a8506 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,39 +86,10 @@ set(HEADERS include/verify/Initialization.h ) -set (TAGLIB - ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib/3rdparty -) - 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 ) @@ -129,10 +100,9 @@ conan_basic_setup() #find_library(BCRYPT bcrypt ${BCRYPTLIB}) -include_directories(include ${CPR_INCLUDE_DIRS} ${TAGLIB} ${TAGLIB_HEADERS} ${BCRYPTLIB}) +include_directories(include ${CPR_INCLUDE_DIRS} ${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) @@ -148,5 +118,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/pa 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) +target_link_libraries(icarus "-lstdc++fs" oatpp tag mysqlclient ${CONAN_LIBS} ${CPR_LIBRARIES} bcrypt) 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..b6de9ff 100644 --- a/include/utility/MetadataRetriever.h +++ b/include/utility/MetadataRetriever.h @@ -4,11 +4,12 @@ #include #include -#include -#include -#include -#include -#include +// #include +#include +#include +#include +#include +#include #include "model/Models.h" -- 2.47.3 From 3ad04ca9a6c8929fd54876d9f2ffbfff1757cb07 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 01:43:47 -0500 Subject: [PATCH 03/10] Migrating some more dependencies to vcpkg --- .gitmodules | 3 --- 3rdparty/cpr | 1 - 2 files changed, 4 deletions(-) delete mode 160000 3rdparty/cpr diff --git a/.gitmodules b/.gitmodules index 5a581cd..cc92494 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "Libs/cpr"] - path = 3rdparty/cpr - url = https://github.com/whoshuu/cpr.git [submodule "3rdparty/oatpp"] path = 3rdparty/oatpp url = https://github.com/oatpp/oatpp 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 -- 2.47.3 From 231b12d60b024f3d5d13c6927c7bd2a073998234 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 01:50:58 -0500 Subject: [PATCH 04/10] Moved another dependency --- .gitmodules | 3 --- 3rdparty/jwt-cpp | 1 - CMakeLists.txt | 20 +++++++++----------- README.md | 12 +++++++++--- conanfile.txt | 5 ----- src/manager/TokenManager.cpp | 7 +++---- 6 files changed, 21 insertions(+), 27 deletions(-) delete mode 160000 3rdparty/jwt-cpp delete mode 100644 conanfile.txt diff --git a/.gitmodules b/.gitmodules index cc92494..cdb20ba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [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 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/CMakeLists.txt b/CMakeLists.txt index 33a8506..e738439 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,19 +90,11 @@ set (BCRYPTLIB ${CMAKE_SOURCE_DIR}/3rdparty/libbcrypt ) -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} ${BCRYPTLIB}) +include_directories(include ${BCRYPTLIB}) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cpr) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) add_library(bcrypt STATIC IMPORTED) @@ -117,7 +109,13 @@ 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) +find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h") + +find_package(nlohmann_json CONFIG REQUIRED) +find_package(cpr CONFIG REQUIRED) + add_executable(icarus ${SOURCES} ${HEADERS}) -target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE}) -target_link_libraries(icarus "-lstdc++fs" oatpp tag mysqlclient ${CONAN_LIBS} ${CPR_LIBRARIES} bcrypt) + +target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS}) +target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp tag mysqlclient nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) diff --git a/README.md b/README.md index d2b848f..6b1e88c 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) +* libmysql * [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 + +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/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/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"}}); -- 2.47.3 From 65a7aad53d597ccb237900d9c150e559bea4665c Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 02:28:09 -0500 Subject: [PATCH 05/10] Moving more packages. Moved libmariadb --- CMakeLists.txt | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e738439..a634ac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,4 +118,4 @@ add_executable(icarus ${SOURCES} ${HEADERS}) target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS}) -target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp tag mysqlclient nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) +target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) diff --git a/README.md b/README.md index 6b1e88c..360ce1a 100644 --- a/README.md +++ b/README.md @@ -21,7 +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) -* libmysql +* libmariadb * [libbcrypt](https://github.com/rg3/libbcrypt) * [oatpp](https://github.com/oatpp/oatpp) @@ -153,7 +153,7 @@ git clone --recursive https://github.com/kdeng00/icarus cd icarus/3rdparty/vcpkg ./bootstrap-vcpkg.sh -./vcpkg install nlohmann-json cpr taglib jwt-cpp +./vcpkg install nlohmann-json cpr taglib jwt-cpp libmariadb cd ../3rdparty/libbcrypt/ make -- 2.47.3 From ff78baf3b9f97164c6d3594ad80d448d5c5aa732 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 02:35:23 -0500 Subject: [PATCH 06/10] Removed the explicit header definitions from the CMake file --- CMakeLists.txt | 62 ++++------------------------- include/utility/MetadataRetriever.h | 1 - 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a634ac8..42c7df3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,59 +31,10 @@ set(SOURCES 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(ICARUS_INCLUDE_DIR + "${CMAKE_CURRENT_SOURCE_DIR}/include" ) set (BCRYPTLIB @@ -93,7 +44,7 @@ set (BCRYPTLIB #find_library(BCRYPT bcrypt ${BCRYPTLIB}) -include_directories(include ${BCRYPTLIB}) +include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB}) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) @@ -108,13 +59,14 @@ 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") find_package(nlohmann_json CONFIG REQUIRED) find_package(cpr CONFIG REQUIRED) -add_executable(icarus ${SOURCES} ${HEADERS}) +add_executable(icarus ${SOURCES}) target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS}) diff --git a/include/utility/MetadataRetriever.h b/include/utility/MetadataRetriever.h index b6de9ff..9e564d0 100644 --- a/include/utility/MetadataRetriever.h +++ b/include/utility/MetadataRetriever.h @@ -4,7 +4,6 @@ #include #include -// #include #include #include #include -- 2.47.3 From ae58b60339bccc94e4215e7ab7d2c1be26c87e7a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 03:18:23 -0500 Subject: [PATCH 07/10] Saving changes. Updated oatpp version has some breaking changes --- CMakeLists.txt | 9 +++-- include/dto/LoginResultDto.hpp | 50 +++++++++++++------------ include/dto/SongDto.hpp | 31 +++++++-------- include/dto/conversion/DtoConversions.h | 17 ++++++--- src/dto/conversion/DtoConversions.cpp | 39 +++++++++++-------- 5 files changed, 83 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42c7df3..118d511 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ set (BCRYPTLIB include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB}) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) +# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp) add_library(bcrypt STATIC IMPORTED) @@ -59,15 +59,18 @@ 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) +# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/build/icarus ${CMAKE_BINARY_DIR}/bin/icarus COPYONLY) 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 tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) +target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp::oatpp tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt) diff --git a/include/dto/LoginResultDto.hpp b/include/dto/LoginResultDto.hpp index 1f0548e..0479e7f 100644 --- a/include/dto/LoginResultDto.hpp +++ b/include/dto/LoginResultDto.hpp @@ -1,43 +1,45 @@ #ifndef LOGINRESULTDTO_H_ #define LOGINRESULTDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +// #include +#include +#include #include "model/Models.h" namespace dto { #include OATPP_CODEGEN_BEGIN(DTO) - class LoginResultDto : public oatpp::data::mapping::type::Object { - DTO_INIT(LoginResultDto, Object) + // class LoginResultDto : public oatpp::data::mapping::type::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..90df52f 100644 --- a/include/dto/SongDto.hpp +++ b/include/dto/SongDto.hpp @@ -1,28 +1,29 @@ #ifndef SONGDTO_H_ #define SONGDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +#include +// #include +#include #include "model/Models.h" 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/conversion/DtoConversions.h b/include/dto/conversion/DtoConversions.h index d22b9d1..5294407 100644 --- a/include/dto/conversion/DtoConversions.h +++ b/include/dto/conversion/DtoConversions.h @@ -9,18 +9,23 @@ namespace dto { namespace conversion { class DtoConversions { public: - static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); + // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); + static dto::LoginResultDto toLoginResultDto(const model::User&, const model::Token&); - static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( + // static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( + static dto::RegisterResultDto toRegisterResultDto( const model::RegisterResult&); - static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); + // static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); + static dto::AlbumDto toAlbumDto(const model::Album&); - static dto::SongDto::ObjectWrapper toSongDto(const model::Song&); + static dto::SongDto toSongDto(const model::Song&); - static model::Song toSong(dto::SongDto::ObjectWrapper&); + // static model::Song toSong(dto::SongDto::ObjectWrapper&); + static model::Song toSong(dto::SongDto*); - static model::User toUser(dto::UserDto::ObjectWrapper&); + // static model::User toUser(dto::UserDto::ObjectWrapper&); + static model::User toUser(dto::UserDto&); }; }} diff --git a/src/dto/conversion/DtoConversions.cpp b/src/dto/conversion/DtoConversions.cpp index 8c57822..cb52a4e 100644 --- a/src/dto/conversion/DtoConversions.cpp +++ b/src/dto/conversion/DtoConversions.cpp @@ -1,7 +1,8 @@ #include "dto/conversion/DtoConversions.h" namespace dto { namespace conversion { - LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, + // LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, + LoginResultDto DtoConversions::toLoginResultDto(const model::User& user, const model::Token& token) { auto logRes = dto::LoginResultDto::createShared(); logRes->username = user.username.c_str(); @@ -13,7 +14,8 @@ namespace dto { namespace conversion { } - dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto( + // dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto( + dto::RegisterResultDto DtoConversions::toRegisterResultDto( const model::RegisterResult& regRes) { auto result = dto::RegisterResultDto::createShared(); result->message = regRes.message.c_str(); @@ -24,7 +26,8 @@ namespace dto { namespace conversion { } - dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) { + // 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() : ""; @@ -35,7 +38,8 @@ namespace dto { namespace conversion { } - dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) { + // 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() : ""; @@ -53,27 +57,31 @@ namespace dto { namespace conversion { } - model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) { + // 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.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.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(); + 0 : songDto->coverart_id.getValue(); return song; } - model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) { + // 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(); @@ -81,6 +89,7 @@ namespace dto { namespace conversion { 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; } -- 2.47.3 From b8caefac81ba37630be02c84ebd97d36baf2580b Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 18 Dec 2020 14:38:46 -0500 Subject: [PATCH 08/10] Working on fixing build errors --- CMakeLists.txt | 2 +- include/component/AppComponent.hpp | 28 +++-- include/controller/AlbumController.hpp | 100 ++++++++++-------- include/controller/ArtistController.hpp | 9 +- include/controller/CoverArtController.hpp | 5 +- include/controller/GenreController.hpp | 5 +- include/controller/RegisterController.hpp | 3 +- include/controller/SongController.hpp | 10 +- include/controller/YearController.hpp | 11 +- include/dto/AlbumDto.hpp | 8 +- include/dto/ArtistDto.hpp | 7 +- include/dto/CoverArtDto.hpp | 6 +- include/dto/GenreDto.hpp | 6 +- include/dto/YearDto.hpp | 6 +- include/dto/conversion/DtoConversions.h | 119 ++++++++++++++++++++-- src/Main.cpp | 31 ++++-- src/dto/conversion/DtoConversions.cpp | 21 ++-- 17 files changed, 272 insertions(+), 105 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 118d511..2497bde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(SOURCES src/database/SongRepository.cpp src/database/UserRepository.cpp src/database/YearRepository.cpp - src/dto/conversion/DtoConversions.cpp + # src/dto/conversion/DtoConversions.cpp src/Main.cpp src/manager/AlbumManager.cpp src/manager/ArtistManager.cpp diff --git a/include/component/AppComponent.hpp b/include/component/AppComponent.hpp index e24368a..47de59a 100644 --- a/include/component/AppComponent.hpp +++ b/include/component/AppComponent.hpp @@ -4,7 +4,8 @@ #include #include "oatpp/core/macro/component.hpp" -#include "oatpp/network/server/SimpleTCPConnectionProvider.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 +13,37 @@ 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({"localhost", appPort(), oatpp::network::Address::IP_4}); + return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 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 + Val appPort() noexcept + { + return 5002; + } }; } diff --git a/include/controller/AlbumController.hpp b/include/controller/AlbumController.hpp index 2a5ca04..59bec1b 100644 --- a/include/controller/AlbumController.hpp +++ b/include/controller/AlbumController.hpp @@ -16,6 +16,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" @@ -27,68 +28,85 @@ #include "type/AlbumFilter.h" namespace fs = std::filesystem; +using namespace dto; 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..f3cf3f4 100644 --- a/include/controller/ArtistController.hpp +++ b/include/controller/ArtistController.hpp @@ -49,15 +49,18 @@ namespace controller { 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(); + // List::createShared(); + for (auto& artDb : artsDb) { auto art = dto::ArtistDto::createShared(); art->id = artDb.id; art->artist = artDb.artist.c_str(); - artists->pushBack(art); + // artists->push_back(art); + artists->push_back(art); + // artists.push_back(art); } return createDtoResponse(Status::CODE_200, artists); diff --git a/include/controller/CoverArtController.hpp b/include/controller/CoverArtController.hpp index 10e2039..c48ffb7 100644 --- a/include/controller/CoverArtController.hpp +++ b/include/controller/CoverArtController.hpp @@ -48,15 +48,14 @@ namespace controller { 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(); for (auto& covDb : covsDb) { auto cov = dto::CoverArtDto::createShared(); cov->id = covDb.id; cov->songTitle = covDb.songTitle.c_str(); - coverArts->pushBack(cov); + coverArts->push_back(cov); } return createDtoResponse(Status::CODE_200, coverArts); diff --git a/include/controller/GenreController.hpp b/include/controller/GenreController.hpp index 327a26a..c77ecb0 100644 --- a/include/controller/GenreController.hpp +++ b/include/controller/GenreController.hpp @@ -49,15 +49,14 @@ namespace controller { 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(); for (auto& gnrDb : gnrsDb) { auto gnr = dto::GenreDto::createShared(); gnr->id = gnrDb.id; gnr->category = gnrDb.category.c_str(); - genres->pushBack(gnr); + genres->push_back(gnr); } return createDtoResponse(Status::CODE_200, genres); diff --git a/include/controller/RegisterController.hpp b/include/controller/RegisterController.hpp index 2e3d479..42862eb 100644 --- a/include/controller/RegisterController.hpp +++ b/include/controller/RegisterController.hpp @@ -23,7 +23,8 @@ namespace controller { #include OATPP_CODEGEN_BEGIN(ApiController) ENDPOINT("POST", "api/v1/register", registerUser, - BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { + // BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { + BODY_DTO(oatpp::data::mapping::type::ObjectWrapper, usr)) { manager::UserManager usrMgr(m_bConf); auto user = dto::conversion::DtoConversions::toUser(usr); if (usrMgr.doesUserExist(user)) { diff --git a/include/controller/SongController.hpp b/include/controller/SongController.hpp index fad2a5c..08b89af 100644 --- a/include/controller/SongController.hpp +++ b/include/controller/SongController.hpp @@ -104,13 +104,16 @@ namespace controller { 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::data::mapping::type::List::createShared(); + auto songs = oatpp::Vector>::createShared(); + + // auto yearRecs = 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); @@ -167,7 +170,8 @@ namespace controller { ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate, REQUEST(std::shared_ptr, request), - BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { + // BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { + BODY_DTO(oatpp::data::mapping::type::ObjectWrapper, songDto), PATH(Int32, id)) { songDto->id = id; auto authHeader = request->getHeader("Authorization"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); diff --git a/include/controller/YearController.hpp b/include/controller/YearController.hpp index 90c4892..c8b3d6c 100644 --- a/include/controller/YearController.hpp +++ b/include/controller/YearController.hpp @@ -48,15 +48,20 @@ namespace controller { 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::data::mapping::type:: + // List::createShared(); + // List::createShared(); + auto yearRecs = oatpp::Vector>::createShared(); + // List::createShared(); + // List::createShared(); for (auto& yrDb : yrsDb) { auto yr = dto::YearDto::createShared(); yr->id = yrDb.id; yr->year = yrDb.year; - yearRecs->pushBack(yr); + // yearRecs->pushBack(yr); + yearRecs->push_back(yr); } return createDtoResponse(Status::CODE_200, yearRecs); diff --git a/include/dto/AlbumDto.hpp b/include/dto/AlbumDto.hpp index 8eff244..482b236 100644 --- a/include/dto/AlbumDto.hpp +++ b/include/dto/AlbumDto.hpp @@ -1,14 +1,14 @@ #ifndef ALBUMDTO_H_ #define ALBUMDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" +#include +#include 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..44f848f 100644 --- a/include/dto/ArtistDto.hpp +++ b/include/dto/ArtistDto.hpp @@ -1,14 +1,15 @@ #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 { #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..75f7786 100644 --- a/include/dto/CoverArtDto.hpp +++ b/include/dto/CoverArtDto.hpp @@ -1,14 +1,14 @@ #ifndef COVERARTDTO_H_ #define COVERARTDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include 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..490a1bb 100644 --- a/include/dto/GenreDto.hpp +++ b/include/dto/GenreDto.hpp @@ -1,14 +1,14 @@ #ifndef GENREDTO_H_ #define GENREDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include 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/YearDto.hpp b/include/dto/YearDto.hpp index 915c270..e2c190b 100644 --- a/include/dto/YearDto.hpp +++ b/include/dto/YearDto.hpp @@ -1,14 +1,14 @@ #ifndef YEARDTO_H_ #define YEARDTO_H_ -#include "oatpp/core/data/mapping/type/Object.hpp" #include "oatpp/core/macro/codegen.hpp" +#include 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 5294407..3b7074f 100644 --- a/include/dto/conversion/DtoConversions.h +++ b/include/dto/conversion/DtoConversions.h @@ -1,31 +1,136 @@ #ifndef DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_ +#include +#include +#include + #include "dto/AlbumDto.hpp" #include "dto/LoginResultDto.hpp" #include "dto/SongDto.hpp" #include "model/Models.h" +#include "oatpp/core/data/mapping/ObjectMapper.hpp" + +using model::User; +using model::Song; +using model::Token; +using model::RegisterResult; + +using namespace model; +using namespace dto; namespace dto { namespace conversion { class DtoConversions { public: // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); - static dto::LoginResultDto toLoginResultDto(const model::User&, const model::Token&); + // static oatpp::data::mapping::type::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token) + // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token) + // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const User &user, const Token &token) + template + static D toLoginResultDto(const User &user, const Token &token) + { + // const model::Token& token) { + auto logRes = 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; + } // static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( - static dto::RegisterResultDto toRegisterResultDto( - const model::RegisterResult&); + template + static D toRegisterResultDto( + const model::RegisterResult ®Res) + { + auto result = RegisterResultDto::createShared(); + /** + result->message = regRes.message.c_str(); + result->registered = regRes.registered; + result->username = regRes.username.c_str(); + */ + + return result; + } // static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); - static dto::AlbumDto toAlbumDto(const model::Album&); + 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 dto::SongDto toSongDto(const model::Song&); + 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; + } // static model::Song toSong(dto::SongDto::ObjectWrapper&); - static model::Song toSong(dto::SongDto*); + template, typename Song = Song> + static model::Song toSong(D songDto) + { + 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; + + } // static model::User toUser(dto::UserDto::ObjectWrapper&); - static model::User toUser(dto::UserDto&); + template + static User toUser(D &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/Main.cpp b/src/Main.cpp index f502e80..4fc3dfb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -5,19 +5,29 @@ #include #include -#include -#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" -#include "oatpp/web/server/HttpConnectionHandler.hpp" +// #include +// #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" +// #include "oatpp/web/server/HttpConnectionHandler.hpp" + +#include + +// #include +#include +// #include +#include + #include "component/AppComponent.hpp" -#include "controller/ArtistController.hpp" +// #include "controller/ArtistController.hpp" #include "controller/AlbumController.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 "model/Models.h" #include "verify/Initialization.h" @@ -26,9 +36,13 @@ namespace fs = std::filesystem; void run(const model::BinaryPath& bConf) { component::AppComponent component; - OATPP_COMPONENT(std::shared_ptr, router); + // 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); auto coverArtController = std::make_shared(bConf); auto gnrController = std::make_shared(bConf); @@ -36,8 +50,10 @@ void run(const model::BinaryPath& bConf) { auto regController = std::make_shared(bConf); auto sngController = std::make_shared(bConf); auto yearController = std::make_shared(bConf); + */ albumController->addEndpointsToRouter(router); + /** artistController->addEndpointsToRouter(router); coverArtController->addEndpointsToRouter(router); gnrController->addEndpointsToRouter(router); @@ -45,12 +61,13 @@ void run(const model::BinaryPath& bConf) { regController->addEndpointsToRouter(router); sngController->addEndpointsToRouter(router); yearController->addEndpointsToRouter(router); + */ - OATPP_COMPONENT(std::shared_ptr, connectionHandler); + // 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()); diff --git a/src/dto/conversion/DtoConversions.cpp b/src/dto/conversion/DtoConversions.cpp index cb52a4e..1391413 100644 --- a/src/dto/conversion/DtoConversions.cpp +++ b/src/dto/conversion/DtoConversions.cpp @@ -1,20 +1,18 @@ #include "dto/conversion/DtoConversions.h" + namespace dto { namespace conversion { // LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, - LoginResultDto 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; + // dto::LoginResultDto DtoConversions::toLoginResultDto(const model::User& user, - return logRes; + /** + 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(); @@ -24,9 +22,11 @@ namespace dto { namespace conversion { 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; @@ -36,9 +36,11 @@ namespace dto { namespace conversion { 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; @@ -55,9 +57,11 @@ namespace dto { namespace conversion { 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(); @@ -75,6 +79,7 @@ namespace dto { namespace conversion { return song; } + */ // model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) { -- 2.47.3 From 8306851dcbf7a00721c9d41eb029b394a38fad28 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 19 Dec 2020 08:07:56 -0500 Subject: [PATCH 09/10] Saving changes --- .gitmodules | 3 - 3rdparty/oatpp | 1 - Scripts/Migrations/Linux/AddUpdate.sh | 26 ----- include/controller/AlbumController.hpp | 18 +-- include/controller/ArtistController.hpp | 46 +++++--- include/controller/CoverArtController.hpp | 51 +++++---- include/controller/GenreController.hpp | 36 +++--- include/controller/LoginController.hpp | 20 +++- include/controller/SongController.hpp | 97 +++++++++++----- include/controller/YearController.hpp | 52 +++++---- include/dto/conversion/DtoConversions.h | 129 ++++++++++++++-------- src/Main.cpp | 8 +- 12 files changed, 282 insertions(+), 205 deletions(-) delete mode 160000 3rdparty/oatpp delete mode 100755 Scripts/Migrations/Linux/AddUpdate.sh diff --git a/.gitmodules b/.gitmodules index cdb20ba..cf103f8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[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 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/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/include/controller/AlbumController.hpp b/include/controller/AlbumController.hpp index 59bec1b..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 @@ -27,16 +26,17 @@ #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) + OATPP_COMPONENT(std::shared_ptr, objectMapper)) : + oatpp::web::server::api::ApiController(objectMapper), + m_bConf(bConf) { } @@ -67,7 +67,7 @@ namespace controller { albums->reserve(albsDb.size()); for (auto& albDb : albsDb) { - auto alb = dto::conversion::DtoConversions::toAlbumDto>(albDb); + auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb); albums->push_back(alb); } @@ -99,7 +99,7 @@ namespace controller { 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); } diff --git a/include/controller/ArtistController.hpp b/include/controller/ArtistController.hpp index f3cf3f4..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,40 +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::Vector>::createShared(); - // List::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->push_back(art); artists->push_back(art); - // artists.push_back(art); } return createDtoResponse(Status::CODE_200, artists); @@ -68,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); @@ -83,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 c48ffb7..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,41 +18,49 @@ #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::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->push_back(cov); } @@ -63,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 c77ecb0..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,42 +18,49 @@ #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::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->push_back(gnr); } @@ -64,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, @@ -81,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..5cf1c16 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,8 +40,11 @@ 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); } diff --git a/include/controller/SongController.hpp b/include/controller/SongController.hpp index 08b89af..579deff 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,40 +33,57 @@ #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()); + 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)); + request->transferBody(&mp_reader); auto file = mp->getNamedPart("file"); + // auto file = mp->readNextPartSimple(); OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null"); @@ -78,6 +97,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,22 +114,24 @@ 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(); - // auto yearRecs = oatpp::Vector>::createShared(); std::cout << "creating object to send\n"; + for (auto& songDb : songsDb) { auto song = dto::conversion::DtoConversions::toSongDto(songDb); @@ -121,12 +143,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); @@ -144,16 +169,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(); } @@ -169,12 +198,13 @@ namespace controller { } ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate, - REQUEST(std::shared_ptr, request), - // BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { - BODY_DTO(oatpp::data::mapping::type::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, @@ -183,6 +213,7 @@ namespace controller { auto updatedSong = dto::conversion::DtoConversions::toSong(songDto); manager::SongManager songMgr(m_bConf); auto result = songMgr.updateSong(updatedSong); + if (!result) { return songDoesNotExist(); } @@ -192,18 +223,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(); } @@ -213,16 +247,19 @@ 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(); } @@ -246,8 +283,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 c8b3d6c..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,49 +17,52 @@ #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(); - // List::createShared(); auto yearRecs = oatpp::Vector>::createShared(); - // List::createShared(); - // List::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); } @@ -69,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/conversion/DtoConversions.h b/include/dto/conversion/DtoConversions.h index 3b7074f..5e38009 100644 --- a/include/dto/conversion/DtoConversions.h +++ b/include/dto/conversion/DtoConversions.h @@ -1,20 +1,19 @@ #ifndef DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_ +#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" -#include "oatpp/core/data/mapping/ObjectMapper.hpp" - -using model::User; -using model::Song; -using model::Token; -using model::RegisterResult; using namespace model; using namespace dto; @@ -22,41 +21,31 @@ using namespace dto; namespace dto { namespace conversion { class DtoConversions { public: - // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); - // static oatpp::data::mapping::type::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token) - // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token) - // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const User &user, const Token &token) - template + template> static D toLoginResultDto(const User &user, const Token &token) { - // const model::Token& token) { auto logRes = 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; - */ + 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; return logRes; } - // static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( - template + template> static D toRegisterResultDto( const model::RegisterResult ®Res) { auto result = RegisterResultDto::createShared(); - /** - result->message = regRes.message.c_str(); + result->message = (!regRes.message.empty()) ? regRes.message.c_str() : "None"; result->registered = regRes.registered; - result->username = regRes.username.c_str(); - */ + result->username = (!regRes.username.empty()) ? regRes.username.c_str() : "None"; return result; } - // static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); template> static D toAlbumDto(const Album &album) { @@ -69,11 +58,42 @@ namespace dto { namespace conversion { return result; } - template + 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() : ""; @@ -85,42 +105,53 @@ namespace dto { namespace conversion { 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; } - // static model::Song toSong(dto::SongDto::ObjectWrapper&); - template, typename Song = Song> - static model::Song toSong(D songDto) + 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; + int id = songDto->id; + song.id = (songDto->id.getPtr() == nullptr) ? 0 : id; + auto title = songDto->title.get(); /** - 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(); - */ + 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.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; } - // static model::User toUser(dto::UserDto::ObjectWrapper&); - template - static User toUser(D &userDto) + template> + static User toUser(const D &userDto) { - model::User user; + User user; + int id = userDto->userId; /** - user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue(); + 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(); diff --git a/src/Main.cpp b/src/Main.cpp index 4fc3dfb..8fbbb36 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -18,16 +18,14 @@ #include "component/AppComponent.hpp" -// #include "controller/ArtistController.hpp" +#include "controller/ArtistController.hpp" #include "controller/AlbumController.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 "model/Models.h" #include "verify/Initialization.h" @@ -42,7 +40,6 @@ void run(const model::BinaryPath& bConf) { auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router); auto albumController = std::make_shared(bConf); - /** auto artistController = std::make_shared(bConf); auto coverArtController = std::make_shared(bConf); auto gnrController = std::make_shared(bConf); @@ -50,10 +47,8 @@ void run(const model::BinaryPath& bConf) { auto regController = std::make_shared(bConf); auto sngController = std::make_shared(bConf); auto yearController = std::make_shared(bConf); - */ albumController->addEndpointsToRouter(router); - /** artistController->addEndpointsToRouter(router); coverArtController->addEndpointsToRouter(router); gnrController->addEndpointsToRouter(router); @@ -61,7 +56,6 @@ void run(const model::BinaryPath& bConf) { regController->addEndpointsToRouter(router); sngController->addEndpointsToRouter(router); yearController->addEndpointsToRouter(router); - */ // OATPP_COMPONENT(std::shared_ptr, connectionHandler); -- 2.47.3 From eb928d0f9ee9e5a1edc846a2c7f8778c8635c7a2 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sat, 19 Dec 2020 11:51:15 -0500 Subject: [PATCH 10/10] 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); - } -} -- 2.47.3