Vcpkg migrate #64

Merged
kdeng00 merged 10 commits from vcpkg_migrate into master 2020-12-19 11:56:35 -05:00
34 changed files with 707 additions and 626 deletions
+3 -12
View File
@@ -1,21 +1,12 @@
[submodule "Libs/cpr"]
path = 3rdparty/cpr
url = https://github.com/whoshuu/cpr.git
[submodule "3rdparty/taglib"]
path = 3rdparty/taglib
url = https://github.com/taglib/taglib
[submodule "3rdparty/oatpp"]
path = 3rdparty/oatpp
url = https://github.com/oatpp/oatpp
[submodule "build/3rdparty/jwt-cpp"]
path = build/3rdparty/jwt-cpp
url = https://github.com/Thalhammer/jwt-cpp
[submodule "3rdparty/jwt-cpp"]
path = 3rdparty/jwt-cpp
url = https://github.com/Thalhammer/jwt-cpp
[submodule "3rdparty/ormpp"]
path = 3rdparty/ormpp
url = https://github.com/qicosmos/ormpp
[submodule "3rdparty/libbcrypt"]
path = 3rdparty/libbcrypt
url = https://github.com/rg3/libbcrypt
[submodule "3rdparty/vcpkg"]
path = 3rdparty/vcpkg
url = https://github.com/microsoft/vcpkg
-1
Submodule 3rdparty/cpr deleted from 07d784ccfe
-1
Submodule 3rdparty/jwt-cpp deleted from 65b632b674
-1
Submodule 3rdparty/oatpp deleted from 27c46444db
-1
Submodule 3rdparty/taglib deleted from e36a9cabb9
Vendored Submodule
+1
Submodule 3rdparty/vcpkg added at ec6fe06e8d
+19 -97
View File
@@ -5,6 +5,8 @@ project(icarus)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(SOURCES
src/callback/StreamCallback.cpp
src/database/AlbumRepository.cpp
@@ -15,7 +17,6 @@ set(SOURCES
src/database/SongRepository.cpp
src/database/UserRepository.cpp
src/database/YearRepository.cpp
src/dto/conversion/DtoConversions.cpp
src/Main.cpp
src/manager/AlbumManager.cpp
src/manager/ArtistManager.cpp
@@ -29,111 +30,22 @@ set(SOURCES
src/utility/ImageFile.cpp
src/utility/MetadataRetriever.cpp
src/utility/PasswordEncryption.cpp
src/verify/Initialization.cpp
)
set(HEADERS
include/callback/StreamCallback.h
include/component/AppComponent.hpp
include/controller/AlbumController.hpp
include/controller/ArtistController.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/database/AlbumRepository.h
include/database/ArtistRepository.h
include/database/BaseRepository.h
include/database/CoverArtRepository.h
include/database/GenreRepository.h
include/database/SongRepository.h
include/database/UserRepository.h
include/database/YearRepository.h
include/dto/AlbumDto.hpp
include/dto/ArtistDto.hpp
include/dto/CoverArtDto.hpp
include/dto/GenreDto.hpp
include/dto/LoginResultDto.hpp
include/dto/SongDto.hpp
include/dto/YearDto.hpp
include/dto/conversion/DtoConversions.h
include/manager/AlbumManager.h
include/manager/ArtistManager.h
include/manager/CoverArtManager.h
include/manager/DirectoryManager.h
include/manager/GenreManager.h
include/manager/SongManager.h
include/manager/TokenManager.h
include/manager/UserManager.h
include/manager/YearManager.h
include/model/Models.h
include/utility/ImageFile.h
include/utility/MetadataRetriever.h
include/utility/PasswordEncryption.h
include/type/AlbumFilter.h
include/type/ArtistFilter.h
include/type/CoverFilter.h
include/type/GenreFilter.h
include/type/PathType.h
include/type/SaltFilter.h
include/type/Scopes.h
include/type/SongChanged.h
include/type/SongFilter.h
include/type/SongUpload.h
include/type/UserFilter.h
include/type/YearFilter.h
include/verify/Initialization.h
)
set (TAGLIB
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib/3rdparty
set(ICARUS_INCLUDE_DIR
"${CMAKE_CURRENT_SOURCE_DIR}/include"
)
set (BCRYPTLIB
${CMAKE_SOURCE_DIR}/3rdparty/libbcrypt
)
set(TAGLIB_HEADERS
"${CMAKE_SOURCE_DIR}/build/3rdparty/taglib"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/ape"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/asf"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/dsdiff"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/dsf"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/flac"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/it"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mod"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mp4"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpc"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg/id3v2"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/mpeg/id3v2/frames"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/ogg"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/riff"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/s3m"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/toolkit"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/trueaudio"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/wavpack"
"${CMAKE_SOURCE_DIR}/3rdparty/taglib/taglib/xm"
)
set(JWT_CPP_INCLUDE
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/jwt-cpp/include
)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
#find_library(BCRYPT bcrypt ${BCRYPTLIB})
include_directories(include ${CPR_INCLUDE_DIRS} ${TAGLIB} ${TAGLIB_HEADERS} ${BCRYPTLIB})
include_directories(${ICARUS_INCLUDE_DIR} ${BCRYPTLIB})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/cpr)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/taglib)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/oatpp)
add_library(bcrypt STATIC IMPORTED)
@@ -147,6 +59,16 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/database.json ${CMAKE_BINARY_DIR}/bin
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/paths.json ${CMAKE_BINARY_DIR}/bin/paths.json COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Images/Stock/CoverArt.png ${CMAKE_BINARY_DIR}/bin/CoverArt.png COPYONLY)
add_executable(icarus ${SOURCES} ${HEADERS})
target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE})
target_link_libraries(icarus "-lstdc++fs" tag oatpp mysqlclient ${CONAN_LIBS} ${CPR_LIBRARIES} bcrypt)
find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h")
find_package(nlohmann_json CONFIG REQUIRED)
find_package(cpr CONFIG REQUIRED)
find_package(oatpp CONFIG REQUIRED)
add_executable(icarus ${SOURCES})
target_include_directories(icarus PRIVATE ${JWT_CPP_INCLUDE_DIRS})
target_link_libraries(icarus PRIVATE "-lstdc++fs" oatpp::oatpp tag mariadb nlohmann_json nlohmann_json::nlohmann_json cpr bcrypt)
+9 -3
View File
@@ -21,6 +21,7 @@ One can interface with Icarus the music server either by:
* [cpr](https://www.github.com/whoshuu/cpr)
* [TagLib](https://github.com/taglib/taglib)
* [jwt-cpp](https://github.com/Thalhammer/jwt-cpp)
* libmariadb
* [libbcrypt](https://github.com/rg3/libbcrypt)
* [oatpp](https://github.com/oatpp/oatpp)
@@ -149,14 +150,19 @@ From this point the database has been successfully created. Metadata and song fi
## Building and Running
```
git clone --recursive https://github.com/kdeng00/icarus
cd 3rdparty/libbcrypt/
cd icarus/3rdparty/vcpkg
./bootstrap-vcpkg.sh
./vcpkg install nlohmann-json cpr taglib jwt-cpp libmariadb
cd ../3rdparty/libbcrypt/
make
cd ../..
mkdir build
cd build
conan install ..
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SYSTEM_CURL=ON -DBUILD_CPR_TESTS=OFF -DOATPP_BUILD_TESTS=OFF
make
cmake --build .
bin/icarus
```
Runs the server on localhost port 5002
-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
-5
View File
@@ -1,5 +0,0 @@
[requires]
jsonformoderncpp/3.7.3@vthiery/stable
[generators]
cmake
+16 -9
View File
@@ -4,7 +4,7 @@
#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"
@@ -12,28 +12,35 @@ 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({"127.0.0.1", 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
{
return 5002;
}
};
}
+63 -45
View File
@@ -1,7 +1,6 @@
#ifndef ALBUMCONTROLLER_H_
#define ALBUMCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -16,6 +15,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"
@@ -26,69 +26,87 @@
#include "type/Scopes.h"
#include "type/AlbumFilter.h"
namespace fs = std::filesystem;
using namespace dto;
namespace controller {
class AlbumController : public oatpp::web::server::api::ApiController {
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(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(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
+32 -17
View File
@@ -19,6 +19,7 @@
#include "database/ArtistRepository.h"
#include "dto/ArtistDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/ArtistManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h"
@@ -27,37 +28,47 @@
namespace fs = std::filesystem;
namespace controller {
class ArtistController : public oatpp::web::server::api::ApiController {
namespace controller
{
class ArtistController : public oatpp::web::server::api::ApiController
{
public:
ArtistController(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 for retrieving all artist records in json format
ENDPOINT("GET", "/api/v1/artist", artistRecords,
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 auth = authHeader->std_str();
manager::TokenManager tok;
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";
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();
artists->reserve(artsDb.size());
for (auto& artDb : artsDb) {
auto art = dto::ArtistDto::createShared();
art->id = artDb.id;
art->artist = artDb.artist.c_str();
auto art = dto::conversion::DtoConversions::toArtistDto(artDb);
artists->pushBack(art);
artists->push_back(art);
}
return createDtoResponse(Status::CODE_200, artists);
@@ -65,13 +76,18 @@ namespace controller {
// endpoint for retrieving single artist record by the artist id in json format
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
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);
model::Artist artDb(id);
@@ -80,11 +96,10 @@ namespace controller {
type::ArtistFilter::id) , Status::CODE_403, "artist does not exist");
std::cout << "artist exist\n";
artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id);
auto artist = dto::ArtistDto::createShared();
artist->id = artDb.id;
artist->artist = artDb.artist.c_str();
auto artist = dto::conversion::DtoConversions::toArtistDto(artDb);
return createDtoResponse(Status::CODE_200, artist);
}
+34 -22
View File
@@ -1,7 +1,6 @@
#ifndef COVERARTCONTROLLER_H_
#define COVERARTCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -19,44 +18,51 @@
#include "database/CoverArtRepository.h"
#include "dto/CoverArtDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/CoverArtManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h"
#include "type/Scopes.h"
#include "type/CoverFilter.h"
namespace fs = std::filesystem;
namespace controller {
class CoverArtController : public oatpp::web::server::api::ApiController {
namespace controller
{
class CoverArtController : public oatpp::web::server::api::ApiController
{
public:
CoverArtController(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 for retrieving all cover art records in json format
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
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 auth = authHeader->std_str();
manager::TokenManager tok;
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";
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();
coverArts->reserve(covsDb.size());
for (auto& covDb : covsDb) {
auto cov = dto::CoverArtDto::createShared();
cov->id = covDb.id;
cov->songTitle = covDb.songTitle.c_str();
auto cov = dto::conversion::DtoConversions::toCoverDto(covDb);
coverArts->pushBack(cov);
coverArts->push_back(cov);
}
return createDtoResponse(Status::CODE_200, coverArts);
@@ -64,39 +70,45 @@ namespace controller {
// endpoint for retrieving single cover art record by the cover art id in json format
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
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);
model::Cover covDb;
covDb.id = id;
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";
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
auto coverArt = dto::CoverArtDto::createShared();
coverArt->id = covDb.id;
coverArt->songTitle = covDb.songTitle.c_str();
auto coverArt = dto::conversion::DtoConversions::toCoverDto(covDb);
return createDtoResponse(Status::CODE_200, coverArt);
}
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
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);
model::Cover covDb;
+23 -18
View File
@@ -1,7 +1,6 @@
#ifndef GENRECONTROLLER_H_
#define GENRECONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -19,45 +18,51 @@
#include "database/GenreRepository.h"
#include "dto/GenreDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/GenreManager.h"
#include "manager/TokenManager.h"
#include "manager/YearManager.h"
#include "model/Models.h"
#include "type/Scopes.h"
#include "type/GenreFilter.h"
namespace fs = std::filesystem;
namespace controller {
class GenreController : public oatpp::web::server::api::ApiController {
namespace controller
{
class GenreController : public oatpp::web::server::api::ApiController
{
public:
GenreController(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 for retrieving all genre records in json format
ENDPOINT("GET", "/api/v1/genre", genreRecords,
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 auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveGenre), Status::CODE_403, "Not allowed");
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();
genres->reserve(gnrsDb.size());
for (auto& gnrDb : gnrsDb) {
auto gnr = dto::GenreDto::createShared();
gnr->id = gnrDb.id;
gnr->category = gnrDb.category.c_str();
auto gnr = dto::conversion::DtoConversions::toGenreDto(gnrDb);
genres->pushBack(gnr);
genres->push_back(gnr);
}
return createDtoResponse(Status::CODE_200, genres);
@@ -65,9 +70,11 @@ namespace controller {
// endpoint for retrieving single genre record by the genre id in json format
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
@@ -82,9 +89,7 @@ namespace controller {
std::cout << "genre exist\n";
gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id);
auto genre = dto::GenreDto::createShared();
genre->id = gnrDb.id;
genre->category= gnrDb.category.c_str();
auto genre = dto::conversion::DtoConversions::toGenreDto(gnrDb);
return createDtoResponse(Status::CODE_200, genre);
}
+15 -7
View File
@@ -9,23 +9,30 @@
#include "oatpp/core/macro/component.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "dto/conversion/DtoConversions.h"
#include "dto/LoginResultDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/TokenManager.h"
#include "manager/UserManager.h"
#include "model/Models.h"
namespace controller {
class LoginController : public oatpp::web::server::api::ApiController {
namespace controller
{
class LoginController : public oatpp::web::server::api::ApiController
{
public:
LoginController(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/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");
manager::UserManager usrMgr(m_bConf);
@@ -33,13 +40,14 @@ namespace controller {
if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) {
auto logRes = dto::LoginResultDto::createShared();
logRes->message = "invalid credentials";
std::cout << "user does not exist\n";
return createDtoResponse(Status::CODE_401, logRes);
}
std::cout << "user exists\n";
manager::TokenManager tok;
auto token = tok.retrieveToken(m_bConf);
+18 -6
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,19 +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::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");
}
+67 -33
View File
@@ -16,6 +16,8 @@
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.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/protocol/http/outgoing/StreamingBody.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
@@ -31,36 +33,46 @@
#include "type/SongFilter.h"
#include "type/SongUpload.h"
namespace fs = std::filesystem;
namespace controller {
class SongController : public oatpp::web::server::api::ApiController {
using namespace dto;
namespace controller
{
class SongController : public oatpp::web::server::api::ApiController
{
public:
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { }
SongController(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 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)) {
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::upload), Status::CODE_403, "Not allowed");
type::Scope::upload),
Status::CODE_403, "Not allowed");
auto mp =
std::make_shared<oatpp::web::mime::multipart::Multipart>
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.setDefaultPartReader(
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
mp_reader.setPartReader("file",
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
request->transferBody(&mp_reader);
@@ -78,6 +90,7 @@ namespace controller {
manager::SongManager songMgr(m_bConf);
const auto result = songMgr.saveSong(sng);
if (!result.first) {
switch (result.second) {
case type::SongUpload::AlreadyExist:
@@ -94,23 +107,28 @@ namespace controller {
// endpoint for retrieving all song records in json format
ENDPOINT("GET", "/api/v1/song", songRecords,
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 auth = authHeader->std_str();
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";
database::SongRepository songRepo(m_bConf);
auto songsDb = songRepo.retrieveRecords();
auto songs = oatpp::data::mapping::type::List<dto::SongDto::ObjectWrapper>::createShared();
auto songs = oatpp::Vector<oatpp::Object<dto::SongDto>>::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);
@@ -118,12 +136,15 @@ namespace controller {
// endpoint for retrieving song record by the song id in json format
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
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);
model::Song songDb(id);
@@ -141,16 +162,20 @@ namespace controller {
}
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::download), Status::CODE_403, "Not allowed");
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::download),
Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf);
model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist();
}
@@ -166,11 +191,13 @@ namespace controller {
}
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
REQUEST(std::shared_ptr<IncomingRequest>, request),
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) {
REQUEST(std::shared_ptr<IncomingRequest>, request),
BODY_DTO(oatpp::Object<SongDto>, songDto), PATH(Int32, id))
{
songDto->id = 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,
@@ -179,6 +206,7 @@ namespace controller {
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
manager::SongManager songMgr(m_bConf);
auto result = songMgr.updateSong(updatedSong);
if (!result) {
return songDoesNotExist();
}
@@ -188,18 +216,21 @@ namespace controller {
// endpoint to delete a song
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::deleteSong), Status::CODE_403, "Not allowed");
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::deleteSong),
Status::CODE_403, "Not allowed");
model::Song song(id);
manager::SongManager sngMgr(m_bConf);
auto result = sngMgr.deleteSong(song);
if (!result) {
return songDoesNotExist();
}
@@ -209,23 +240,26 @@ namespace controller {
// endpoint for streaming a song
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::stream), Status::CODE_403, "Not allowed");
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::stream),
Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf);
model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist();
}
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>(
@@ -242,8 +276,8 @@ namespace controller {
#include OATPP_CODEGEN_END(ApiController)
private:
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
songDoesNotExist() {
songDoesNotExist()
{
return createResponse(Status::CODE_404, "Song not found");
}
+30 -21
View File
@@ -1,7 +1,6 @@
#ifndef YEARCONTROLLER_H_
#define YEARCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -18,45 +17,53 @@
#include "oatpp/web/server/api/ApiController.hpp"
#include "database/YearRepository.h"
#include "dto/conversion/DtoConversions.h"
#include "dto/YearDto.hpp"
#include "manager/TokenManager.h"
#include "manager/YearManager.h"
#include "model/Models.h"
#include "type/Scopes.h"
#include "type/YearFilter.h"
namespace fs = std::filesystem;
namespace controller {
class YearController : public oatpp::web::server::api::ApiController {
namespace controller
{
class YearController : public oatpp::web::server::api::ApiController
{
public:
YearController(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 for retrieving all year records in json format
ENDPOINT("GET", "/api/v1/year", yearRecords,
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 auth = authHeader->std_str();
manager::TokenManager tok;
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";
database::YearRepository yrRepo(m_bConf);
auto yrsDb = yrRepo.retrieveRecords();
auto yearRecs = oatpp::data::mapping::type::
List<dto::YearDto::ObjectWrapper>::createShared();
auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
yearRecs->reserve(yrsDb.size());
for (auto& yrDb : yrsDb) {
auto yr = dto::YearDto::createShared();
yr->id = yrDb.id;
yr->year = yrDb.year;
for (auto &yrDb : yrsDb) {
auto yr = dto::conversion::DtoConversions::toYearDto(yrDb);
yearRecs->pushBack(yr);
yearRecs->push_back(yr);
}
return createDtoResponse(Status::CODE_200, yearRecs);
@@ -64,26 +71,28 @@ namespace controller {
// endpoint for retrieving single year record by the year id in json format
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");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
manager::TokenManager tok;
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);
model::Year yrDb(id);
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";
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
auto year = dto::YearDto::createShared();
year->id = yrDb.id;
year->year= yrDb.year;
auto year = dto::conversion::DtoConversions::toYearDto(yrDb);
return createDtoResponse(Status::CODE_200, year);
}
+7 -5
View File
@@ -1,14 +1,16 @@
#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 {
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);
+7 -4
View File
@@ -1,14 +1,17 @@
#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 {
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);
+6 -4
View File
@@ -1,14 +1,16 @@
#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 {
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);
+6 -4
View File
@@ -1,14 +1,16 @@
#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 {
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);
+29 -25
View File
@@ -1,43 +1,47 @@
#ifndef LOGINRESULTDTO_H_
#define LOGINRESULTDTO_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>
#include "model/Models.h"
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class LoginResultDto : public oatpp::data::mapping::type::Object {
DTO_INIT(LoginResultDto, Object)
class LoginResultDto : public oatpp::DTO
{
DTO_INIT(LoginResultDto, DTO)
DTO_FIELD(Int32, id);
DTO_FIELD(String, username);
DTO_FIELD(String, token);
DTO_FIELD(String, token_type);
DTO_FIELD(Int32, expiration);
DTO_FIELD(String, message);
DTO_FIELD(oatpp::Int32, id);
DTO_FIELD(oatpp::String, username);
DTO_FIELD(oatpp::String, token);
DTO_FIELD(oatpp::String, token_type);
DTO_FIELD(oatpp::Int32, expiration);
DTO_FIELD(oatpp::String, message);
};
class RegisterResultDto : public oatpp::data::mapping::type::Object {
DTO_INIT(RegisterResultDto, Object)
class RegisterResultDto : public oatpp::DTO
{
DTO_INIT(RegisterResultDto, DTO)
DTO_FIELD(String, username);
DTO_FIELD(Boolean, registered);
DTO_FIELD(String, message);
DTO_FIELD(oatpp::String, username);
DTO_FIELD(oatpp::Boolean, registered);
DTO_FIELD(oatpp::String, message);
};
class UserDto : public oatpp::data::mapping::type::Object {
DTO_INIT(UserDto, Object)
class UserDto : public oatpp::DTO
{
DTO_INIT(UserDto, DTO)
DTO_FIELD(Int32, userId);
DTO_FIELD(String, firstname);
DTO_FIELD(String, lastname);
DTO_FIELD(String, phone);
DTO_FIELD(String, email);
DTO_FIELD(String, username);
DTO_FIELD(String, password);
DTO_FIELD(oatpp::Int32, userId);
DTO_FIELD(oatpp::String, firstname);
DTO_FIELD(oatpp::String, lastname);
DTO_FIELD(oatpp::String, phone);
DTO_FIELD(oatpp::String, email);
DTO_FIELD(oatpp::String, username);
DTO_FIELD(oatpp::String, password);
};
#include OATPP_CODEGEN_END(DTO)
+18 -16
View File
@@ -1,28 +1,30 @@
#ifndef SONGDTO_H_
#define SONGDTO_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>
#include "model/Models.h"
namespace dto {
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class SongDto : public oatpp::data::mapping::type::Object {
DTO_INIT(SongDto, Object)
class SongDto : public oatpp::DTO
{
DTO_INIT(SongDto, DTO)
DTO_FIELD(Int32, id);
DTO_FIELD(String, title);
DTO_FIELD(String, artist);
DTO_FIELD(String, album_artist);
DTO_FIELD(String, album);
DTO_FIELD(String, genre);
DTO_FIELD(Int32, track);
DTO_FIELD(Int32, disc);
DTO_FIELD(Int32, year);
DTO_FIELD(Int32, duration);
DTO_FIELD(Int32, coverart_id);
DTO_FIELD(oatpp::Int32, id);
DTO_FIELD(oatpp::String, title);
DTO_FIELD(oatpp::String, artist);
DTO_FIELD(oatpp::String, album_artist);
DTO_FIELD(oatpp::String, album);
DTO_FIELD(oatpp::String, genre);
DTO_FIELD(oatpp::Int32, track);
DTO_FIELD(oatpp::Int32, disc);
DTO_FIELD(oatpp::Int32, year);
DTO_FIELD(oatpp::Int32, duration);
DTO_FIELD(oatpp::Int32, coverart_id);
};
#include OATPP_CODEGEN_END(DTO)
+6 -4
View File
@@ -1,14 +1,16 @@
#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 {
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);
+153 -10
View File
@@ -1,27 +1,170 @@
#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>
#include <oatpp/core/Types.hpp>
#include "dto/AlbumDto.hpp"
#include "dto/ArtistDto.hpp"
#include "dto/CoverArtDto.hpp"
#include "dto/GenreDto.hpp"
#include "dto/LoginResultDto.hpp"
#include "dto/SongDto.hpp"
#include "dto/YearDto.hpp"
#include "model/Models.h"
namespace dto { namespace conversion {
class DtoConversions {
using namespace model;
using namespace dto;
namespace dto::conversion
{
class DtoConversions
{
public:
static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&);
template<typename D = oatpp::Object<LoginResultDto>>
static D toLoginResultDto(const User &user, const Token &token)
{
auto logRes = LoginResultDto::createShared();
logRes->id = (user.id != 0) ? user.id : 0;
logRes->username = (!user.username.empty()) ? user.username.c_str() : "None";
logRes->token = (!token.accessToken.empty()) ? token.accessToken.c_str() : "None";
logRes->token_type = (!token.tokenType.empty()) ? token.tokenType.c_str() : "None";
logRes->expiration = (token.expiration != 0) ? token.expiration : 0;
static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto(
const model::RegisterResult&);
return logRes;
}
static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&);
template<typename D = oatpp::Object<RegisterResultDto>>
static D toRegisterResultDto(
const model::RegisterResult &regRes)
{
auto result = RegisterResultDto::createShared();
result->message = (!regRes.message.empty()) ? regRes.message.c_str() : "None";
result->registered = regRes.registered;
result->username = (!regRes.username.empty()) ? regRes.username.c_str() : "None";
static dto::SongDto::ObjectWrapper toSongDto(const model::Song&);
return result;
}
static model::Song toSong(dto::SongDto::ObjectWrapper&);
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 model::User toUser(dto::UserDto::ObjectWrapper&);
return result;
}
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)
{
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;
}
template<typename D = oatpp::Object<YearDto>>
static D toYearDto(const Year &year)
{
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.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;
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;
return song;
}
template<typename D = oatpp::Object<UserDto>>
static User toUser(const D &userDto)
{
User user;
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
+10 -9
View File
@@ -3,15 +3,16 @@
#include <iostream>
#include <attachedpictureframe.h>
#include <tag.h>
#include <tfile.h>
#include <tfilestream.h>
#include <fileref.h>
#include <tbytevector.h>
#include <tbytevectorstream.h>
#include <tpropertymap.h>
#include <id3v2tag.h>
#include <taglib/attachedpictureframe.h>
#include <taglib/tag.h>
#include <taglib/tfile.h>
#include <taglib/tfilestream.h>
#include <taglib/fileref.h>
#include <taglib/tbytevector.h>
#include <taglib/tbytevectorstream.h>
#include <taglib/tpropertymap.h>
#include <taglib/id3v2tag.h>
namespace utility {
class ImageFile : public TagLib::File {
+5 -5
View File
@@ -4,11 +4,11 @@
#include <iostream>
#include <string>
#include <attachedpictureframe.h>
#include <textidentificationframe.h>
#include <fileref.h>
#include <mpegfile.h>
#include <tag.h>
#include <taglib/attachedpictureframe.h>
#include <taglib/textidentificationframe.h>
#include <taglib/fileref.h>
#include <taglib/mpegfile.h>
#include <taglib/tag.h>
#include "model/Models.h"
+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;
}
};
}
+27 -18
View File
@@ -1,13 +1,15 @@
#include <exception>
#include <iostream>
#include <filesystem>
#include <exception>
#include <memory>
#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/web/server/HttpConnectionHandler.hpp>
#include <oatpp/network/Server.hpp>
#include <oatpp/network/tcp/server/ConnectionProvider.hpp>
#include "component/AppComponent.hpp"
#include "controller/ArtistController.hpp"
@@ -21,12 +23,14 @@
#include "model/Models.h"
#include "verify/Initialization.h"
namespace fs = std::filesystem;
void run(const model::BinaryPath& bConf) {
void run(const model::BinaryPath& bConf)
{
component::AppComponent component;
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);
@@ -46,30 +50,35 @@ void run(const model::BinaryPath& bConf) {
sngController->addEndpointsToRouter(router);
yearController->addEndpointsToRouter(router);
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());
server.run();
}
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
oatpp::base::Environment::init();
model::BinaryPath bConf(std::move(argv[0]));
if (argc > 1) {
if (!verify::Initialization::skipVerification(argv[1])) {
verify::Initialization::checkIcarus(bConf);
} else {
if (argc > 1)
{
if (!verify::Initialization<>::skipVerification(argv[1]))
{
verify::Initialization<>::checkIcarus(bConf);
}
else
{
std::cout << "skiping verifyication\n";
}
} else {
verify::Initialization::checkIcarus(bConf);
}
else
{
verify::Initialization<>::checkIcarus(bConf);
}
run(bConf);
-87
View File
@@ -1,87 +0,0 @@
#include "dto/conversion/DtoConversions.h"
namespace dto { namespace conversion {
LoginResultDto::ObjectWrapper 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;
}
dto::RegisterResultDto::ObjectWrapper DtoConversions::toRegisterResultDto(
const model::RegisterResult& regRes) {
auto result = dto::RegisterResultDto::createShared();
result->message = regRes.message.c_str();
result->registered = regRes.registered;
result->username = regRes.username.c_str();
return result;
}
dto::AlbumDto::ObjectWrapper DtoConversions::toAlbumDto(const model::Album& album) {
auto result = dto::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;
return result;
}
dto::SongDto::ObjectWrapper DtoConversions::toSongDto(const model::Song& song) {
auto result = dto::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;
}
model::Song DtoConversions::toSong(dto::SongDto::ObjectWrapper& songDto) {
model::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;
}
model::User DtoConversions::toUser(dto::UserDto::ObjectWrapper& 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;
}
}}
+3 -4
View File
@@ -3,7 +3,6 @@
#include <iostream>
#include <iterator>
#include <fstream>
#include <filesystem>
#include <string>
#include <string_view>
#include <sstream>
@@ -11,8 +10,6 @@
#include "manager/DirectoryManager.h"
namespace fs = std::filesystem;
namespace manager {
model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf) {
auto cred = parseAuthCredentials(bConf);
@@ -93,7 +90,9 @@ namespace manager {
cpr::Response TokenManager::sendRequest(std::string_view uri, nlohmann::json& obj) {
auto resp = cpr::Post(cpr::Url{uri}, cpr::Body{obj.dump()},
const std::string uriString(uri.begin(), uri.end());
auto resp = cpr::Post(cpr::Url(uriString), cpr::Body{obj.dump()},
cpr::Header{{"Content-type", "application/json"},
{"Connection", "keep-alive"}});
-98
View File
@@ -1,98 +0,0 @@
#include "verify/Initialization.h"
#include <iostream>
#include <filesystem>
#include "database/BaseRepository.h"
#include "manager/DirectoryManager.h"
#include "manager/TokenManager.h"
#include "type/PathType.h"
namespace fs = std::filesystem;
namespace verify {
bool Initialization::skipVerification(const std::string& argument) {
return argument.compare("--noverify") == 0;
}
// verifies if the configuration settings are valid
void Initialization::checkIcarus(const model::BinaryPath& bConf) {
auto auth = confirmConfigAuth(bConf);
auto database = confirmConfigDatabase(bConf);
auto path = confirmConfigPaths(bConf);
if ((!auth) && (!database) && (!path)) {
failedConfirmation();
}
std::cout << "icarus check passed\n";
}
// verifies that the authorization settings are not the default values
bool Initialization::confirmConfigAuth(const model::BinaryPath& bConf) {
manager::TokenManager tokMgr;
return tokMgr.testAuth(bConf);
}
// verifies if database connectivity can be established
bool Initialization::confirmConfigDatabase(const model::BinaryPath& bConf) {
database::BaseRepository baseRepo(bConf);
return baseRepo.testConnection();
}
// verifies if the paths found in the config files exists
bool Initialization::confirmConfigPaths(const model::BinaryPath& bConf) {
using manager::DirectoryManager;
auto pathConfig = DirectoryManager::pathConfigContent(bConf);
const auto rootMusicPath =
pathConfig
[DirectoryManager::retrievePathType
(type::PathType::music)].get<std::string>();
const auto archiveRootPath =
pathConfig
[DirectoryManager::retrievePathType
(type::PathType::archive)].get<std::string>();
const auto tempRootPath =
pathConfig
[DirectoryManager::retrievePathType
(type::PathType::temp)].get<std::string>();
const auto coverRootPath =
pathConfig
[DirectoryManager::retrievePathType
(type::PathType::coverArt)].get<std::string>();
if (!fs::exists(rootMusicPath)) {
std::cout << "root music path is not properly configured\n";
return false;
}
if (!fs::exists(archiveRootPath)) {
std::cout << "archive root path is not properly configured\n";
return false;
}
if (!fs::exists(tempRootPath)) {
std::cout << "temp root path is not properly configured\n";
return false;
}
if (!fs::exists(coverRootPath)) {
std::cout << "cover art root path is not properly configured\n";
return false;
}
return true;
}
// confirmation failed
void Initialization::failedConfirmation() {
std::cout << "configuration confirmation failed. check your settings\n";
std::exit(-1);
}
}