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; }