Code cleanup
This commit is contained in:
@@ -29,69 +29,66 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class AlbumController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
AlbumController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
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,
|
||||
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
|
||||
|
||||
// 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" << std::endl;
|
||||
database::AlbumRepository albRepo(m_bConf);
|
||||
auto albsDb = albRepo.retrieveRecords();
|
||||
auto albums = oatpp::data::mapping::type::List<dto::AlbumDto::ObjectWrapper>::createShared();
|
||||
for (auto& albDb : albsDb) {
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
|
||||
for (auto& albDb : albsDb) {
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
albums->pushBack(alb);
|
||||
}
|
||||
|
||||
albums->pushBack(alb);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, albums);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// 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,
|
||||
type::AlbumFilter::id) , Status::CODE_403, "album does not exist");
|
||||
|
||||
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" << std::endl;
|
||||
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id);
|
||||
auto album = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
|
||||
auto album = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
return createDtoResponse(Status::CODE_200, album);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, album);
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,73 +28,70 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class ArtistController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
ArtistController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
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) { }
|
||||
|
||||
ArtistController(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 artist records in json format
|
||||
ENDPOINT("GET", "/api/v1/artist", artistRecords,
|
||||
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");
|
||||
|
||||
// endpoint for retrieving all artist records in json format
|
||||
ENDPOINT("GET", "/api/v1/artist", artistRecords,
|
||||
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");
|
||||
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();
|
||||
|
||||
std::cout << "starting process of retrieving artist" << std::endl;
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
auto artsDb = artRepo.retrieveRecords();
|
||||
auto artists = oatpp::data::mapping::type::List<dto::ArtistDto::ObjectWrapper>::createShared();
|
||||
for (auto& artDb : artsDb) {
|
||||
auto art = dto::ArtistDto::createShared();
|
||||
art->id = artDb.id;
|
||||
art->artist = artDb.artist.c_str();
|
||||
|
||||
for (auto& artDb : artsDb) {
|
||||
auto art = dto::ArtistDto::createShared();
|
||||
art->id = artDb.id;
|
||||
art->artist = artDb.artist.c_str();
|
||||
artists->pushBack(art);
|
||||
}
|
||||
|
||||
artists->pushBack(art);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, artists);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, artists);
|
||||
}
|
||||
// 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)) {
|
||||
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");
|
||||
|
||||
// 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)) {
|
||||
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");
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
model::Artist artDb(id);
|
||||
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
model::Artist artDb(id);
|
||||
OATPP_ASSERT_HTTP(artRepo.doesArtistExist(artDb,
|
||||
type::ArtistFilter::id) , Status::CODE_403, "artist does not exist");
|
||||
|
||||
OATPP_ASSERT_HTTP(artRepo.doesArtistExist(artDb, type::ArtistFilter::id) , Status::CODE_403, "artist does not exist");
|
||||
std::cout << "artist exist\n";
|
||||
artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id);
|
||||
|
||||
std::cout << "artist exist" << std::endl;
|
||||
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::ArtistDto::createShared();
|
||||
artist->id = artDb.id;
|
||||
artist->artist = artDb.artist.c_str();
|
||||
return createDtoResponse(Status::CODE_200, artist);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, artist);
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,95 +27,93 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class CoverArtController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
CoverArtController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
class CoverArtController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
CoverArtController(const model::BinaryPath& bConf,
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
|
||||
CoverArtController(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 cover art records in json format
|
||||
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving all cover art records in json format
|
||||
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
|
||||
std::cout << "starting process of retrieving cover art" << std::endl;
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
auto covsDb = covRepo.retrieveRecords();
|
||||
auto coverArts = oatpp::data::mapping::type::List<dto::CoverArtDto::ObjectWrapper>::createShared();
|
||||
for (auto& covDb : covsDb) {
|
||||
auto cov = dto::CoverArtDto::createShared();
|
||||
cov->id = covDb.id;
|
||||
cov->songTitle = covDb.songTitle.c_str();
|
||||
|
||||
for (auto& covDb : covsDb) {
|
||||
auto cov = dto::CoverArtDto::createShared();
|
||||
cov->id = covDb.id;
|
||||
cov->songTitle = covDb.songTitle.c_str();
|
||||
coverArts->pushBack(cov);
|
||||
}
|
||||
|
||||
coverArts->pushBack(cov);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, coverArts);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, coverArts);
|
||||
}
|
||||
// endpoint for retrieving single cover art record by the cover art id in json format
|
||||
ENDPOINT("GET", "/api/v1/coverart/{id}", coverArtRecord,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving single cover art record by the cover art id in json format
|
||||
ENDPOINT("GET", "/api/v1/coverart/{id}", coverArtRecord,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
model::Cover covDb;
|
||||
covDb.id = id;
|
||||
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
model::Cover covDb;
|
||||
covDb.id = id;
|
||||
OATPP_ASSERT_HTTP(covRepo.doesCoverArtExist(covDb,
|
||||
type::CoverFilter::id) , Status::CODE_403, "song does not exist");
|
||||
|
||||
OATPP_ASSERT_HTTP(covRepo.doesCoverArtExist(covDb, type::CoverFilter::id) , Status::CODE_403, "song does not exist");
|
||||
std::cout << "cover art exists\n";
|
||||
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
|
||||
|
||||
std::cout << "cover art exists" << std::endl;
|
||||
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
|
||||
auto coverArt = dto::CoverArtDto::createShared();
|
||||
coverArt->id = covDb.id;
|
||||
coverArt->songTitle = covDb.songTitle.c_str();
|
||||
|
||||
auto coverArt = dto::CoverArtDto::createShared();
|
||||
coverArt->id = covDb.id;
|
||||
coverArt->songTitle = covDb.songTitle.c_str();
|
||||
return createDtoResponse(Status::CODE_200, coverArt);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, coverArt);
|
||||
}
|
||||
ENDPOINT("GET", "/api/v1/coverart/download/{id}", downloadCoverArt,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
|
||||
ENDPOINT("GET", "/api/v1/coverart/download/{id}", downloadCoverArt,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
model::Cover covDb;
|
||||
covDb.id = id;
|
||||
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
|
||||
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
model::Cover covDb;
|
||||
covDb.id = id;
|
||||
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
|
||||
auto rawCover = oatpp::base::StrBuffer::loadFromFile(covDb.imagePath.c_str());
|
||||
auto response = createResponse(Status::CODE_200, rawCover);
|
||||
|
||||
response->putHeader(Header::CONTENT_TYPE, "image/*");
|
||||
|
||||
auto rawCover = oatpp::base::StrBuffer::loadFromFile(covDb.imagePath.c_str());
|
||||
auto response = createResponse(Status::CODE_200, rawCover);
|
||||
|
||||
response->putHeader(Header::CONTENT_TYPE, "image/*");
|
||||
return response;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,73 +28,70 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class GenreController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
GenreController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
class GenreController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
GenreController(const model::BinaryPath& bConf,
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
|
||||
GenreController(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 genre records in json format
|
||||
ENDPOINT("GET", "/api/v1/genre", genreRecords,
|
||||
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::retrieveGenre), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving all genre records in json format
|
||||
ENDPOINT("GET", "/api/v1/genre", genreRecords,
|
||||
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::retrieveGenre), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
|
||||
std::cout << "starting process of retrieving genre" << std::endl;
|
||||
database::GenreRepository gnrRepo(m_bConf);
|
||||
auto gnrsDb = gnrRepo.retrieveRecords();
|
||||
auto genres = oatpp::data::mapping::type::List<dto::GenreDto::ObjectWrapper>::createShared();
|
||||
for (auto& gnrDb : gnrsDb) {
|
||||
auto gnr = dto::GenreDto::createShared();
|
||||
gnr->id = gnrDb.id;
|
||||
gnr->category = gnrDb.category.c_str();
|
||||
|
||||
for (auto& gnrDb : gnrsDb) {
|
||||
auto gnr = dto::GenreDto::createShared();
|
||||
gnr->id = gnrDb.id;
|
||||
gnr->category = gnrDb.category.c_str();
|
||||
genres->pushBack(gnr);
|
||||
}
|
||||
|
||||
genres->pushBack(gnr);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, genres);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, genres);
|
||||
}
|
||||
// endpoint for retrieving single genre record by the genre id in json format
|
||||
ENDPOINT("GET", "/api/v1/genre/{id}", genreRecord,
|
||||
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::retrieveGenre), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving single genre record by the genre id in json format
|
||||
ENDPOINT("GET", "/api/v1/genre/{id}", genreRecord,
|
||||
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::retrieveGenre), Status::CODE_403, "Not allowed");
|
||||
database::GenreRepository gnrRepo(m_bConf);
|
||||
model::Genre gnrDb(id);
|
||||
|
||||
database::GenreRepository gnrRepo(m_bConf);
|
||||
model::Genre gnrDb(id);
|
||||
OATPP_ASSERT_HTTP(gnrRepo.doesGenreExist(gnrDb,
|
||||
type::GenreFilter::id) , Status::CODE_403, "genre does not exist");
|
||||
|
||||
OATPP_ASSERT_HTTP(gnrRepo.doesGenreExist(gnrDb, type::GenreFilter::id) , Status::CODE_403, "genre does not exist");
|
||||
std::cout << "genre exist\n";
|
||||
gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id);
|
||||
|
||||
std::cout << "genre exist" << std::endl;
|
||||
gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id);
|
||||
auto genre = dto::GenreDto::createShared();
|
||||
genre->id = gnrDb.id;
|
||||
genre->category= gnrDb.category.c_str();
|
||||
|
||||
auto genre = dto::GenreDto::createShared();
|
||||
genre->id = gnrDb.id;
|
||||
genre->category= gnrDb.category.c_str();
|
||||
return createDtoResponse(Status::CODE_200, genre);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, genre);
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -16,46 +16,42 @@
|
||||
#include "model/Models.h"
|
||||
|
||||
namespace controller {
|
||||
class LoginController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
LoginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), exe_path(p)
|
||||
{ }
|
||||
LoginController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
:oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf)
|
||||
{ }
|
||||
class LoginController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
LoginController(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("POST", "/api/v1/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
OATPP_LOGI("icarus", "logging in");
|
||||
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
OATPP_LOGI("icarus", "logging in");
|
||||
|
||||
manager::UserManager usrMgr(m_bConf);
|
||||
auto user = dto::conversion::DtoConversions::toUser(usr);
|
||||
manager::UserManager usrMgr(m_bConf);
|
||||
auto user = dto::conversion::DtoConversions::toUser(usr);
|
||||
|
||||
if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) {
|
||||
auto logRes = dto::LoginResultDto::createShared();
|
||||
logRes->message = "invalid credentials";
|
||||
std::cout << "user does not exist" << std::endl;
|
||||
return createDtoResponse(Status::CODE_401, logRes);
|
||||
}
|
||||
if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) {
|
||||
auto logRes = dto::LoginResultDto::createShared();
|
||||
logRes->message = "invalid credentials";
|
||||
std::cout << "user does not exist\n";
|
||||
return createDtoResponse(Status::CODE_401, logRes);
|
||||
}
|
||||
|
||||
std::cout << "user exists" << std::endl;
|
||||
std::cout << "user exists\n";
|
||||
|
||||
manager::TokenManager tok;
|
||||
auto token = tok.retrieveToken(m_bConf);
|
||||
manager::TokenManager tok;
|
||||
auto token = tok.retrieveToken(m_bConf);
|
||||
|
||||
auto logRes = dto::conversion::DtoConversions::toLoginResultDto(user, token);
|
||||
logRes->message = "Successful";
|
||||
auto logRes = dto::conversion::DtoConversions::toLoginResultDto(user, token);
|
||||
logRes->message = "Successful";
|
||||
|
||||
return createDtoResponse(Status::CODE_200, logRes);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, logRes);
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace controller {
|
||||
class RegisterController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
RegisterController(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)
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace controller {
|
||||
BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
manager::UserManager usrMgr(m_bConf);
|
||||
auto user = dto::conversion::DtoConversions::toUser(usr);
|
||||
if (usrMgr.doesUserExist(user)) {
|
||||
return createResponse(Status::CODE_401, "user already exists");
|
||||
}
|
||||
|
||||
auto res = usrMgr.registerUser(user);
|
||||
auto registerResult = dto::conversion::DtoConversions::toRegisterResultDto(res);
|
||||
|
||||
@@ -32,219 +32,219 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class SongController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
SongController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
class SongController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
|
||||
SongController(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 uploading a song
|
||||
ENDPOINT("POST", "/api/v1/song/data", songUpload,
|
||||
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::upload), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for uploading a song
|
||||
ENDPOINT("POST", "/api/v1/song/data", songUpload,
|
||||
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::upload), Status::CODE_403, "Not allowed");
|
||||
auto mp =
|
||||
std::make_shared<oatpp::web::mime::multipart::Multipart>
|
||||
(request->getHeaders());
|
||||
|
||||
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
|
||||
oatpp::web::mime::multipart::Reader mp_reader(mp.get());
|
||||
|
||||
oatpp::web::mime::multipart::Reader mp_reader(mp.get());
|
||||
mp_reader.setPartReader("file",
|
||||
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
|
||||
|
||||
mp_reader.setPartReader("file", oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
|
||||
request->transferBody(&mp_reader);
|
||||
|
||||
request->transferBody(&mp_reader);
|
||||
auto file = mp->getNamedPart("file");
|
||||
|
||||
auto file = mp->getNamedPart("file");
|
||||
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
|
||||
|
||||
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
|
||||
auto buff = std::unique_ptr<char>(new char[file->getKnownSize()]);
|
||||
auto buffSize = file->getInputStream()->read(buff.get(), file->getKnownSize());
|
||||
|
||||
auto buff = std::unique_ptr<char>(new char[file->getKnownSize()]);
|
||||
auto buffSize = file->getInputStream()->read(buff.get(), file->getKnownSize());
|
||||
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
|
||||
|
||||
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
|
||||
model::Song sng;
|
||||
sng.data = std::move(data);
|
||||
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
const auto result = songMgr.saveSong(sng);
|
||||
if (!result.first) {
|
||||
switch (result.second) {
|
||||
case type::SongUpload::AlreadyExist:
|
||||
return createResponse(Status::CODE_400, "Song already exists");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
model::Song sng;
|
||||
sng.data = std::move(data);
|
||||
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
const auto result = songMgr.saveSong(sng);
|
||||
if (!result.first) {
|
||||
switch (result.second) {
|
||||
case type::SongUpload::AlreadyExist:
|
||||
return createResponse(Status::CODE_400, "Song already exists");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto songDto = dto::conversion::DtoConversions::toSongDto(sng);
|
||||
|
||||
auto songDto = dto::conversion::DtoConversions::toSongDto(sng);
|
||||
return createDtoResponse(Status::CODE_200, songDto);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, songDto);
|
||||
}
|
||||
// endpoint for retrieving all song records in json format
|
||||
ENDPOINT("GET", "/api/v1/song", songRecords,
|
||||
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::retrieveSong), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving all song records in json format
|
||||
ENDPOINT("GET", "/api/v1/song", songRecords,
|
||||
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::retrieveSong), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
|
||||
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<dto::SongDto::ObjectWrapper>::createShared();
|
||||
std::cout << "creating object to send\n";
|
||||
for (auto& songDb : songsDb) {
|
||||
auto song = dto::conversion::DtoConversions::toSongDto(songDb);
|
||||
|
||||
std::cout << "creating object to send" << std::endl;
|
||||
for (auto& songDb : songsDb) {
|
||||
auto song = dto::conversion::DtoConversions::toSongDto(songDb);
|
||||
songs->pushBack(song);
|
||||
}
|
||||
|
||||
songs->pushBack(song);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, songs);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, songs);
|
||||
}
|
||||
|
||||
// endpoint for retrieving song record by the song id in json format
|
||||
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
||||
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::retrieveSong), Status::CODE_403, "Not allowed");
|
||||
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
||||
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::retrieveSong), Status::CODE_403, "Not allowed");
|
||||
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
|
||||
std::cout << "song exists" << std::endl;
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
std::cout << "song exists\n";
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
auto song = dto::conversion::DtoConversions::toSongDto(songDb);
|
||||
auto song = dto::conversion::DtoConversions::toSongDto(songDb);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, song);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, song);
|
||||
}
|
||||
|
||||
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
||||
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::download), Status::CODE_403, "Not allowed");
|
||||
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
||||
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::download), Status::CODE_403, "Not allowed");
|
||||
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
auto rawSong = oatpp::base::StrBuffer::loadFromFile(songDb.songPath.c_str());
|
||||
|
||||
auto response = createResponse(Status::CODE_200, rawSong);
|
||||
response->putHeader(Header::CONTENT_TYPE, "audio/mpeg");
|
||||
auto rawSong = oatpp::base::StrBuffer::loadFromFile(songDb.songPath.c_str());
|
||||
|
||||
auto response = createResponse(Status::CODE_200, rawSong);
|
||||
response->putHeader(Header::CONTENT_TYPE, "audio/mpeg");
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request),
|
||||
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
||||
songDto->id = 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::updateSong), Status::CODE_403, "Not allowed");
|
||||
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request),
|
||||
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
||||
songDto->id = 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::updateSong), Status::CODE_403, "Not allowed");
|
||||
|
||||
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
auto result = songMgr.updateSong(updatedSong);
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
auto result = songMgr.updateSong(updatedSong);
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
|
||||
// endpoint to delete a song
|
||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete,
|
||||
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::deleteSong), Status::CODE_403, "Not allowed");
|
||||
// endpoint to delete a song
|
||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete,
|
||||
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::deleteSong), Status::CODE_403, "Not allowed");
|
||||
|
||||
model::Song song(id);
|
||||
model::Song song(id);
|
||||
|
||||
manager::SongManager sngMgr(m_bConf);
|
||||
auto result = sngMgr.deleteSong(song);
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
manager::SongManager sngMgr(m_bConf);
|
||||
auto result = sngMgr.deleteSong(song);
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
|
||||
// endpoint for streaming a song
|
||||
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong,
|
||||
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::stream), Status::CODE_403, "Not allowed");
|
||||
// endpoint for streaming a song
|
||||
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong,
|
||||
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::stream), Status::CODE_403, "Not allowed");
|
||||
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
oatpp::data::v_io_size dSize = 1024;
|
||||
oatpp::data::v_io_size dSize = 1024;
|
||||
|
||||
auto db = std::make_shared<oatpp::web::protocol::http::outgoing::ChunkedBody>(
|
||||
std::make_shared<callback::StreamCallback>(songDb.songPath), nullptr, dSize);
|
||||
auto db = std::make_shared<oatpp::web::protocol::http::outgoing::ChunkedBody>(
|
||||
std::make_shared<callback::StreamCallback>(songDb.songPath),
|
||||
nullptr, dSize);
|
||||
|
||||
auto response = OutgoingResponse::createShared(Status::CODE_200, db);
|
||||
response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE);
|
||||
response->putHeader(Header::CONTENT_TYPE, "audio/mpeg");
|
||||
auto response = OutgoingResponse::createShared(Status::CODE_200, db);
|
||||
response->putHeader(Header::CONNECTION, Header::Value::CONNECTION_KEEP_ALIVE);
|
||||
response->putHeader(Header::CONTENT_TYPE, "audio/mpeg");
|
||||
|
||||
return response;
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
|
||||
songDoesNotExist() {
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
|
||||
songDoesNotExist() {
|
||||
|
||||
return createResponse(Status::CODE_404, "Song not found");
|
||||
}
|
||||
return createResponse(Status::CODE_404, "Song not found");
|
||||
}
|
||||
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
|
||||
model::BinaryPath m_bConf;
|
||||
|
||||
const long m_dataSize = std::numeric_limits<long long int>::max();
|
||||
};
|
||||
const long m_dataSize = std::numeric_limits<long long int>::max();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,73 +27,71 @@
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class YearController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
YearController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
class YearController : public oatpp::web::server::api::ApiController {
|
||||
public:
|
||||
YearController(const model::BinaryPath& bConf,
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
|
||||
|
||||
YearController(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 year records in json format
|
||||
ENDPOINT("GET", "/api/v1/year", yearRecords,
|
||||
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::retrieveYear), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving all year records in json format
|
||||
ENDPOINT("GET", "/api/v1/year", yearRecords,
|
||||
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::retrieveYear), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
|
||||
std::cout << "starting process of retrieving year" << std::endl;
|
||||
database::YearRepository yrRepo(m_bConf);
|
||||
auto yrsDb = yrRepo.retrieveRecords();
|
||||
auto yearRecs = oatpp::data::mapping::type::List<dto::YearDto::ObjectWrapper>::createShared();
|
||||
for (auto& yrDb : yrsDb) {
|
||||
auto yr = dto::YearDto::createShared();
|
||||
yr->id = yrDb.id;
|
||||
yr->year = yrDb.year;
|
||||
|
||||
for (auto& yrDb : yrsDb) {
|
||||
auto yr = dto::YearDto::createShared();
|
||||
yr->id = yrDb.id;
|
||||
yr->year = yrDb.year;
|
||||
yearRecs->pushBack(yr);
|
||||
}
|
||||
|
||||
yearRecs->pushBack(yr);
|
||||
}
|
||||
return createDtoResponse(Status::CODE_200, yearRecs);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, yearRecs);
|
||||
}
|
||||
// endpoint for retrieving single year record by the year id in json format
|
||||
ENDPOINT("GET", "/api/v1/year/{id}", yearRecord,
|
||||
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::retrieveYear), Status::CODE_403, "Not allowed");
|
||||
|
||||
// endpoint for retrieving single year record by the year id in json format
|
||||
ENDPOINT("GET", "/api/v1/year/{id}", yearRecord,
|
||||
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::retrieveYear), Status::CODE_403, "Not allowed");
|
||||
database::YearRepository yrRepo(m_bConf);
|
||||
model::Year yrDb(id);
|
||||
|
||||
database::YearRepository yrRepo(m_bConf);
|
||||
model::Year yrDb(id);
|
||||
OATPP_ASSERT_HTTP(yrRepo.doesYearExist(yrDb,
|
||||
type::YearFilter::id) , Status::CODE_403, "year does not exist");
|
||||
|
||||
OATPP_ASSERT_HTTP(yrRepo.doesYearExist(yrDb, type::YearFilter::id) , Status::CODE_403, "year does not exist");
|
||||
std::cout << "year exist\n";
|
||||
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
|
||||
|
||||
std::cout << "year exist" << std::endl;
|
||||
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
|
||||
auto year = dto::YearDto::createShared();
|
||||
year->id = yrDb.id;
|
||||
year->year= yrDb.year;
|
||||
|
||||
auto year = dto::YearDto::createShared();
|
||||
year->id = yrDb.id;
|
||||
year->year= yrDb.year;
|
||||
return createDtoResponse(Status::CODE_200, year);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, year);
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user