Working on fixing build errors

This commit is contained in:
kdeng00
2020-12-18 14:38:46 -05:00
parent ae58b60339
commit b8caefac81
17 changed files with 272 additions and 105 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ set(SOURCES
src/database/SongRepository.cpp src/database/SongRepository.cpp
src/database/UserRepository.cpp src/database/UserRepository.cpp
src/database/YearRepository.cpp src/database/YearRepository.cpp
src/dto/conversion/DtoConversions.cpp # src/dto/conversion/DtoConversions.cpp
src/Main.cpp src/Main.cpp
src/manager/AlbumManager.cpp src/manager/AlbumManager.cpp
src/manager/ArtistManager.cpp src/manager/ArtistManager.cpp
+19 -9
View File
@@ -4,7 +4,8 @@
#include <memory> #include <memory>
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" // #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
#include "oatpp/parser/json/mapping/ObjectMapper.hpp" #include "oatpp/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/web/server/HttpConnectionHandler.hpp"
@@ -12,28 +13,37 @@ namespace component {
class AppComponent { class AppComponent {
public: public:
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,
serverConnectionProvider)([&] { serverConnectionProvider)([&]
return oatpp::network::server::SimpleTCPConnectionProvider:: {
createShared(appPort()); // return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort(), oatpp::network::Address::IP_4});
return oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", appPort<v_uint16>(), oatpp::network::Address::IP_4});
}()); }());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([] { OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([]
{
return oatpp::web::server::HttpRouter::createShared(); return oatpp::web::server::HttpRouter::createShared();
}()); }());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>,
serverConnectionHandler)([] { serverConnectionHandler)([]
{
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
return oatpp::web::server::HttpConnectionHandler::createShared(router); return oatpp::web::server::HttpConnectionHandler::createShared(router);
}()); }());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>,
apiObjectMapper)([] { apiObjectMapper)([]
{
return oatpp::parser::json::mapping::ObjectMapper::createShared(); return oatpp::parser::json::mapping::ObjectMapper::createShared();
}()); }());
private: private:
constexpr int appPort() noexcept { return 5002; } template<typename Val>
// constexpr Val appPort() noexcept
Val appPort() noexcept
{
return 5002;
}
}; };
} }
+59 -41
View File
@@ -16,6 +16,7 @@
#include "oatpp/web/mime/multipart/InMemoryPartReader.hpp" #include "oatpp/web/mime/multipart/InMemoryPartReader.hpp"
#include "oatpp/web/mime/multipart/Reader.hpp" #include "oatpp/web/mime/multipart/Reader.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/Types.hpp"
#include "database/AlbumRepository.h" #include "database/AlbumRepository.h"
#include "dto/AlbumDto.hpp" #include "dto/AlbumDto.hpp"
@@ -27,68 +28,85 @@
#include "type/AlbumFilter.h" #include "type/AlbumFilter.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
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), 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 album records in json format // endpoint for retrieving all album records in json format
ENDPOINT("GET", "/api/v1/album", albumRecords, ENDPOINT("GET", "/api/v1/album", albumRecords,
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 authHeader = request->getHeader("Authorization");
auto auth = authHeader->std_str();
manager::TokenManager tok; OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
auto auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed"); type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
std::cout << "starting process of retrieving album\n"; 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();
for (auto& albDb : albsDb) { database::AlbumRepository albRepo(m_bConf);
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
albums->pushBack(alb); auto albsDb = albRepo.retrieveRecords();
}
return createDtoResponse(Status::CODE_200, albums); auto albums = oatpp::Vector<oatpp::Object<AlbumDto>>::createShared();
} albums->reserve(albsDb.size());
// endpoint for retrieving single album record by the album id in json format for (auto& albDb : albsDb) {
ENDPOINT("GET", "/api/v1/album/{id}", albumRecord, auto alb = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(Int32, id)) {
auto authHeader = request->getHeader("Authorization"); albums->push_back(alb);
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); }
auto auth = authHeader->std_str();
manager::TokenManager tok; return createDtoResponse(Status::CODE_200, albums);
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, }
// 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"); type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
database::AlbumRepository albRepo(m_bConf); database::AlbumRepository albRepo(m_bConf);
model::Album albDb(id); model::Album albDb(id);
OATPP_ASSERT_HTTP(albRepo.doesAlbumExists(albDb, OATPP_ASSERT_HTTP(albRepo.doesAlbumExists(albDb,
type::AlbumFilter::id) , Status::CODE_403, "album does not exist"); type::AlbumFilter::id) , Status::CODE_403, "album does not exist");
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(albDb); auto album = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
return createDtoResponse(Status::CODE_200, album); return createDtoResponse(Status::CODE_200, album);
} }
#include OATPP_CODEGEN_END(ApiController) #include OATPP_CODEGEN_END(ApiController)
private: private:
model::BinaryPath m_bConf; model::BinaryPath m_bConf;
}; };
} }
#endif #endif
+6 -3
View File
@@ -49,15 +49,18 @@ namespace controller {
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::data::mapping::type:: auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
List<dto::ArtistDto::ObjectWrapper>::createShared(); // List<dto::ArtistDto::ObjectWrapper>::createShared();
for (auto& artDb : artsDb) { for (auto& artDb : artsDb) {
auto art = dto::ArtistDto::createShared(); auto art = dto::ArtistDto::createShared();
art->id = artDb.id; art->id = artDb.id;
art->artist = artDb.artist.c_str(); art->artist = artDb.artist.c_str();
artists->pushBack(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);
+2 -3
View File
@@ -48,15 +48,14 @@ namespace controller {
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::data::mapping::type:: auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::createShared();
List<dto::CoverArtDto::ObjectWrapper>::createShared();
for (auto& covDb : covsDb) { for (auto& covDb : covsDb) {
auto cov = dto::CoverArtDto::createShared(); auto cov = dto::CoverArtDto::createShared();
cov->id = covDb.id; cov->id = covDb.id;
cov->songTitle = covDb.songTitle.c_str(); cov->songTitle = covDb.songTitle.c_str();
coverArts->pushBack(cov); coverArts->push_back(cov);
} }
return createDtoResponse(Status::CODE_200, coverArts); return createDtoResponse(Status::CODE_200, coverArts);
+2 -3
View File
@@ -49,15 +49,14 @@ namespace controller {
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::data::mapping::type:: auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::createShared();
List<dto::GenreDto::ObjectWrapper>::createShared();
for (auto& gnrDb : gnrsDb) { for (auto& gnrDb : gnrsDb) {
auto gnr = dto::GenreDto::createShared(); auto gnr = dto::GenreDto::createShared();
gnr->id = gnrDb.id; gnr->id = gnrDb.id;
gnr->category = gnrDb.category.c_str(); gnr->category = gnrDb.category.c_str();
genres->pushBack(gnr); genres->push_back(gnr);
} }
return createDtoResponse(Status::CODE_200, genres); return createDtoResponse(Status::CODE_200, genres);
+2 -1
View File
@@ -23,7 +23,8 @@ namespace controller {
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
ENDPOINT("POST", "api/v1/register", registerUser, ENDPOINT("POST", "api/v1/register", registerUser,
BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { // BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::UserDto>, usr)) {
manager::UserManager usrMgr(m_bConf); manager::UserManager usrMgr(m_bConf);
auto user = dto::conversion::DtoConversions::toUser(usr); auto user = dto::conversion::DtoConversions::toUser(usr);
if (usrMgr.doesUserExist(user)) { if (usrMgr.doesUserExist(user)) {
+7 -3
View File
@@ -104,13 +104,16 @@ namespace controller {
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::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"; 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);
songs->pushBack(song); songs->push_back(song);
} }
return createDtoResponse(Status::CODE_200, songs); return createDtoResponse(Status::CODE_200, songs);
@@ -167,7 +170,8 @@ 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(dto::SongDto::ObjectWrapper, 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");
+8 -3
View File
@@ -48,15 +48,20 @@ namespace controller {
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:: // auto yearRecs = oatpp::data::mapping::type::
List<dto::YearDto::ObjectWrapper>::createShared(); // 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();
for (auto& yrDb : yrsDb) { for (auto& yrDb : yrsDb) {
auto yr = dto::YearDto::createShared(); auto yr = dto::YearDto::createShared();
yr->id = yrDb.id; yr->id = yrDb.id;
yr->year = yrDb.year; yr->year = yrDb.year;
yearRecs->pushBack(yr); // yearRecs->pushBack(yr);
yearRecs->push_back(yr);
} }
return createDtoResponse(Status::CODE_200, yearRecs); return createDtoResponse(Status::CODE_200, yearRecs);
+4 -4
View File
@@ -1,14 +1,14 @@
#ifndef ALBUMDTO_H_ #ifndef ALBUMDTO_H_
#define ALBUMDTO_H_ #define ALBUMDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp" #include <oatpp/core/Types.hpp>
#include "oatpp/core/macro/codegen.hpp" #include <oatpp/core/macro/codegen.hpp>
namespace dto { namespace dto {
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class AlbumDto : public oatpp::data::mapping::type::Object { class AlbumDto : public oatpp::DTO {
DTO_INIT(AlbumDto, Object) DTO_INIT(AlbumDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, title); DTO_FIELD(String, title);
+4 -3
View File
@@ -1,14 +1,15 @@
#ifndef ARTISTDTO_H_ #ifndef ARTISTDTO_H_
#define ARTISTDTO_H_ #define ARTISTDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp" // #include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
namespace dto { namespace dto {
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class ArtistDto : public oatpp::data::mapping::type::Object { class ArtistDto : public oatpp::DTO {
DTO_INIT(ArtistDto, Object) DTO_INIT(ArtistDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, artist); DTO_FIELD(String, artist);
+3 -3
View File
@@ -1,14 +1,14 @@
#ifndef COVERARTDTO_H_ #ifndef COVERARTDTO_H_
#define COVERARTDTO_H_ #define COVERARTDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto {
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class CoverArtDto : public oatpp::data::mapping::type::Object { class CoverArtDto : public oatpp::DTO {
DTO_INIT(CoverArtDto, Object) DTO_INIT(CoverArtDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, songTitle); DTO_FIELD(String, songTitle);
+3 -3
View File
@@ -1,14 +1,14 @@
#ifndef GENREDTO_H_ #ifndef GENREDTO_H_
#define GENREDTO_H_ #define GENREDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto {
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class GenreDto : public oatpp::data::mapping::type::Object { class GenreDto : public oatpp::DTO {
DTO_INIT(GenreDto, Object) DTO_INIT(GenreDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, category); DTO_FIELD(String, category);
+3 -3
View File
@@ -1,14 +1,14 @@
#ifndef YEARDTO_H_ #ifndef YEARDTO_H_
#define YEARDTO_H_ #define YEARDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto {
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class YearDto : public oatpp::data::mapping::type::Object { class YearDto : public oatpp::DTO {
DTO_INIT(YearDto, Object) DTO_INIT(YearDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(Int32, year); DTO_FIELD(Int32, year);
+112 -7
View File
@@ -1,31 +1,136 @@
#ifndef DTOCONVERSIONS_H_ #ifndef DTOCONVERSIONS_H_
#define DTOCONVERSIONS_H_ #define DTOCONVERSIONS_H_
#include <oatpp/core/data/mapping/type/Type.hpp>
#include <oatpp/core/data/mapping/type/Object.hpp>
#include <oatpp/core/Types.hpp>
#include "dto/AlbumDto.hpp" #include "dto/AlbumDto.hpp"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
#include "dto/SongDto.hpp" #include "dto/SongDto.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 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&); // static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&);
static dto::LoginResultDto toLoginResultDto(const model::User&, const model::Token&); // 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)
{
// const model::Token& token) {
auto logRes = LoginResultDto::createShared();
/**
logRes->username = user.username.c_str();
logRes->token = token.accessToken.c_str();
logRes->token_type = token.tokenType.c_str();
logRes->expiration = token.expiration;
*/
return logRes;
}
// static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto( // static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto(
static dto::RegisterResultDto toRegisterResultDto( template<typename D = RegisterResultDto>
const model::RegisterResult&); static D toRegisterResultDto(
const model::RegisterResult &regRes)
{
auto result = RegisterResultDto::createShared();
/**
result->message = regRes.message.c_str();
result->registered = regRes.registered;
result->username = regRes.username.c_str();
*/
return result;
}
// static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&); // static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&);
static dto::AlbumDto toAlbumDto(const model::Album&); template<typename D = oatpp::Object<AlbumDto>>
static D toAlbumDto(const Album &album)
{
auto result = AlbumDto::createShared();
result->id = (album.id != 0) ? album.id : 0;
result->title = (!album.title.empty()) ? album.title.c_str() : "";
result->artist = (!album.artist.empty()) ? album.artist.c_str() : "";
result->year = (album.year != 0) ? album.year : 0;
static dto::SongDto toSongDto(const model::Song&); return result;
}
template<typename D = SongDto>
static D toSongDto(const model::Song &song)
{
auto result = SongDto::createShared();
/**
result->id = (song.id != 0) ? song.id : 0;
result->title = (!song.title.empty()) ? song.title.c_str() : "";
result->album = (!song.album.empty()) ? song.album.c_str() : "";
result->artist = (!song.artist.empty()) ? song.artist.c_str() : "";
result->album_artist = (!song.albumArtist.empty()) ? song.albumArtist.c_str() : "";
result->genre = (!song.genre.empty()) ? song.genre.c_str() : "";
result->duration = (song.duration != 0) ? song.duration : 0;
result->year = (song.year != 0) ? song.year : 0;
result->track = (song.track != 0) ? song.track : 0;
result->disc = (song.disc != 0) ? song.disc : 0;
result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0;
*/
return result;
}
// static model::Song toSong(dto::SongDto::ObjectWrapper&); // static model::Song toSong(dto::SongDto::ObjectWrapper&);
static model::Song toSong(dto::SongDto*); template<typename D = oatpp::Object<SongDto>, typename Song = Song>
static model::Song toSong(D songDto)
{
Song song;
/**
song.id = (songDto.id.getPtr() == nullptr) ? 0 : songDto.id->getValue();
song.title = (songDto.title == nullptr) ? "" : songDto.title.c_str();
song.album = (songDto.album == nullptr) ? "" : songDto.album.c_str();
song.artist = (songDto.artist == nullptr) ? "" : songDto.artist.c_str();
song.albumArtist = (songDto.album_artist == nullptr) ?
"" : songDto.album_artist.c_str();
song.genre = (songDto.genre == nullptr) ? "" : songDto.genre.c_str();
song.year = (songDto.year.getPtr() == nullptr) ? 0 : songDto.year.getValue();
song.track = (songDto.track.getPtr() == nullptr) ? 0 : songDto.track.getValue();
song.disc = (songDto.disc.getPtr() == nullptr) ? 0 : songDto.disc.getValue();
song.coverArtId = (songDto.coverart_id.getPtr() == nullptr) ?
0 : songDto.coverart_id.getValue();
*/
return song;
}
// static model::User toUser(dto::UserDto::ObjectWrapper&); // static model::User toUser(dto::UserDto::ObjectWrapper&);
static model::User toUser(dto::UserDto&); template<typename D = UserDto>
static User toUser(D &userDto)
{
model::User user;
/**
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue();
user.firstname = (userDto->firstname == nullptr) ? "" : userDto->firstname->c_str();
user.lastname = (userDto->lastname == nullptr) ? "" : userDto->lastname->c_str();
user.phone = (userDto->phone == nullptr) ? "" : userDto->phone->c_str();
user.email = (userDto->email == nullptr) ? "" : userDto->email->c_str();
user.username = (userDto->username == nullptr) ? "" : userDto->username->c_str();
user.password = (userDto->password == nullptr) ? "" : userDto->password->c_str();
*/
return user;
}
}; };
}} }}
+24 -7
View File
@@ -5,19 +5,29 @@
#include <string> #include <string>
#include <mysql/mysql.h> #include <mysql/mysql.h>
#include <oatpp/network/server/Server.hpp> // #include <oatpp/network/server/Server.hpp>
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp" // #include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
#include "oatpp/web/server/HttpConnectionHandler.hpp" // #include "oatpp/web/server/HttpConnectionHandler.hpp"
#include <oatpp/web/server/HttpConnectionHandler.hpp>
// #include <oatpp/network/Server.hpp>
#include <oatpp/network/Server.hpp>
// #include <oatpp/network/server/SimpleTCPConnectionProvider.hpp>
#include <oatpp/network/tcp/server/ConnectionProvider.hpp>
#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"
@@ -26,9 +36,13 @@ namespace fs = std::filesystem;
void run(const model::BinaryPath& bConf) { void run(const model::BinaryPath& bConf) {
component::AppComponent component; component::AppComponent component;
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); // OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
auto router = oatpp::web::server::HttpRouter::createShared();
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);
@@ -36,8 +50,10 @@ 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);
@@ -45,12 +61,13 @@ 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);
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider); OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
oatpp::network::server::Server server(connectionProvider, connectionHandler); oatpp::network::Server server(connectionProvider, connectionHandler);
OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData()); OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData());
+13 -8
View File
@@ -1,20 +1,18 @@
#include "dto/conversion/DtoConversions.h" #include "dto/conversion/DtoConversions.h"
namespace dto { namespace conversion { namespace dto { namespace conversion {
// LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user, // LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user,
LoginResultDto DtoConversions::toLoginResultDto(const model::User& user, // dto::LoginResultDto DtoConversions::toLoginResultDto(const model::User& user,
const model::Token& token) {
auto logRes = dto::LoginResultDto::createShared();
logRes->username = user.username.c_str();
logRes->token = token.accessToken.c_str();
logRes->token_type = token.tokenType.c_str();
logRes->expiration = token.expiration;
return logRes; /**
oatpp::data::mapping::type::DTOWrapper<dto::LoginResultDto> DtoConversions::toLoginResultDto(const model::User& user,
} }
*/
// dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto( // dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto(
/**
dto::RegisterResultDto DtoConversions::toRegisterResultDto( dto::RegisterResultDto DtoConversions::toRegisterResultDto(
const model::RegisterResult& regRes) { const model::RegisterResult& regRes) {
auto result = dto::RegisterResultDto::createShared(); auto result = dto::RegisterResultDto::createShared();
@@ -24,9 +22,11 @@ namespace dto { namespace conversion {
return result; return result;
} }
*/
// dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) { // dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) {
/**
dto::AlbumDto DtoConversions::toAlbumDto(const model::Album& album) { dto::AlbumDto DtoConversions::toAlbumDto(const model::Album& album) {
auto result = dto::AlbumDto::createShared(); auto result = dto::AlbumDto::createShared();
result->id = (album.id != 0) ? album.id : 0; result->id = (album.id != 0) ? album.id : 0;
@@ -36,9 +36,11 @@ namespace dto { namespace conversion {
return result; return result;
} }
*/
// dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) { // dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) {
/**
dto::SongDto DtoConversions::toSongDto(const model::Song& song) { dto::SongDto DtoConversions::toSongDto(const model::Song& song) {
auto result = dto::SongDto::createShared(); auto result = dto::SongDto::createShared();
result->id = (song.id != 0) ? song.id : 0; result->id = (song.id != 0) ? song.id : 0;
@@ -55,9 +57,11 @@ namespace dto { namespace conversion {
return result; return result;
} }
*/
// model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) { // model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) {
/**
model::Song DtoConversions::toSong(dto::SongDto *songDto) { model::Song DtoConversions::toSong(dto::SongDto *songDto) {
model::Song song; model::Song song;
song.id = (songDto->id.getPtr() == nullptr) ? 0 : songDto->id->getValue(); song.id = (songDto->id.getPtr() == nullptr) ? 0 : songDto->id->getValue();
@@ -75,6 +79,7 @@ namespace dto { namespace conversion {
return song; return song;
} }
*/
// model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) { // model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) {