Tidied up code, going to put up the coding convention later on
This commit is contained in:
@@ -9,35 +9,36 @@
|
||||
#include "oatpp/core/macro/component.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
|
||||
#include "dto/loginResultDto.hpp"
|
||||
#include "managers/token_manager.h"
|
||||
#include "dto/LoginResultDto.hpp"
|
||||
#include "manager/TokenManager.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:
|
||||
loginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
LoginController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), exe_path(p)
|
||||
{ }
|
||||
loginController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
LoginController(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)
|
||||
|
||||
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(Dto::userDto::ObjectWrapper, usr)) {
|
||||
ENDPOINT("POST", "/api/v1/login", data, BODY_DTO(dto::UserDto::ObjectWrapper, usr)) {
|
||||
OATPP_LOGI("icarus", "logging in");
|
||||
|
||||
Manager::token_manager tok;
|
||||
auto token = tok.retrieve_token(m_bConf);
|
||||
manager::TokenManager tok;
|
||||
auto token = tok.retrieveToken(m_bConf);
|
||||
|
||||
auto logRes = Dto::loginResultDto::createShared();
|
||||
auto logRes = dto::LoginResultDto::createShared();
|
||||
logRes->id = 0; // TODO: change this later on to something meaningful
|
||||
logRes->username = usr->username->c_str();
|
||||
logRes->token = token.access_token.c_str();
|
||||
logRes->token_type = token.token_type.c_str();
|
||||
logRes->token = token.accessToken.c_str();
|
||||
logRes->token_type = token.tokenType.c_str();
|
||||
logRes->expiration = token.expiration;
|
||||
logRes->message = "Successful";
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace Controller
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string exe_path;
|
||||
Model::BinaryPath m_bConf;
|
||||
model::BinaryPath m_bConf;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -17,26 +17,26 @@
|
||||
#include "oatpp/web/mime/multipart/Reader.hpp"
|
||||
#include "oatpp/web/server/api/ApiController.hpp"
|
||||
|
||||
#include "database/songRepository.h"
|
||||
#include "dto/songDto.hpp"
|
||||
#include "managers/song_manager.h"
|
||||
#include "managers/token_manager.h"
|
||||
#include "models/models.h"
|
||||
#include "types/scopes.h"
|
||||
#include "types/songFilter.h"
|
||||
#include "database/SongRepository.h"
|
||||
#include "dto/SongDto.hpp"
|
||||
#include "manager/SongManager.h"
|
||||
#include "manager/TokenManager.h"
|
||||
#include "model/Models.h"
|
||||
#include "type/Scopes.h"
|
||||
#include "type/SongFilter.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace Controller
|
||||
namespace controller
|
||||
{
|
||||
class songController : public oatpp::web::server::api::ApiController
|
||||
class SongController : public oatpp::web::server::api::ApiController
|
||||
{
|
||||
public:
|
||||
songController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
SongController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
|
||||
{ }
|
||||
|
||||
songController(const Model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
|
||||
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf)
|
||||
{ }
|
||||
|
||||
@@ -52,8 +52,8 @@ namespace Controller
|
||||
|
||||
auto auth = authHeader->std_str();
|
||||
|
||||
Manager::token_manager tok;
|
||||
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Type::Scope::upload), Status::CODE_403, "Not allowed");
|
||||
manager::TokenManager tok;
|
||||
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::upload), Status::CODE_403, "Not allowed");
|
||||
|
||||
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
|
||||
|
||||
@@ -72,11 +72,11 @@ namespace Controller
|
||||
|
||||
std::vector<unsigned char> data(buff.get(), buff.get() + buffSize);
|
||||
|
||||
Model::Song sng;
|
||||
model::Song sng;
|
||||
sng.data = std::move(data);
|
||||
|
||||
Manager::song_manager s_mgr(m_bConf);
|
||||
s_mgr.saveSong(sng);
|
||||
manager::SongManager songMgr(m_bConf);
|
||||
songMgr.saveSong(sng);
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
}
|
||||
@@ -86,13 +86,13 @@ namespace Controller
|
||||
REQUEST(std::shared_ptr<IncomingRequest>, request))
|
||||
{
|
||||
std::cout << "starting process of retrieving songs" << std::endl;
|
||||
Database::songRepository songRepo(m_bConf);
|
||||
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();
|
||||
|
||||
std::cout << "creating object to send" << std::endl;
|
||||
for (auto& songDb : songsDb) {
|
||||
auto song = Dto::songDto::createShared();
|
||||
auto song = dto::SongDto::createShared();
|
||||
song->id = songDb.id;
|
||||
song->title = songDb.title.c_str();
|
||||
song->artist = songDb.artist.c_str();
|
||||
@@ -113,16 +113,16 @@ namespace Controller
|
||||
ENDPOINT("GET", "/api/v1/song/{id}", songRecord,
|
||||
PATH(Int32, id)) {
|
||||
|
||||
Database::songRepository songRepo(m_bConf);
|
||||
Model::Song songDb;
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb;
|
||||
songDb.id = id;
|
||||
|
||||
OATPP_ASSERT_HTTP(songRepo.doesSongExist(songDb, Type::songFilter::id) , Status::CODE_403, "song does not exist");
|
||||
OATPP_ASSERT_HTTP(songRepo.doesSongExist(songDb, type::SongFilter::id) , Status::CODE_403, "song does not exist");
|
||||
|
||||
std::cout << "song exists" << std::endl;
|
||||
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
auto song = Dto::songDto::createShared();
|
||||
auto song = dto::SongDto::createShared();
|
||||
song->id = songDb.id;
|
||||
song->title = songDb.title.c_str();
|
||||
song->artist = songDb.artist.c_str();
|
||||
@@ -139,10 +139,10 @@ namespace Controller
|
||||
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong,
|
||||
PATH(Int32, id)) {
|
||||
|
||||
Database::songRepository songRepo(m_bConf);
|
||||
Model::Song songDb;
|
||||
database::SongRepository songRepo(m_bConf);
|
||||
model::Song songDb;
|
||||
songDb.id = id;
|
||||
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
|
||||
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
|
||||
|
||||
std::ifstream fl(songDb.songPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
|
||||
fl.seekg(0);
|
||||
@@ -165,10 +165,10 @@ namespace Controller
|
||||
|
||||
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, PATH(Int32, id)) {
|
||||
|
||||
Model::Song song;
|
||||
model::Song song;
|
||||
song.id = id;
|
||||
|
||||
Manager::song_manager sngMgr(m_bConf);
|
||||
manager::SongManager sngMgr(m_bConf);
|
||||
sngMgr.deleteSong(song);
|
||||
|
||||
return createResponse(Status::CODE_200, "OK");
|
||||
@@ -179,7 +179,7 @@ namespace Controller
|
||||
#include OATPP_CODEGEN_END(ApiController)
|
||||
private:
|
||||
std::string m_exe_path;
|
||||
Model::BinaryPath m_bConf;
|
||||
model::BinaryPath m_bConf;
|
||||
const long m_dataSize = std::numeric_limits<long long int>::max();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user