Made some more changes

This commit is contained in:
kdeng00
2020-12-19 11:51:15 -05:00
parent 8306851dcb
commit eb928d0f9e
17 changed files with 198 additions and 295 deletions
+2 -5
View File
@@ -4,7 +4,6 @@
#include <memory>
#include "oatpp/core/macro/component.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"
@@ -15,8 +14,7 @@ namespace component {
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,
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});
return oatpp::network::tcp::server::ConnectionProvider::createShared({"127.0.0.1", appPort<v_uint16>(), oatpp::network::Address::IP_4});
}());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, httpRouter)([]
@@ -39,8 +37,7 @@ namespace component {
}());
private:
template<typename Val>
// constexpr Val appPort() noexcept
Val appPort() noexcept
constexpr Val appPort() noexcept
{
return 5002;
}
-2
View File
@@ -48,8 +48,6 @@ namespace controller
return createDtoResponse(Status::CODE_401, logRes);
}
std::cout << "user exists\n";
manager::TokenManager tok;
auto token = tok.retrieveToken(m_bConf);
+18 -7
View File
@@ -6,6 +6,7 @@
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "dto/LoginResultDto.hpp"
@@ -13,20 +14,30 @@
#include "manager/UserManager.h"
#include "model/Models.h"
namespace controller {
class RegisterController : public oatpp::web::server::api::ApiController {
using namespace dto;
namespace controller
{
class RegisterController : public oatpp::web::server::api::ApiController
{
public:
RegisterController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController)
ENDPOINT("POST", "api/v1/register", registerUser,
// BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::UserDto>, usr)) {
BODY_DTO(oatpp::Object<UserDto>, usr))
{
manager::UserManager usrMgr(m_bConf);
auto user = dto::conversion::DtoConversions::toUser(usr);
auto user = conversion::DtoConversions::toUser(usr);
OATPP_LOGI("icarus", "Dto converted");
if (usrMgr.doesUserExist(user)) {
return createResponse(Status::CODE_401, "user already exists");
}
+1 -8
View File
@@ -53,7 +53,6 @@ namespace controller
// endpoint for uploading a song
ENDPOINT("POST", "/api/v1/song/data", songUpload,
//AUTHORIZATION(std::shared_ptr<oatpp::web::server::handler::DefaultBearerAuthorizationObject>, authObject),
REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization");
@@ -69,13 +68,8 @@ namespace controller
std::make_shared<oatpp::web::mime::multipart::PartList>
(request->getHeaders());
// oatpp::web::mime::multipart::Reader mp_reader(mp.get());
oatpp::web::mime::multipart::Reader mp_reader = mp.get();
/**
mp_reader.setPartReader("file",
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
*/
mp_reader.setDefaultPartReader(
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
@@ -83,7 +77,6 @@ namespace controller
request->transferBody(&mp_reader);
auto file = mp->getNamedPart("file");
// auto file = mp->readNextPartSimple();
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
@@ -266,7 +259,7 @@ namespace controller
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
auto dSize = 1024;
constexpr auto dSize = 1024;
auto callback = std::make_shared<callback::StreamCallback>(songDb.songPath);
auto db = std::make_shared<oatpp::web::protocol::http::outgoing::StreamingBody>(
+4 -2
View File
@@ -4,10 +4,12 @@
#include <oatpp/core/Types.hpp>
#include <oatpp/core/macro/codegen.hpp>
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class AlbumDto : public oatpp::DTO {
class AlbumDto : public oatpp::DTO
{
DTO_INIT(AlbumDto, DTO)
DTO_FIELD(Int32, id);
+4 -2
View File
@@ -5,10 +5,12 @@
#include "oatpp/core/Types.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class ArtistDto : public oatpp::DTO {
class ArtistDto : public oatpp::DTO
{
DTO_INIT(ArtistDto, DTO)
DTO_FIELD(Int32, id);
+4 -2
View File
@@ -4,10 +4,12 @@
#include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class CoverArtDto : public oatpp::DTO {
class CoverArtDto : public oatpp::DTO
{
DTO_INIT(CoverArtDto, DTO)
DTO_FIELD(Int32, id);
+4 -2
View File
@@ -4,10 +4,12 @@
#include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class GenreDto : public oatpp::DTO {
class GenreDto : public oatpp::DTO
{
DTO_INIT(GenreDto, DTO)
DTO_FIELD(Int32, id);
+9 -7
View File
@@ -1,17 +1,17 @@
#ifndef LOGINRESULTDTO_H_
#define LOGINRESULTDTO_H_
// #include <oatpp/core/data/mapping/type/Object.hpp>
#include <oatpp/core/Types.hpp>
#include <oatpp/core/macro/codegen.hpp>
#include <oatpp/core/Types.hpp>
#include "model/Models.h"
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
// class LoginResultDto : public oatpp::data::mapping::type::Object {
class LoginResultDto : public oatpp::DTO {
class LoginResultDto : public oatpp::DTO
{
DTO_INIT(LoginResultDto, DTO)
DTO_FIELD(oatpp::Int32, id);
@@ -22,7 +22,8 @@ namespace dto {
DTO_FIELD(oatpp::String, message);
};
class RegisterResultDto : public oatpp::DTO {
class RegisterResultDto : public oatpp::DTO
{
DTO_INIT(RegisterResultDto, DTO)
DTO_FIELD(oatpp::String, username);
@@ -30,7 +31,8 @@ namespace dto {
DTO_FIELD(oatpp::String, message);
};
class UserDto : public oatpp::DTO {
class UserDto : public oatpp::DTO
{
DTO_INIT(UserDto, DTO)
DTO_FIELD(oatpp::Int32, userId);
+4 -3
View File
@@ -2,15 +2,16 @@
#define SONGDTO_H_
#include <oatpp/core/Types.hpp>
// #include <oatpp/core/data/mapping/type/Object.hpp>
#include <oatpp/core/macro/codegen.hpp>
#include "model/Models.h"
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class SongDto : public oatpp::DTO {
class SongDto : public oatpp::DTO
{
DTO_INIT(SongDto, DTO)
DTO_FIELD(oatpp::Int32, id);
+4 -2
View File
@@ -4,10 +4,12 @@
#include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class YearDto : public oatpp::DTO {
class YearDto : public oatpp::DTO
{
DTO_INIT(YearDto, DTO)
DTO_FIELD(Int32, id);
+23 -21
View File
@@ -1,6 +1,10 @@
#ifndef DTOCONVERSIONS_H_
#define DTOCONVERSIONS_H_
#include <iostream>
#include <chrono>
#include <thread>
#include <oatpp/core/data/mapping/ObjectMapper.hpp>
#include <oatpp/core/data/mapping/type/Type.hpp>
#include <oatpp/core/data/mapping/type/Object.hpp>
@@ -18,8 +22,10 @@
using namespace model;
using namespace dto;
namespace dto { namespace conversion {
class DtoConversions {
namespace dto::conversion
{
class DtoConversions
{
public:
template<typename D = oatpp::Object<LoginResultDto>>
static D toLoginResultDto(const User &user, const Token &token)
@@ -124,22 +130,18 @@ namespace dto { namespace conversion {
static Song toSong(const D &songDto)
{
Song song;
int id = songDto->id;
song.id = (songDto->id.getPtr() == nullptr) ? 0 : id;
auto title = songDto->title.get();
/**
song.title = (songDto->title == nullptr) ? "" : songDto->title;
song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str();
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str();
song.id = (songDto->id.getPtr() == nullptr) ? 0 : *songDto->id;
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();
"" : songDto->album_artist->c_str();
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre->c_str();
song.year = (songDto->year.getPtr() == nullptr) ? 0 : *songDto->year;
song.track = (songDto->track.getPtr() == nullptr) ? 0 : *songDto->track;
song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : *songDto->disc;
song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ?
0 : songDto->coverart_id.getValue();
*/
0 : *songDto->coverart_id;
return song;
@@ -149,20 +151,20 @@ namespace dto { namespace conversion {
static User toUser(const D &userDto)
{
User user;
int id = userDto->userId;
/**
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId.getValue();
user.id = (userDto->userId.getPtr()) ? 0 : *userDto->userId;
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();
*/
std::cout << "Over\n";
return user;
}
};
}}
}
#endif
+100 -8
View File
@@ -1,22 +1,114 @@
#ifndef INITIALIZATION_H_
#define INITIALIZATION_H_
#include <iostream>
#include <filesystem>
#include <string>
#include <vector>
#include <utility>
#include "database/BaseRepository.h"
#include "manager/DirectoryManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h"
#include "type/PathType.h"
namespace verify {
class Initialization {
namespace fs = std::filesystem;
namespace verify
{
template<typename Config = model::BinaryPath>
class Initialization
{
public:
static bool skipVerification(const std::string&);
static bool skipVerification(const std::string &argument) noexcept
{
return argument.compare("--noverify") == 0;
}
static void checkIcarus(const model::BinaryPath&);
static void checkIcarus(const Config &bConf)
{
auto auth = confirmConfigAuth(bConf);
auto database = confirmConfigDatabase(bConf);
auto path = confirmConfigPaths(bConf);
if ((!auth) && (!database) && (!path)) {
failedConfirmation();
}
std::cout << "icarus check passed\n";
}
private:
static bool confirmConfigAuth(const model::BinaryPath&);
static bool confirmConfigDatabase(const model::BinaryPath&);
static bool confirmConfigPaths(const model::BinaryPath&);
static bool confirmConfigAuth(const Config &bConf)
{
manager::TokenManager tokMgr;
static void failedConfirmation();
return tokMgr.testAuth(bConf);
}
static bool confirmConfigDatabase(const Config &bConf)
{
database::BaseRepository baseRepo(bConf);
return baseRepo.testConnection();
}
static bool confirmConfigPaths(const Config &bConf)
{
using manager::DirectoryManager;
using namespace type;
auto pathConfig = DirectoryManager::pathConfigContent(bConf);
const auto musicType = PathType::music;
const auto archiveType = PathType::archive;
const auto tempRootType = PathType::temp;
const auto coverArtType = PathType::coverArt;
auto rootMusicPath =
pathConfig[DirectoryManager::retrievePathType(musicType)];
auto archiveRootPath =
pathConfig
[DirectoryManager::retrievePathType(archiveType)];
auto tempRootPath =
pathConfig
[DirectoryManager::retrievePathType(tempRootType)];
auto coverRootPath =
pathConfig
[DirectoryManager::retrievePathType(coverArtType)];
std::vector<std::string> paths;
paths.reserve(4);
paths.emplace_back(std::move(rootMusicPath));
paths.emplace_back(std::move(archiveRootPath));
paths.emplace_back(std::move(tempRootPath));
paths.emplace_back(std::move(coverRootPath));
return confirmMultiplePaths(paths);
}
static void failedConfirmation()
{
std::cout << "configuration confirmation failed. check your settings\n";
std::exit(-1);
}
template<typename Obj = std::string, typename Container = std::vector<Obj>>
static bool confirmMultiplePaths(const Container &con)
{
auto result = true;
for (auto &path : con)
{
if (!fs::exists(path))
{
std::cout << path << " is not properly configured\n";
return false;
}
}
return result;
}
};
}