Saving changes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#ifndef ALBUMCONTROLLER_H_
|
||||
#define ALBUMCONTROLLER_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
@@ -27,16 +26,17 @@
|
||||
#include "type/Scopes.h"
|
||||
#include "type/AlbumFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace dto;
|
||||
|
||||
namespace controller {
|
||||
class AlbumController : public oatpp::web::server::api::ApiController {
|
||||
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)
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
|
||||
oatpp::web::server::api::ApiController(objectMapper),
|
||||
m_bConf(bConf)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace controller {
|
||||
albums->reserve(albsDb.size());
|
||||
|
||||
for (auto& albDb : albsDb) {
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
|
||||
albums->push_back(alb);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace controller {
|
||||
std::cout << "album exists\n";
|
||||
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id);
|
||||
|
||||
auto album = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
|
||||
auto album = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, album);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef COVERARTCONTROLLER_H_
|
||||
#define COVERARTCONTROLLER_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
@@ -19,41 +18,49 @@
|
||||
|
||||
#include "database/CoverArtRepository.h"
|
||||
#include "dto/CoverArtDto.hpp"
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
#include "manager/CoverArtManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
#include "type/CoverFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class CoverArtController : public oatpp::web::server::api::ApiController {
|
||||
namespace controller
|
||||
{
|
||||
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) { }
|
||||
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 cover art records in json format
|
||||
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
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::Vector<oatpp::Object<dto::CoverArtDto>>::createShared();
|
||||
coverArts->reserve(covsDb.size());
|
||||
|
||||
for (auto& covDb : covsDb) {
|
||||
auto cov = dto::CoverArtDto::createShared();
|
||||
cov->id = covDb.id;
|
||||
cov->songTitle = covDb.songTitle.c_str();
|
||||
auto cov = dto::conversion::DtoConversions::toCoverDto(covDb);
|
||||
|
||||
coverArts->push_back(cov);
|
||||
}
|
||||
@@ -63,39 +70,45 @@ namespace controller {
|
||||
|
||||
// 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)) {
|
||||
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");
|
||||
type::Scope::downloadCoverArt),
|
||||
Status::CODE_403,
|
||||
"Not allowed");
|
||||
|
||||
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");
|
||||
type::CoverFilter::id),
|
||||
Status::CODE_403, "song does not exist");
|
||||
|
||||
std::cout << "cover art exists\n";
|
||||
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::conversion::DtoConversions::toCoverDto(covDb);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, coverArt);
|
||||
}
|
||||
|
||||
ENDPOINT("GET", "/api/v1/coverart/download/{id}", downloadCoverArt,
|
||||
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::downloadCoverArt), Status::CODE_403, "Not allowed");
|
||||
type::Scope::downloadCoverArt),
|
||||
Status::CODE_403, "Not allowed");
|
||||
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
model::Cover covDb;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef GENRECONTROLLER_H_
|
||||
#define GENRECONTROLLER_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
@@ -19,42 +18,49 @@
|
||||
|
||||
#include "database/GenreRepository.h"
|
||||
#include "dto/GenreDto.hpp"
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
#include "manager/GenreManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "manager/YearManager.h"
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
#include "type/GenreFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class GenreController : public oatpp::web::server::api::ApiController {
|
||||
namespace controller
|
||||
{
|
||||
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) { }
|
||||
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 genre records in json format
|
||||
ENDPOINT("GET", "/api/v1/genre", genreRecords,
|
||||
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::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::Vector<oatpp::Object<dto::GenreDto>>::createShared();
|
||||
genres->reserve(gnrsDb.size());
|
||||
|
||||
for (auto& gnrDb : gnrsDb) {
|
||||
auto gnr = dto::GenreDto::createShared();
|
||||
gnr->id = gnrDb.id;
|
||||
gnr->category = gnrDb.category.c_str();
|
||||
auto gnr = dto::conversion::DtoConversions::toGenreDto(gnrDb);
|
||||
|
||||
genres->push_back(gnr);
|
||||
}
|
||||
@@ -64,9 +70,11 @@ namespace controller {
|
||||
|
||||
// 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)) {
|
||||
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,
|
||||
@@ -81,9 +89,7 @@ namespace controller {
|
||||
std::cout << "genre exist\n";
|
||||
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::conversion::DtoConversions::toGenreDto(gnrDb);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, genre);
|
||||
}
|
||||
|
||||
@@ -9,23 +9,30 @@
|
||||
#include "oatpp/core/macro/component.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
#include "dto/LoginResultDto.hpp"
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "manager/UserManager.h"
|
||||
#include "model/Models.h"
|
||||
|
||||
namespace controller {
|
||||
class LoginController : public oatpp::web::server::api::ApiController {
|
||||
namespace controller
|
||||
{
|
||||
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) { }
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
|
||||
oatpp::web::server::api::ApiController(objectMapper),
|
||||
m_bConf(bConf)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||
|
||||
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(oatpp::Object<UserDto>, usr))
|
||||
{
|
||||
OATPP_LOGI("icarus", "logging in");
|
||||
|
||||
manager::UserManager usrMgr(m_bConf);
|
||||
@@ -33,8 +40,11 @@ namespace controller {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include "oatpp/core/macro/component.hpp"
|
||||
#include "oatpp/web/mime/multipart/InMemoryPartReader.hpp"
|
||||
#include "oatpp/web/mime/multipart/Multipart.hpp"
|
||||
#include "oatpp/web/mime/multipart/PartList.hpp"
|
||||
#include "oatpp/web/mime/multipart/Reader.hpp"
|
||||
#include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
@@ -31,40 +33,57 @@
|
||||
#include "type/SongFilter.h"
|
||||
#include "type/SongUpload.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class SongController : public oatpp::web::server::api::ApiController {
|
||||
using namespace dto;
|
||||
|
||||
|
||||
namespace controller
|
||||
{
|
||||
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)
|
||||
|
||||
// endpoint for uploading a song
|
||||
ENDPOINT("POST", "/api/v1/song/data", songUpload,
|
||||
//AUTHORIZATION(std::shared_ptr<oatpp::web::server::handler::DefaultBearerAuthorizationObject>, authObject),
|
||||
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::upload), Status::CODE_403, "Not allowed");
|
||||
type::Scope::upload),
|
||||
Status::CODE_403, "Not allowed");
|
||||
|
||||
auto mp =
|
||||
std::make_shared<oatpp::web::mime::multipart::Multipart>
|
||||
std::make_shared<oatpp::web::mime::multipart::PartList>
|
||||
(request->getHeaders());
|
||||
|
||||
oatpp::web::mime::multipart::Reader mp_reader(mp.get());
|
||||
// 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.setDefaultPartReader(
|
||||
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
|
||||
|
||||
|
||||
request->transferBody(&mp_reader);
|
||||
|
||||
auto file = mp->getNamedPart("file");
|
||||
// auto file = mp->readNextPartSimple();
|
||||
|
||||
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
|
||||
|
||||
@@ -78,6 +97,7 @@ namespace controller {
|
||||
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
const auto result = songMgr.saveSong(sng);
|
||||
|
||||
if (!result.first) {
|
||||
switch (result.second) {
|
||||
case type::SongUpload::AlreadyExist:
|
||||
@@ -94,22 +114,24 @@ namespace controller {
|
||||
|
||||
// endpoint for retrieving all song records in json format
|
||||
ENDPOINT("GET", "/api/v1/song", songRecords,
|
||||
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::retrieveSong), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
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);
|
||||
|
||||
@@ -121,12 +143,15 @@ namespace controller {
|
||||
|
||||
// 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)) {
|
||||
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");
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::retrieveSong),
|
||||
Status::CODE_403, "Not allowed");
|
||||
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb(id);
|
||||
@@ -144,16 +169,20 @@ namespace controller {
|
||||
}
|
||||
|
||||
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
||||
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::download), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
}
|
||||
@@ -169,12 +198,13 @@ 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(oatpp::data::mapping::type::ObjectWrapper<dto::SongDto>, songDto), PATH(Int32, id)) {
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request),
|
||||
BODY_DTO(oatpp::Object<SongDto>, 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,
|
||||
@@ -183,6 +213,7 @@ namespace controller {
|
||||
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
auto result = songMgr.updateSong(updatedSong);
|
||||
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
@@ -192,18 +223,21 @@ namespace controller {
|
||||
|
||||
// endpoint to delete a song
|
||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete,
|
||||
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::deleteSong), Status::CODE_403, "Not allowed");
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::deleteSong),
|
||||
Status::CODE_403, "Not allowed");
|
||||
|
||||
model::Song song(id);
|
||||
|
||||
manager::SongManager sngMgr(m_bConf);
|
||||
auto result = sngMgr.deleteSong(song);
|
||||
|
||||
if (!result) {
|
||||
return songDoesNotExist();
|
||||
}
|
||||
@@ -213,16 +247,19 @@ namespace controller {
|
||||
|
||||
// endpoint for streaming a song
|
||||
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong,
|
||||
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::stream), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
}
|
||||
@@ -246,8 +283,8 @@ namespace controller {
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
|
||||
songDoesNotExist() {
|
||||
|
||||
songDoesNotExist()
|
||||
{
|
||||
return createResponse(Status::CODE_404, "Song not found");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef YEARCONTROLLER_H_
|
||||
#define YEARCONTROLLER_H_
|
||||
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
@@ -18,49 +17,52 @@
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
|
||||
#include "database/YearRepository.h"
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
#include "dto/YearDto.hpp"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "manager/YearManager.h"
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
#include "type/YearFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace controller {
|
||||
class YearController : public oatpp::web::server::api::ApiController {
|
||||
namespace controller
|
||||
{
|
||||
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) { }
|
||||
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 year records in json format
|
||||
ENDPOINT("GET", "/api/v1/year", yearRecords,
|
||||
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::retrieveYear), Status::CODE_403, "Not allowed");
|
||||
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();
|
||||
// List<dto::YearDto>::createShared();
|
||||
auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
|
||||
// List<dto::YearDto::ObjectWrapper>::createShared();
|
||||
// List<dto::YearDto>::createShared();
|
||||
yearRecs->reserve(yrsDb.size());
|
||||
|
||||
for (auto& yrDb : yrsDb) {
|
||||
auto yr = dto::YearDto::createShared();
|
||||
yr->id = yrDb.id;
|
||||
yr->year = yrDb.year;
|
||||
for (auto &yrDb : yrsDb) {
|
||||
auto yr = dto::conversion::DtoConversions::toYearDto(yrDb);
|
||||
|
||||
// yearRecs->pushBack(yr);
|
||||
yearRecs->push_back(yr);
|
||||
}
|
||||
|
||||
@@ -69,26 +71,28 @@ namespace controller {
|
||||
|
||||
// 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)) {
|
||||
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");
|
||||
type::Scope::retrieveYear),
|
||||
Status::CODE_403, "Not allowed");
|
||||
|
||||
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");
|
||||
type::YearFilter::id),
|
||||
Status::CODE_403, "year does not exist");
|
||||
|
||||
std::cout << "year exist\n";
|
||||
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
|
||||
|
||||
auto year = dto::YearDto::createShared();
|
||||
year->id = yrDb.id;
|
||||
year->year= yrDb.year;
|
||||
auto year = dto::conversion::DtoConversions::toYearDto(yrDb);
|
||||
|
||||
return createDtoResponse(Status::CODE_200, year);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user