Saving changes
This commit is contained in:
@@ -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>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, 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<IncomingRequest>, request)) {
|
||||
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::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<oatpp::Object<dto::ArtistDto>>::createShared();
|
||||
// List<dto::ArtistDto::ObjectWrapper>::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<IncomingRequest>, request), PATH(Int32, id)) {
|
||||
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::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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user