Saving changes

This commit is contained in:
kdeng00
2020-12-19 08:07:56 -05:00
parent b8caefac81
commit 8306851dcb
12 changed files with 282 additions and 205 deletions
-3
View File
@@ -1,6 +1,3 @@
[submodule "3rdparty/oatpp"]
path = 3rdparty/oatpp
url = https://github.com/oatpp/oatpp
[submodule "build/3rdparty/jwt-cpp"] [submodule "build/3rdparty/jwt-cpp"]
path = build/3rdparty/jwt-cpp path = build/3rdparty/jwt-cpp
url = https://github.com/Thalhammer/jwt-cpp url = https://github.com/Thalhammer/jwt-cpp
-1
Submodule 3rdparty/oatpp deleted from 27c46444db
-26
View File
@@ -1,26 +0,0 @@
echo "Adding migrations..."
echo "Adding User migration"
dotnet ef migrations add User --context UserContext
echo "Adding Song migration"
dotnet ef migrations add Song --context SongContext
echo "Adding Album migration"
dotnet ef migrations add Album --context AlbumContext
echo "Adding Artist migration"
dotnet ef migrations add Artist --context ArtistContext
echo "Adding Genre migration"
dotnet ef migrations add Genre --context GenreContext
echo "Adding Year migration"
dotnet ef migrations add Year --context YearContext
echo "Adding Cover art migration"
dotnet ef migrations add CoverArt --context CoverArtContext
echo "Updating migrations.."
echo "Updating User migration"
dotnet ef database update --context UserContext
echo "Updating Song migration"
echo "Updating Album migration"
echo "Updating Artist migration"
echo "Updating Genre migration"
echo "Updating Year migration"
echo "Updating Cover art migration"
dotnet ef database update --context SongContext
+9 -9
View File
@@ -1,7 +1,6 @@
#ifndef ALBUMCONTROLLER_H_ #ifndef ALBUMCONTROLLER_H_
#define ALBUMCONTROLLER_H_ #define ALBUMCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -27,16 +26,17 @@
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/AlbumFilter.h" #include "type/AlbumFilter.h"
namespace fs = std::filesystem;
using namespace dto; using namespace dto;
namespace controller { namespace controller
class AlbumController : public oatpp::web::server::api::ApiController { {
class AlbumController : public oatpp::web::server::api::ApiController
{
public: public:
AlbumController(const model::BinaryPath& bConf, AlbumController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf) m_bConf(bConf)
{ {
} }
@@ -67,7 +67,7 @@ namespace controller {
albums->reserve(albsDb.size()); albums->reserve(albsDb.size());
for (auto& albDb : albsDb) { 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); albums->push_back(alb);
} }
@@ -99,7 +99,7 @@ namespace controller {
std::cout << "album exists\n"; std::cout << "album exists\n";
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id); 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); return createDtoResponse(Status::CODE_200, album);
} }
+29 -17
View File
@@ -19,6 +19,7 @@
#include "database/ArtistRepository.h" #include "database/ArtistRepository.h"
#include "dto/ArtistDto.hpp" #include "dto/ArtistDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/ArtistManager.h" #include "manager/ArtistManager.h"
#include "manager/TokenManager.h" #include "manager/TokenManager.h"
#include "model/Models.h" #include "model/Models.h"
@@ -27,40 +28,47 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace controller { namespace controller
class ArtistController : public oatpp::web::server::api::ApiController { {
class ArtistController : public oatpp::web::server::api::ApiController
{
public: public:
ArtistController(const model::BinaryPath& bConf, ArtistController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } 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 for retrieving all artist records in json format
ENDPOINT("GET", "/api/v1/artist", artistRecords, ENDPOINT("GET", "/api/v1/artist", artistRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving artist\n";
database::ArtistRepository artRepo(m_bConf); database::ArtistRepository artRepo(m_bConf);
auto artsDb = artRepo.retrieveRecords(); auto artsDb = artRepo.retrieveRecords();
auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared(); auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
// List<dto::ArtistDto::ObjectWrapper>::createShared(); artists->reserve(artsDb.size());
for (auto& artDb : artsDb) { for (auto& artDb : artsDb) {
auto art = dto::ArtistDto::createShared(); auto art = dto::conversion::DtoConversions::toArtistDto(artDb);
art->id = artDb.id;
art->artist = artDb.artist.c_str();
// artists->push_back(art);
artists->push_back(art); artists->push_back(art);
// artists.push_back(art);
} }
return createDtoResponse(Status::CODE_200, artists); 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 for retrieving single artist record by the artist id in json format
ENDPOINT("GET", "/api/v1/artist/{id}", artistRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::ArtistRepository artRepo(m_bConf);
model::Artist artDb(id); model::Artist artDb(id);
@@ -83,11 +96,10 @@ namespace controller {
type::ArtistFilter::id) , Status::CODE_403, "artist does not exist"); type::ArtistFilter::id) , Status::CODE_403, "artist does not exist");
std::cout << "artist exist\n"; std::cout << "artist exist\n";
artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id); artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id);
auto artist = dto::ArtistDto::createShared(); auto artist = dto::conversion::DtoConversions::toArtistDto(artDb);
artist->id = artDb.id;
artist->artist = artDb.artist.c_str();
return createDtoResponse(Status::CODE_200, artist); return createDtoResponse(Status::CODE_200, artist);
} }
+32 -19
View File
@@ -1,7 +1,6 @@
#ifndef COVERARTCONTROLLER_H_ #ifndef COVERARTCONTROLLER_H_
#define COVERARTCONTROLLER_H_ #define COVERARTCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -19,41 +18,49 @@
#include "database/CoverArtRepository.h" #include "database/CoverArtRepository.h"
#include "dto/CoverArtDto.hpp" #include "dto/CoverArtDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/CoverArtManager.h" #include "manager/CoverArtManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/CoverFilter.h" #include "type/CoverFilter.h"
namespace fs = std::filesystem;
namespace controller { namespace controller
class CoverArtController : public oatpp::web::server::api::ApiController { {
class CoverArtController : public oatpp::web::server::api::ApiController
{
public: public:
CoverArtController(const model::BinaryPath& bConf, CoverArtController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } 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 for retrieving all cover art records in json format
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords, ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving cover art\n";
database::CoverArtRepository covRepo(m_bConf); database::CoverArtRepository covRepo(m_bConf);
auto covsDb = covRepo.retrieveRecords(); auto covsDb = covRepo.retrieveRecords();
auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::createShared(); auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::createShared();
coverArts->reserve(covsDb.size());
for (auto& covDb : covsDb) { for (auto& covDb : covsDb) {
auto cov = dto::CoverArtDto::createShared(); auto cov = dto::conversion::DtoConversions::toCoverDto(covDb);
cov->id = covDb.id;
cov->songTitle = covDb.songTitle.c_str();
coverArts->push_back(cov); 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 for retrieving single cover art record by the cover art id in json format
ENDPOINT("GET", "/api/v1/coverart/{id}", coverArtRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::CoverArtRepository covRepo(m_bConf);
model::Cover covDb; model::Cover covDb;
covDb.id = id; covDb.id = id;
OATPP_ASSERT_HTTP(covRepo.doesCoverArtExist(covDb, 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"; std::cout << "cover art exists\n";
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id); covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
auto coverArt = dto::CoverArtDto::createShared(); auto coverArt = dto::conversion::DtoConversions::toCoverDto(covDb);
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, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::CoverArtRepository covRepo(m_bConf);
model::Cover covDb; model::Cover covDb;
+21 -15
View File
@@ -1,7 +1,6 @@
#ifndef GENRECONTROLLER_H_ #ifndef GENRECONTROLLER_H_
#define GENRECONTROLLER_H_ #define GENRECONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -19,42 +18,49 @@
#include "database/GenreRepository.h" #include "database/GenreRepository.h"
#include "dto/GenreDto.hpp" #include "dto/GenreDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/GenreManager.h" #include "manager/GenreManager.h"
#include "manager/TokenManager.h"
#include "manager/YearManager.h" #include "manager/YearManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/GenreFilter.h" #include "type/GenreFilter.h"
namespace fs = std::filesystem; namespace controller
{
namespace controller { class GenreController : public oatpp::web::server::api::ApiController
class GenreController : public oatpp::web::server::api::ApiController { {
public: public:
GenreController(const model::BinaryPath& bConf, GenreController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } 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 for retrieving all genre records in json format
ENDPOINT("GET", "/api/v1/genre", genreRecords, ENDPOINT("GET", "/api/v1/genre", genreRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveGenre), Status::CODE_403, "Not allowed"); type::Scope::retrieveGenre), Status::CODE_403, "Not allowed");
std::cout << "starting process of retrieving genre\n"; std::cout << "starting process of retrieving genre\n";
database::GenreRepository gnrRepo(m_bConf); database::GenreRepository gnrRepo(m_bConf);
auto gnrsDb = gnrRepo.retrieveRecords(); auto gnrsDb = gnrRepo.retrieveRecords();
auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::createShared(); auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::createShared();
genres->reserve(gnrsDb.size());
for (auto& gnrDb : gnrsDb) { for (auto& gnrDb : gnrsDb) {
auto gnr = dto::GenreDto::createShared(); auto gnr = dto::conversion::DtoConversions::toGenreDto(gnrDb);
gnr->id = gnrDb.id;
gnr->category = gnrDb.category.c_str();
genres->push_back(gnr); genres->push_back(gnr);
} }
@@ -64,9 +70,11 @@ namespace controller {
// endpoint for retrieving single genre record by the genre id in json format // endpoint for retrieving single genre record by the genre id in json format
ENDPOINT("GET", "/api/v1/genre/{id}", genreRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
@@ -81,9 +89,7 @@ namespace controller {
std::cout << "genre exist\n"; std::cout << "genre exist\n";
gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id); gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id);
auto genre = dto::GenreDto::createShared(); auto genre = dto::conversion::DtoConversions::toGenreDto(gnrDb);
genre->id = gnrDb.id;
genre->category= gnrDb.category.c_str();
return createDtoResponse(Status::CODE_200, genre); return createDtoResponse(Status::CODE_200, genre);
} }
+15 -5
View File
@@ -9,23 +9,30 @@
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "dto/conversion/DtoConversions.h"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
#include "dto/conversion/DtoConversions.h" #include "dto/conversion/DtoConversions.h"
#include "manager/TokenManager.h" #include "manager/TokenManager.h"
#include "manager/UserManager.h" #include "manager/UserManager.h"
#include "model/Models.h" #include "model/Models.h"
namespace controller { namespace controller
class LoginController : public oatpp::web::server::api::ApiController { {
class LoginController : public oatpp::web::server::api::ApiController
{
public: public:
LoginController(const model::BinaryPath& bConf, LoginController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
:oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } 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)) { ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(oatpp::Object<UserDto>, usr))
{
OATPP_LOGI("icarus", "logging in"); OATPP_LOGI("icarus", "logging in");
manager::UserManager usrMgr(m_bConf); manager::UserManager usrMgr(m_bConf);
@@ -33,8 +40,11 @@ namespace controller {
if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) { if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) {
auto logRes = dto::LoginResultDto::createShared(); auto logRes = dto::LoginResultDto::createShared();
logRes->message = "invalid credentials"; logRes->message = "invalid credentials";
std::cout << "user does not exist\n"; std::cout << "user does not exist\n";
return createDtoResponse(Status::CODE_401, logRes); return createDtoResponse(Status::CODE_401, logRes);
} }
+67 -30
View File
@@ -16,6 +16,8 @@
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/web/mime/multipart/InMemoryPartReader.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/mime/multipart/Reader.hpp"
#include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp" #include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
@@ -31,40 +33,57 @@
#include "type/SongFilter.h" #include "type/SongFilter.h"
#include "type/SongUpload.h" #include "type/SongUpload.h"
namespace fs = std::filesystem;
namespace controller { using namespace dto;
class SongController : public oatpp::web::server::api::ApiController {
namespace controller
{
class SongController : public oatpp::web::server::api::ApiController
{
public: public:
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) SongController(const model::BinaryPath& bConf,
: 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) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for uploading a song // endpoint for uploading a song
ENDPOINT("POST", "/api/v1/song/data", songUpload, ENDPOINT("POST", "/api/v1/song/data", songUpload,
//AUTHORIZATION(std::shared_ptr<oatpp::web::server::handler::DefaultBearerAuthorizationObject>, authObject), //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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::upload), Status::CODE_403, "Not allowed"); type::Scope::upload),
Status::CODE_403, "Not allowed");
auto mp = auto mp =
std::make_shared<oatpp::web::mime::multipart::Multipart> std::make_shared<oatpp::web::mime::multipart::PartList>
(request->getHeaders()); (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", mp_reader.setPartReader("file",
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize)); oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
*/
mp_reader.setDefaultPartReader(
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
request->transferBody(&mp_reader); request->transferBody(&mp_reader);
auto file = mp->getNamedPart("file"); auto file = mp->getNamedPart("file");
// auto file = mp->readNextPartSimple();
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null"); OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
@@ -78,6 +97,7 @@ namespace controller {
manager::SongManager songMgr(m_bConf); manager::SongManager songMgr(m_bConf);
const auto result = songMgr.saveSong(sng); const auto result = songMgr.saveSong(sng);
if (!result.first) { if (!result.first) {
switch (result.second) { switch (result.second) {
case type::SongUpload::AlreadyExist: case type::SongUpload::AlreadyExist:
@@ -94,22 +114,24 @@ namespace controller {
// endpoint for retrieving all song records in json format // endpoint for retrieving all song records in json format
ENDPOINT("GET", "/api/v1/song", songRecords, ENDPOINT("GET", "/api/v1/song", songRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; 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"; std::cout << "starting process of retrieving songs\n";
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
auto songsDb = songRepo.retrieveRecords(); 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 songs = oatpp::Vector<oatpp::Object<dto::SongDto>>::createShared();
// auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
std::cout << "creating object to send\n"; std::cout << "creating object to send\n";
for (auto& songDb : songsDb) { for (auto& songDb : songsDb) {
auto song = dto::conversion::DtoConversions::toSongDto(songDb); 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 for retrieving song record by the song id in json format
ENDPOINT("GET", "/api/v1/song/{id}", songRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; 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); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
@@ -144,16 +169,20 @@ namespace controller {
} }
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::download),
type::Scope::download), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -169,12 +198,13 @@ namespace controller {
} }
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate, ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
REQUEST(std::shared_ptr<IncomingRequest>, request), REQUEST(std::shared_ptr<IncomingRequest>, request),
// BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { BODY_DTO(oatpp::Object<SongDto>, songDto), PATH(Int32, id))
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::SongDto>, songDto), PATH(Int32, id)) { {
songDto->id = id; songDto->id = id;
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
@@ -183,6 +213,7 @@ namespace controller {
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto); auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
manager::SongManager songMgr(m_bConf); manager::SongManager songMgr(m_bConf);
auto result = songMgr.updateSong(updatedSong); auto result = songMgr.updateSong(updatedSong);
if (!result) { if (!result) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -192,18 +223,21 @@ namespace controller {
// endpoint to delete a song // endpoint to delete a song
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::deleteSong),
type::Scope::deleteSong), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
model::Song song(id); model::Song song(id);
manager::SongManager sngMgr(m_bConf); manager::SongManager sngMgr(m_bConf);
auto result = sngMgr.deleteSong(song); auto result = sngMgr.deleteSong(song);
if (!result) { if (!result) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -213,16 +247,19 @@ namespace controller {
// endpoint for streaming a song // endpoint for streaming a song
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::stream),
type::Scope::stream), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -246,8 +283,8 @@ namespace controller {
#include OATPP_CODEGEN_END(ApiController) #include OATPP_CODEGEN_END(ApiController)
private: private:
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
songDoesNotExist() { songDoesNotExist()
{
return createResponse(Status::CODE_404, "Song not found"); return createResponse(Status::CODE_404, "Song not found");
} }
+28 -24
View File
@@ -1,7 +1,6 @@
#ifndef YEARCONTROLLER_H_ #ifndef YEARCONTROLLER_H_
#define YEARCONTROLLER_H_ #define YEARCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -18,49 +17,52 @@
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "database/YearRepository.h" #include "database/YearRepository.h"
#include "dto/conversion/DtoConversions.h"
#include "dto/YearDto.hpp" #include "dto/YearDto.hpp"
#include "manager/TokenManager.h"
#include "manager/YearManager.h" #include "manager/YearManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/YearFilter.h" #include "type/YearFilter.h"
namespace fs = std::filesystem;
namespace controller { namespace controller
class YearController : public oatpp::web::server::api::ApiController { {
class YearController : public oatpp::web::server::api::ApiController
{
public: public:
YearController(const model::BinaryPath& bConf, YearController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } 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 for retrieving all year records in json format
ENDPOINT("GET", "/api/v1/year", yearRecords, ENDPOINT("GET", "/api/v1/year", yearRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving year\n";
database::YearRepository yrRepo(m_bConf); database::YearRepository yrRepo(m_bConf);
auto yrsDb = yrRepo.retrieveRecords(); 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(); auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
// List<dto::YearDto::ObjectWrapper>::createShared(); yearRecs->reserve(yrsDb.size());
// List<dto::YearDto>::createShared();
for (auto& yrDb : yrsDb) { for (auto &yrDb : yrsDb) {
auto yr = dto::YearDto::createShared(); auto yr = dto::conversion::DtoConversions::toYearDto(yrDb);
yr->id = yrDb.id;
yr->year = yrDb.year;
// yearRecs->pushBack(yr);
yearRecs->push_back(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 for retrieving single year record by the year id in json format
ENDPOINT("GET", "/api/v1/year/{id}", yearRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::YearRepository yrRepo(m_bConf);
model::Year yrDb(id); model::Year yrDb(id);
OATPP_ASSERT_HTTP(yrRepo.doesYearExist(yrDb, 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"; std::cout << "year exist\n";
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id); yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
auto year = dto::YearDto::createShared(); auto year = dto::conversion::DtoConversions::toYearDto(yrDb);
year->id = yrDb.id;
year->year= yrDb.year;
return createDtoResponse(Status::CODE_200, year); return createDtoResponse(Status::CODE_200, year);
} }
+80 -49
View File
@@ -1,20 +1,19 @@
#ifndef DTOCONVERSIONS_H_ #ifndef DTOCONVERSIONS_H_
#define DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_
#include <oatpp/core/data/mapping/ObjectMapper.hpp>
#include <oatpp/core/data/mapping/type/Type.hpp> #include <oatpp/core/data/mapping/type/Type.hpp>
#include <oatpp/core/data/mapping/type/Object.hpp> #include <oatpp/core/data/mapping/type/Object.hpp>
#include <oatpp/core/Types.hpp> #include <oatpp/core/Types.hpp>
#include "dto/AlbumDto.hpp" #include "dto/AlbumDto.hpp"
#include "dto/ArtistDto.hpp"
#include "dto/CoverArtDto.hpp"
#include "dto/GenreDto.hpp"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
#include "dto/SongDto.hpp" #include "dto/SongDto.hpp"
#include "dto/YearDto.hpp"
#include "model/Models.h" #include "model/Models.h"
#include "oatpp/core/data/mapping/ObjectMapper.hpp"
using model::User;
using model::Song;
using model::Token;
using model::RegisterResult;
using namespace model; using namespace model;
using namespace dto; using namespace dto;
@@ -22,41 +21,31 @@ using namespace dto;
namespace dto { namespace conversion { namespace dto { namespace conversion {
class DtoConversions { class DtoConversions {
public: public:
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&); template<typename D = oatpp::Object<LoginResultDto>>
// static oatpp::data::mapping::type::ObjectWrapper<dto::LoginResultDto> toLoginResultDto(const model::User &user, const model::Token &token)
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token)
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const User &user, const Token &token)
template<typename D = LoginResultDto>
static D toLoginResultDto(const User &user, const Token &token) static D toLoginResultDto(const User &user, const Token &token)
{ {
// const model::Token& token) {
auto logRes = LoginResultDto::createShared(); auto logRes = LoginResultDto::createShared();
/** logRes->id = (user.id != 0) ? user.id : 0;
logRes->username = user.username.c_str(); logRes->username = (!user.username.empty()) ? user.username.c_str() : "None";
logRes->token = token.accessToken.c_str(); logRes->token = (!token.accessToken.empty()) ? token.accessToken.c_str() : "None";
logRes->token_type = token.tokenType.c_str(); logRes->token_type = (!token.tokenType.empty()) ? token.tokenType.c_str() : "None";
logRes->expiration = token.expiration; logRes->expiration = (token.expiration != 0) ? token.expiration : 0;
*/
return logRes; return logRes;
} }
// static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( template<typename D = oatpp::Object<RegisterResultDto>>
template<typename D = RegisterResultDto>
static D toRegisterResultDto( static D toRegisterResultDto(
const model::RegisterResult &regRes) const model::RegisterResult &regRes)
{ {
auto result = RegisterResultDto::createShared(); auto result = RegisterResultDto::createShared();
/** result->message = (!regRes.message.empty()) ? regRes.message.c_str() : "None";
result->message = regRes.message.c_str();
result->registered = regRes.registered; result->registered = regRes.registered;
result->username = regRes.username.c_str(); result->username = (!regRes.username.empty()) ? regRes.username.c_str() : "None";
*/
return result; return result;
} }
// static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&);
template<typename D = oatpp::Object<AlbumDto>> template<typename D = oatpp::Object<AlbumDto>>
static D toAlbumDto(const Album &album) static D toAlbumDto(const Album &album)
{ {
@@ -69,11 +58,42 @@ namespace dto { namespace conversion {
return result; return result;
} }
template<typename D = SongDto> template<typename D = oatpp::Object<ArtistDto>>
static D toArtistDto(const Artist &artist)
{
auto result = ArtistDto::createShared();
result->id = (artist.id != 0) ? artist.id : 0;
result->artist = (!artist.artist.empty()) ? artist.artist.c_str() : "None";
return result;
}
template<typename D = oatpp::Object<CoverArtDto>>
static D toCoverDto(const Cover &cover)
{
auto result = CoverArtDto::createShared();
result->id = cover.id != 0 ? cover.id : 0;
result->songTitle = (!cover.songTitle.empty()) ? cover.songTitle.c_str() : "None";
return result;
}
template<typename D = oatpp::Object<GenreDto>>
static D toGenreDto(const Genre &genre)
{
auto result = GenreDto::createShared();
result->id = (genre.id != 0) ? genre.id : 0;
result->category = (!genre.category.empty()) ? genre.category.c_str() : "None";
return result;
}
template<typename D = oatpp::Object<SongDto>>
static D toSongDto(const model::Song &song) static D toSongDto(const model::Song &song)
{ {
auto result = SongDto::createShared(); auto result = SongDto::createShared();
/**
result->id = (song.id != 0) ? song.id : 0; result->id = (song.id != 0) ? song.id : 0;
result->title = (!song.title.empty()) ? song.title.c_str() : ""; result->title = (!song.title.empty()) ? song.title.c_str() : "";
result->album = (!song.album.empty()) ? song.album.c_str() : ""; result->album = (!song.album.empty()) ? song.album.c_str() : "";
@@ -85,42 +105,53 @@ namespace dto { namespace conversion {
result->track = (song.track != 0) ? song.track : 0; result->track = (song.track != 0) ? song.track : 0;
result->disc = (song.disc != 0) ? song.disc : 0; result->disc = (song.disc != 0) ? song.disc : 0;
result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0; result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0;
*/
return result; return result;
} }
// static model::Song toSong(dto::SongDto::ObjectWrapper&); template<typename D = oatpp::Object<YearDto>>
template<typename D = oatpp::Object<SongDto>, typename Song = Song> static D toYearDto(const Year &year)
static model::Song toSong(D songDto) {
auto result = YearDto::createShared();
result->id = (year.id != 0) ? year.id : 0;
result->year = (year.year != 0) ? year.year : 0;
return result;
}
template<typename D = oatpp::Object<SongDto>>
static Song toSong(const D &songDto)
{ {
Song song; Song song;
int id = songDto->id;
song.id = (songDto->id.getPtr() == nullptr) ? 0 : id;
auto title = songDto->title.get();
/** /**
song.id = (songDto.id.getPtr() == nullptr) ? 0 : songDto.id->getValue(); song.title = (songDto->title == nullptr) ? "" : songDto->title;
song.title = (songDto.title == nullptr) ? "" : songDto.title.c_str(); song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str();
song.album = (songDto.album == nullptr) ? "" : songDto.album.c_str(); song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str();
song.artist = (songDto.artist == nullptr) ? "" : songDto.artist.c_str(); song.albumArtist = (songDto->album_artist == nullptr) ?
song.albumArtist = (songDto.album_artist == nullptr) ? "" : songDto->album_artist.c_str();
"" : songDto.album_artist.c_str(); song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str();
song.genre = (songDto.genre == nullptr) ? "" : songDto.genre.c_str(); song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue();
song.year = (songDto.year.getPtr() == nullptr) ? 0 : songDto.year.getValue(); song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue();
song.track = (songDto.track.getPtr() == nullptr) ? 0 : songDto.track.getValue(); song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue();
song.disc = (songDto.disc.getPtr() == nullptr) ? 0 : songDto.disc.getValue(); song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ?
song.coverArtId = (songDto.coverart_id.getPtr() == nullptr) ? 0 : songDto->coverart_id.getValue();
0 : songDto.coverart_id.getValue(); */
*/
return song; return song;
} }
// static model::User toUser(dto::UserDto::ObjectWrapper&); template<typename D = oatpp::Object<UserDto>>
template<typename D = UserDto> static User toUser(const D &userDto)
static User toUser(D &userDto)
{ {
model::User user; User user;
int id = userDto->userId;
/** /**
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue(); user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId.getValue();
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str(); user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str(); user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str(); user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
+1 -7
View File
@@ -18,16 +18,14 @@
#include "component/AppComponent.hpp" #include "component/AppComponent.hpp"
// #include "controller/ArtistController.hpp" #include "controller/ArtistController.hpp"
#include "controller/AlbumController.hpp" #include "controller/AlbumController.hpp"
/**
#include "controller/CoverArtController.hpp" #include "controller/CoverArtController.hpp"
#include "controller/GenreController.hpp" #include "controller/GenreController.hpp"
#include "controller/LoginController.hpp" #include "controller/LoginController.hpp"
#include "controller/RegisterController.hpp" #include "controller/RegisterController.hpp"
#include "controller/SongController.hpp" #include "controller/SongController.hpp"
#include "controller/YearController.hpp" #include "controller/YearController.hpp"
*/
#include "model/Models.h" #include "model/Models.h"
#include "verify/Initialization.h" #include "verify/Initialization.h"
@@ -42,7 +40,6 @@ void run(const model::BinaryPath& bConf) {
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router); auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
auto albumController = std::make_shared<controller::AlbumController>(bConf); auto albumController = std::make_shared<controller::AlbumController>(bConf);
/**
auto artistController = std::make_shared<controller::ArtistController>(bConf); auto artistController = std::make_shared<controller::ArtistController>(bConf);
auto coverArtController = std::make_shared<controller::CoverArtController>(bConf); auto coverArtController = std::make_shared<controller::CoverArtController>(bConf);
auto gnrController = std::make_shared<controller::GenreController>(bConf); auto gnrController = std::make_shared<controller::GenreController>(bConf);
@@ -50,10 +47,8 @@ void run(const model::BinaryPath& bConf) {
auto regController = std::make_shared<controller::RegisterController>(bConf); auto regController = std::make_shared<controller::RegisterController>(bConf);
auto sngController = std::make_shared<controller::SongController>(bConf); auto sngController = std::make_shared<controller::SongController>(bConf);
auto yearController = std::make_shared<controller::YearController>(bConf); auto yearController = std::make_shared<controller::YearController>(bConf);
*/
albumController->addEndpointsToRouter(router); albumController->addEndpointsToRouter(router);
/**
artistController->addEndpointsToRouter(router); artistController->addEndpointsToRouter(router);
coverArtController->addEndpointsToRouter(router); coverArtController->addEndpointsToRouter(router);
gnrController->addEndpointsToRouter(router); gnrController->addEndpointsToRouter(router);
@@ -61,7 +56,6 @@ void run(const model::BinaryPath& bConf) {
regController->addEndpointsToRouter(router); regController->addEndpointsToRouter(router);
sngController->addEndpointsToRouter(router); sngController->addEndpointsToRouter(router);
yearController->addEndpointsToRouter(router); yearController->addEndpointsToRouter(router);
*/
// OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler); // OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);