Vcpkg migrate #64
+1
-1
@@ -15,7 +15,7 @@ set(SOURCES
|
||||
src/database/SongRepository.cpp
|
||||
src/database/UserRepository.cpp
|
||||
src/database/YearRepository.cpp
|
||||
src/dto/conversion/DtoConversions.cpp
|
||||
# src/dto/conversion/DtoConversions.cpp
|
||||
src/Main.cpp
|
||||
src/manager/AlbumManager.cpp
|
||||
src/manager/ArtistManager.cpp
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <memory>
|
||||
|
||||
#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/web/server/HttpConnectionHandler.hpp"
|
||||
|
||||
@@ -12,28 +13,37 @@ namespace component {
|
||||
class AppComponent {
|
||||
public:
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,
|
||||
serverConnectionProvider)([&] {
|
||||
return oatpp::network::server::SimpleTCPConnectionProvider::
|
||||
createShared(appPort());
|
||||
serverConnectionProvider)([&]
|
||||
{
|
||||
// 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();
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>,
|
||||
serverConnectionHandler)([] {
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>,
|
||||
serverConnectionHandler)([]
|
||||
{
|
||||
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
|
||||
|
||||
return oatpp::web::server::HttpConnectionHandler::createShared(router);
|
||||
}());
|
||||
|
||||
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>,
|
||||
apiObjectMapper)([] {
|
||||
apiObjectMapper)([]
|
||||
{
|
||||
return oatpp::parser::json::mapping::ObjectMapper::createShared();
|
||||
}());
|
||||
private:
|
||||
constexpr int appPort() noexcept { return 5002; }
|
||||
template<typename Val>
|
||||
// constexpr Val appPort() noexcept
|
||||
Val appPort() noexcept
|
||||
{
|
||||
return 5002;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "oatpp/web/mime/multipart/InMemoryPartReader.hpp"
|
||||
#include "oatpp/web/mime/multipart/Reader.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
#include "oatpp/core/Types.hpp"
|
||||
|
||||
#include "database/AlbumRepository.h"
|
||||
#include "dto/AlbumDto.hpp"
|
||||
@@ -27,68 +28,85 @@
|
||||
#include "type/AlbumFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
using namespace dto;
|
||||
|
||||
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) { }
|
||||
AlbumController(const model::BinaryPath& bConf,
|
||||
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper),
|
||||
m_bConf(bConf)
|
||||
{
|
||||
}
|
||||
|
||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||
|
||||
// endpoint for retrieving all album records in json format
|
||||
ENDPOINT("GET", "/api/v1/album", albumRecords,
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request)) {
|
||||
auto authHeader = request->getHeader("Authorization");
|
||||
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
|
||||
auto auth = authHeader->std_str();
|
||||
manager::TokenManager tok;
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
|
||||
// endpoint for retrieving all album records in json format
|
||||
ENDPOINT("GET", "/api/v1/album", albumRecords,
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
||||
{
|
||||
auto authHeader = request->getHeader("Authorization");
|
||||
|
||||
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
|
||||
|
||||
auto auth = authHeader->std_str();
|
||||
|
||||
manager::TokenManager tok;
|
||||
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
|
||||
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
|
||||
|
||||
std::cout << "starting process of retrieving album\n";
|
||||
database::AlbumRepository albRepo(m_bConf);
|
||||
auto albsDb = albRepo.retrieveRecords();
|
||||
auto albums = oatpp::data::mapping::type::
|
||||
List<dto::AlbumDto::ObjectWrapper>::createShared();
|
||||
std::cout << "starting process of retrieving album\n";
|
||||
|
||||
for (auto& albDb : albsDb) {
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
|
||||
database::AlbumRepository albRepo(m_bConf);
|
||||
|
||||
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
|
||||
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,
|
||||
for (auto& albDb : albsDb) {
|
||||
auto alb = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
|
||||
|
||||
albums->push_back(alb);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, albums);
|
||||
}
|
||||
|
||||
// endpoint for retrieving single album record by the album id in json format
|
||||
ENDPOINT("GET", "/api/v1/album/{id}", albumRecord,
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(Int32, id))
|
||||
{
|
||||
auto authHeader = request->getHeader("Authorization");
|
||||
|
||||
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
|
||||
|
||||
auto auth = authHeader->std_str();
|
||||
|
||||
manager::TokenManager tok;
|
||||
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
|
||||
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
|
||||
|
||||
database::AlbumRepository albRepo(m_bConf);
|
||||
model::Album albDb(id);
|
||||
database::AlbumRepository albRepo(m_bConf);
|
||||
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");
|
||||
|
||||
std::cout << "album exists\n";
|
||||
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id);
|
||||
std::cout << "album exists\n";
|
||||
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:
|
||||
model::BinaryPath m_bConf;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -49,15 +49,18 @@ namespace controller {
|
||||
std::cout << "starting process of retrieving artist\n";
|
||||
database::ArtistRepository artRepo(m_bConf);
|
||||
auto artsDb = artRepo.retrieveRecords();
|
||||
auto artists = oatpp::data::mapping::type::
|
||||
List<dto::ArtistDto::ObjectWrapper>::createShared();
|
||||
auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
|
||||
// List<dto::ArtistDto::ObjectWrapper>::createShared();
|
||||
|
||||
|
||||
for (auto& artDb : artsDb) {
|
||||
auto art = dto::ArtistDto::createShared();
|
||||
art->id = artDb.id;
|
||||
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);
|
||||
|
||||
@@ -48,15 +48,14 @@ namespace controller {
|
||||
std::cout << "starting process of retrieving cover art\n";
|
||||
database::CoverArtRepository covRepo(m_bConf);
|
||||
auto covsDb = covRepo.retrieveRecords();
|
||||
auto coverArts = oatpp::data::mapping::type::
|
||||
List<dto::CoverArtDto::ObjectWrapper>::createShared();
|
||||
auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::createShared();
|
||||
|
||||
for (auto& covDb : covsDb) {
|
||||
auto cov = dto::CoverArtDto::createShared();
|
||||
cov->id = covDb.id;
|
||||
cov->songTitle = covDb.songTitle.c_str();
|
||||
|
||||
coverArts->pushBack(cov);
|
||||
coverArts->push_back(cov);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, coverArts);
|
||||
|
||||
@@ -49,15 +49,14 @@ namespace controller {
|
||||
std::cout << "starting process of retrieving genre\n";
|
||||
database::GenreRepository gnrRepo(m_bConf);
|
||||
auto gnrsDb = gnrRepo.retrieveRecords();
|
||||
auto genres = oatpp::data::mapping::type::
|
||||
List<dto::GenreDto::ObjectWrapper>::createShared();
|
||||
auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::createShared();
|
||||
|
||||
for (auto& gnrDb : gnrsDb) {
|
||||
auto gnr = dto::GenreDto::createShared();
|
||||
gnr->id = gnrDb.id;
|
||||
gnr->category = gnrDb.category.c_str();
|
||||
|
||||
genres->pushBack(gnr);
|
||||
genres->push_back(gnr);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, genres);
|
||||
|
||||
@@ -23,7 +23,8 @@ namespace controller {
|
||||
#include OATPP_CODEGEN_BEGIN(ApiController)
|
||||
|
||||
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);
|
||||
auto user = dto::conversion::DtoConversions::toUser(usr);
|
||||
if (usrMgr.doesUserExist(user)) {
|
||||
|
||||
@@ -104,13 +104,16 @@ namespace controller {
|
||||
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::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);
|
||||
|
||||
songs->pushBack(song);
|
||||
songs->push_back(song);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, songs);
|
||||
@@ -167,7 +170,8 @@ 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(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
|
||||
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::SongDto>, songDto), PATH(Int32, id)) {
|
||||
songDto->id = id;
|
||||
auto authHeader = request->getHeader("Authorization");
|
||||
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
|
||||
|
||||
@@ -48,15 +48,20 @@ namespace controller {
|
||||
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();
|
||||
// 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();
|
||||
|
||||
for (auto& yrDb : yrsDb) {
|
||||
auto yr = dto::YearDto::createShared();
|
||||
yr->id = yrDb.id;
|
||||
yr->year = yrDb.year;
|
||||
|
||||
yearRecs->pushBack(yr);
|
||||
// yearRecs->pushBack(yr);
|
||||
yearRecs->push_back(yr);
|
||||
}
|
||||
|
||||
return createDtoResponse(Status::CODE_200, yearRecs);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef ALBUMDTO_H_
|
||||
#define ALBUMDTO_H_
|
||||
|
||||
#include "oatpp/core/data/mapping/type/Object.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
#include <oatpp/core/macro/codegen.hpp>
|
||||
|
||||
namespace dto {
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class AlbumDto : public oatpp::data::mapping::type::Object {
|
||||
DTO_INIT(AlbumDto, Object)
|
||||
class AlbumDto : public oatpp::DTO {
|
||||
DTO_INIT(AlbumDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
DTO_FIELD(String, title);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#ifndef 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"
|
||||
|
||||
namespace dto {
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class ArtistDto : public oatpp::data::mapping::type::Object {
|
||||
DTO_INIT(ArtistDto, Object)
|
||||
class ArtistDto : public oatpp::DTO {
|
||||
DTO_INIT(ArtistDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
DTO_FIELD(String, artist);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef COVERARTDTO_H_
|
||||
#define COVERARTDTO_H_
|
||||
|
||||
#include "oatpp/core/data/mapping/type/Object.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class CoverArtDto : public oatpp::data::mapping::type::Object {
|
||||
DTO_INIT(CoverArtDto, Object)
|
||||
class CoverArtDto : public oatpp::DTO {
|
||||
DTO_INIT(CoverArtDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
DTO_FIELD(String, songTitle);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef GENREDTO_H_
|
||||
#define GENREDTO_H_
|
||||
|
||||
#include "oatpp/core/data/mapping/type/Object.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class GenreDto : public oatpp::data::mapping::type::Object {
|
||||
DTO_INIT(GenreDto, Object)
|
||||
class GenreDto : public oatpp::DTO {
|
||||
DTO_INIT(GenreDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
DTO_FIELD(String, category);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#ifndef YEARDTO_H_
|
||||
#define YEARDTO_H_
|
||||
|
||||
#include "oatpp/core/data/mapping/type/Object.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
#include <oatpp/core/Types.hpp>
|
||||
|
||||
namespace dto {
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
class YearDto : public oatpp::data::mapping::type::Object {
|
||||
DTO_INIT(YearDto, Object)
|
||||
class YearDto : public oatpp::DTO {
|
||||
DTO_INIT(YearDto, DTO)
|
||||
|
||||
DTO_FIELD(Int32, id);
|
||||
DTO_FIELD(Int32, year);
|
||||
|
||||
@@ -1,31 +1,136 @@
|
||||
#ifndef 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/LoginResultDto.hpp"
|
||||
#include "dto/SongDto.hpp"
|
||||
#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 {
|
||||
class DtoConversions {
|
||||
public:
|
||||
// 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 toRegisterResultDto(
|
||||
const model::RegisterResult&);
|
||||
template<typename D = RegisterResultDto>
|
||||
static D toRegisterResultDto(
|
||||
const model::RegisterResult ®Res)
|
||||
{
|
||||
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 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*);
|
||||
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&);
|
||||
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
@@ -5,19 +5,29 @@
|
||||
#include <string>
|
||||
|
||||
#include <mysql/mysql.h>
|
||||
#include <oatpp/network/server/Server.hpp>
|
||||
#include "oatpp/network/server/SimpleTCPConnectionProvider.hpp"
|
||||
#include "oatpp/web/server/HttpConnectionHandler.hpp"
|
||||
// #include <oatpp/network/server/Server.hpp>
|
||||
// #include "oatpp/network/server/SimpleTCPConnectionProvider.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 "controller/ArtistController.hpp"
|
||||
// #include "controller/ArtistController.hpp"
|
||||
#include "controller/AlbumController.hpp"
|
||||
/**
|
||||
#include "controller/CoverArtController.hpp"
|
||||
#include "controller/GenreController.hpp"
|
||||
#include "controller/LoginController.hpp"
|
||||
#include "controller/RegisterController.hpp"
|
||||
#include "controller/SongController.hpp"
|
||||
#include "controller/YearController.hpp"
|
||||
*/
|
||||
#include "model/Models.h"
|
||||
#include "verify/Initialization.h"
|
||||
|
||||
@@ -26,9 +36,13 @@ namespace fs = std::filesystem;
|
||||
void run(const model::BinaryPath& bConf) {
|
||||
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 artistController = std::make_shared<controller::ArtistController>(bConf);
|
||||
auto coverArtController = std::make_shared<controller::CoverArtController>(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 sngController = std::make_shared<controller::SongController>(bConf);
|
||||
auto yearController = std::make_shared<controller::YearController>(bConf);
|
||||
*/
|
||||
|
||||
albumController->addEndpointsToRouter(router);
|
||||
/**
|
||||
artistController->addEndpointsToRouter(router);
|
||||
coverArtController->addEndpointsToRouter(router);
|
||||
gnrController->addEndpointsToRouter(router);
|
||||
@@ -45,12 +61,13 @@ void run(const model::BinaryPath& bConf) {
|
||||
regController->addEndpointsToRouter(router);
|
||||
sngController->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::network::server::Server server(connectionProvider, connectionHandler);
|
||||
oatpp::network::Server server(connectionProvider, connectionHandler);
|
||||
|
||||
OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData());
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
#include "dto/conversion/DtoConversions.h"
|
||||
|
||||
|
||||
namespace dto { namespace conversion {
|
||||
// LoginResultDto::ObjectWrapper DtoConversions::toLoginResultDto(const model::User& user,
|
||||
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;
|
||||
// dto::LoginResultDto DtoConversions::toLoginResultDto(const model::User& user,
|
||||
|
||||
return logRes;
|
||||
/**
|
||||
oatpp::data::mapping::type::DTOWrapper<dto::LoginResultDto> DtoConversions::toLoginResultDto(const model::User& user,
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto(
|
||||
/**
|
||||
dto::RegisterResultDto DtoConversions::toRegisterResultDto(
|
||||
const model::RegisterResult& regRes) {
|
||||
auto result = dto::RegisterResultDto::createShared();
|
||||
@@ -24,9 +22,11 @@ namespace dto { namespace conversion {
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) {
|
||||
/**
|
||||
dto::AlbumDto DtoConversions::toAlbumDto(const model::Album& album) {
|
||||
auto result = dto::AlbumDto::createShared();
|
||||
result->id = (album.id != 0) ? album.id : 0;
|
||||
@@ -36,9 +36,11 @@ namespace dto { namespace conversion {
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) {
|
||||
/**
|
||||
dto::SongDto DtoConversions::toSongDto(const model::Song& song) {
|
||||
auto result = dto::SongDto::createShared();
|
||||
result->id = (song.id != 0) ? song.id : 0;
|
||||
@@ -55,9 +57,11 @@ namespace dto { namespace conversion {
|
||||
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) {
|
||||
/**
|
||||
model::Song DtoConversions::toSong(dto::SongDto *songDto) {
|
||||
model::Song song;
|
||||
song.id = (songDto->id.getPtr() == nullptr) ? 0 : songDto->id->getValue();
|
||||
@@ -75,6 +79,7 @@ namespace dto { namespace conversion {
|
||||
|
||||
return song;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& userDto) {
|
||||
|
||||
Reference in New Issue
Block a user