From 540d665a7eed843ded43d69cfb041c1abf3fbf84 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Sun, 25 Aug 2019 15:26:47 -0400 Subject: [PATCH] Can retrieve all song records --- src/controller/loginController.hpp | 3 --- src/controller/songController.hpp | 36 +++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/controller/loginController.hpp b/src/controller/loginController.hpp index e17de5e..35460e9 100644 --- a/src/controller/loginController.hpp +++ b/src/controller/loginController.hpp @@ -2,7 +2,6 @@ #define LOGINCONTROLLER_H_ #include -#include #include #include @@ -13,8 +12,6 @@ #include "../dto/loginResultDto.hpp" #include "managers/token_manager.h" -namespace fs = std::filesystem; - class loginController : public oatpp::web::server::api::ApiController { public: diff --git a/src/controller/songController.hpp b/src/controller/songController.hpp index f35e9be..1824a80 100644 --- a/src/controller/songController.hpp +++ b/src/controller/songController.hpp @@ -2,7 +2,7 @@ #define SONGCONTROLLER_H_ #include -#include +#include #include #include #include @@ -13,6 +13,8 @@ #include "oatpp/web/mime/multipart/Reader.hpp" #include "oatpp/web/server/api/ApiController.hpp" +#include "database/songRepository.h" +#include "../dto/songDto.hpp" #include "managers/song_manager.h" #include "managers/token_manager.h" #include "models/models.h" @@ -27,8 +29,7 @@ public: #include OATPP_CODEGEN_BEGIN(ApiController) - // TODO: work on uploading a song - // and clean up + // endpoint for uploading a song ENDPOINT("POST", "/api/v1/song/data", songUpload, REQUEST(std::shared_ptr, request)) { @@ -68,11 +69,36 @@ public: return createResponse(Status::CODE_200, "OK"); } + // endpoint for retrieving all song records in json format + ENDPOINT("GET", "/api/v1/song", songRecords, + REQUEST(std::shared_ptr, request)) + { + std::cout << "starting process of retrieving songs" << std::endl; + songRepository songRepo(exe_path); + auto songsDb = songRepo.retrieveRecords(); + auto songs = oatpp::data::mapping::type::List::createShared(); + + std::cout << "creating object to send" << std::endl; + for (auto& songDb : songsDb) { + auto song = songDto::createShared(); + song->id = songDb.id; + song->title = songDb.title.c_str(); + song->artist = songDb.artist.c_str(); + song->album = songDb.album.c_str(); + song->genre = songDb.genre.c_str(); + song->year = songDb.year; + song->duration = songDb.duration; + + songs->pushBack(song); + } + + return createDtoResponse(Status::CODE_200, songs); + } + #include OATPP_CODEGEN_END(ApiController) private: std::string exe_path; - - const long dataSize = 1000000000000; + const long dataSize = std::numeric_limits::max(); }; #endif