From c0fba2c9d8bdd8a08b543ac6a29608f7d3e9ab4a Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 1 Sep 2019 17:08:00 -0400 Subject: [PATCH] Move Dto's to Dto in include directory and created Dto namespace --- CMakeLists.txt | 4 ++-- include/dto/loginResultDto.hpp | 34 ++++++++++++++++++++++++++++++ include/dto/songDto.hpp | 29 +++++++++++++++++++++++++ src/controller/loginController.hpp | 6 +++--- src/controller/songController.hpp | 8 +++---- src/dto/loginResultDto.hpp | 31 --------------------------- src/dto/songDto.hpp | 26 ----------------------- 7 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 include/dto/loginResultDto.hpp create mode 100644 include/dto/songDto.hpp delete mode 100644 src/dto/loginResultDto.hpp delete mode 100644 src/dto/songDto.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index eed89b3..80ac244 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,6 @@ set(SOURCES src/database/genreRepository.cpp src/database/songRepository.cpp src/database/yearRepository.cpp - src/dto/loginResultDto.hpp - src/dto/songDto.hpp src/main.cpp src/managers/albumManager.cpp src/managers/artistManager.cpp @@ -38,6 +36,8 @@ set(HEADERS include/database/genreRepository.h include/database/songRepository.h include/database/yearRepository.h + include/dto/loginResultDto.hpp + include/dto/songDto.hpp include/managers/albumManager.h include/managers/artistManager.h include/managers/coverArtManager.h diff --git a/include/dto/loginResultDto.hpp b/include/dto/loginResultDto.hpp new file mode 100644 index 0000000..d0956fd --- /dev/null +++ b/include/dto/loginResultDto.hpp @@ -0,0 +1,34 @@ +#ifndef LOGINRESULTDTO_H_ +#define LOGINRESULTDTO_H_ + +#include "oatpp/core/data/mapping/type/Object.hpp" +#include "oatpp/core/macro/codegen.hpp" + +namespace Dto +{ + #include OATPP_CODEGEN_BEGIN(DTO) + + class loginResultDto : public oatpp::data::mapping::type::Object + { + DTO_INIT(loginResultDto, Object) + + 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); + }; + + class userDto : public oatpp::data::mapping::type::Object + { + DTO_INIT(userDto, Object) + + DTO_FIELD(String, username); + DTO_FIELD(String, password); + }; + + #include OATPP_CODEGEN_END(DTO) +} + +#endif diff --git a/include/dto/songDto.hpp b/include/dto/songDto.hpp new file mode 100644 index 0000000..e0dcc70 --- /dev/null +++ b/include/dto/songDto.hpp @@ -0,0 +1,29 @@ +#ifndef SONGDTO_H_ +#define SONGDTO_H_ + +#include "oatpp/core/data/mapping/type/Object.hpp" +#include "oatpp/core/macro/codegen.hpp" + +namespace Dto +{ + #include OATPP_CODEGEN_BEGIN(DTO) + + class songDto : public oatpp::data::mapping::type::Object + { + DTO_INIT(songDto, Object) + + DTO_FIELD(Int32, id); + DTO_FIELD(String, title); + DTO_FIELD(String, 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); + }; + + #include OATPP_CODEGEN_END(DTO) +} + +#endif diff --git a/src/controller/loginController.hpp b/src/controller/loginController.hpp index 8db3c43..1ff42ca 100644 --- a/src/controller/loginController.hpp +++ b/src/controller/loginController.hpp @@ -9,7 +9,7 @@ #include "oatpp/core/macro/component.hpp" #include "oatpp/web/server/api/ApiController.hpp" -#include "../dto/loginResultDto.hpp" +#include "dto/loginResultDto.hpp" #include "managers/token_manager.h" namespace Controller @@ -27,14 +27,14 @@ namespace Controller #include OATPP_CODEGEN_BEGIN(ApiController) - ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(userDto::ObjectWrapper, usr)) { + ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(Dto::userDto::ObjectWrapper, usr)) { OATPP_LOGI("icarus", "logging in"); Manager::token_manager tok; //auto token = tok.retrieve_token(exe_path); auto token = tok.retrieve_token(m_bConf); - auto logRes = loginResultDto::createShared(); + auto logRes = Dto::loginResultDto::createShared(); logRes->id = 0; // TODO: change this later on to something meaningful logRes->username = usr->username->c_str(); logRes->token = token.access_token.c_str(); diff --git a/src/controller/songController.hpp b/src/controller/songController.hpp index 95b80b1..54b6ee7 100644 --- a/src/controller/songController.hpp +++ b/src/controller/songController.hpp @@ -18,7 +18,7 @@ #include "oatpp/web/server/api/ApiController.hpp" #include "database/songRepository.h" -#include "../dto/songDto.hpp" +#include "dto/songDto.hpp" #include "managers/song_manager.h" #include "managers/token_manager.h" #include "models/models.h" @@ -88,11 +88,11 @@ namespace Controller std::cout << "starting process of retrieving songs" << std::endl; 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(); std::cout << "creating object to send" << std::endl; for (auto& songDb : songsDb) { - auto song = songDto::createShared(); + auto song = Dto::songDto::createShared(); song->id = songDb.id; song->title = songDb.title.c_str(); song->artist = songDb.artist.c_str(); @@ -119,7 +119,7 @@ namespace Controller songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id); - auto song = songDto::createShared(); + auto song = Dto::songDto::createShared(); song->id = songDb.id; song->title = songDb.title.c_str(); song->artist = songDb.artist.c_str(); diff --git a/src/dto/loginResultDto.hpp b/src/dto/loginResultDto.hpp deleted file mode 100644 index 935bbc7..0000000 --- a/src/dto/loginResultDto.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LOGINRESULTDTO_H_ -#define LOGINRESULTDTO_H_ - -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" - -#include OATPP_CODEGEN_BEGIN(DTO) - -class loginResultDto : public oatpp::data::mapping::type::Object -{ - DTO_INIT(loginResultDto, Object) - - 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); -}; - -class userDto : public oatpp::data::mapping::type::Object -{ - DTO_INIT(userDto, Object) - - DTO_FIELD(String, username); - DTO_FIELD(String, password); -}; - -#include OATPP_CODEGEN_END(DTO) - -#endif diff --git a/src/dto/songDto.hpp b/src/dto/songDto.hpp deleted file mode 100644 index cc13c11..0000000 --- a/src/dto/songDto.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef SONGDTO_H_ -#define SONGDTO_H_ - -#include "oatpp/core/data/mapping/type/Object.hpp" -#include "oatpp/core/macro/codegen.hpp" - -#include OATPP_CODEGEN_BEGIN(DTO) - -class songDto : public oatpp::data::mapping::type::Object -{ - DTO_INIT(songDto, Object) - - DTO_FIELD(Int32, id); - DTO_FIELD(String, title); - DTO_FIELD(String, 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); -}; - -#include OATPP_CODEGEN_END(DTO) - -#endif