Working on fixing build errors

This commit is contained in:
kdeng00
2020-12-18 14:38:46 -05:00
parent ae58b60339
commit b8caefac81
17 changed files with 272 additions and 105 deletions
+59 -41
View File
@@ -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>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
AlbumController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, 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<IncomingRequest>, 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<IncomingRequest>, 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<dto::AlbumDto::ObjectWrapper>::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<oatpp::Object<AlbumDto>>::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<IncomingRequest>, 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<oatpp::Object<AlbumDto>>(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<IncomingRequest>, 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<oatpp::Object<AlbumDto>>(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
+6 -3
View File
@@ -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<dto::ArtistDto::ObjectWrapper>::createShared();
auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
// List<dto::ArtistDto::ObjectWrapper>::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);
+2 -3
View File
@@ -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<dto::CoverArtDto::ObjectWrapper>::createShared();
auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::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);
+2 -3
View File
@@ -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<dto::GenreDto::ObjectWrapper>::createShared();
auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::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);
+2 -1
View File
@@ -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<dto::UserDto>, usr)) {
manager::UserManager usrMgr(m_bConf);
auto user = dto::conversion::DtoConversions::toUser(usr);
if (usrMgr.doesUserExist(user)) {
+7 -3
View File
@@ -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<dto::SongDto::ObjectWrapper>::createShared();
// auto songs = oatpp::data::mapping::type::List<dto::SongDto::ObjectWrapper>::createShared();
auto songs = oatpp::Vector<oatpp::Object<dto::SongDto>>::createShared();
// auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::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<IncomingRequest>, 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<dto::SongDto>, songDto), PATH(Int32, id)) {
songDto->id = id;
auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
+8 -3
View File
@@ -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<dto::YearDto::ObjectWrapper>::createShared();
// auto yearRecs = oatpp::data::mapping::type::
// List<dto::YearDto::ObjectWrapper>::createShared();
// List<dto::YearDto>::createShared();
auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
// List<dto::YearDto::ObjectWrapper>::createShared();
// List<dto::YearDto>::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);