Saving changes
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user