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"] [submodule "build/3rdparty/jwt-cpp"]
path = build/3rdparty/jwt-cpp path = build/3rdparty/jwt-cpp
url = https://github.com/Thalhammer/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"] [submodule "3rdparty/ormpp"]
path = 3rdparty/ormpp path = 3rdparty/ormpp
url = https://github.com/qicosmos/ormpp url = https://github.com/qicosmos/ormpp
[submodule "3rdparty/libbcrypt"] [submodule "3rdparty/libbcrypt"]
path = 3rdparty/libbcrypt path = 3rdparty/libbcrypt
url = https://github.com/rg3/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_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(SOURCES set(SOURCES
src/callback/StreamCallback.cpp src/callback/StreamCallback.cpp
src/database/AlbumRepository.cpp src/database/AlbumRepository.cpp
@@ -15,7 +17,6 @@ set(SOURCES
src/database/SongRepository.cpp src/database/SongRepository.cpp
src/database/UserRepository.cpp src/database/UserRepository.cpp
src/database/YearRepository.cpp src/database/YearRepository.cpp
src/dto/conversion/DtoConversions.cpp
src/Main.cpp src/Main.cpp
src/manager/AlbumManager.cpp src/manager/AlbumManager.cpp
src/manager/ArtistManager.cpp src/manager/ArtistManager.cpp
@@ -29,111 +30,22 @@ set(SOURCES
src/utility/ImageFile.cpp src/utility/ImageFile.cpp
src/utility/MetadataRetriever.cpp src/utility/MetadataRetriever.cpp
src/utility/PasswordEncryption.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 set (BCRYPTLIB
${CMAKE_SOURCE_DIR}/3rdparty/libbcrypt ${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}) #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) 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}/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) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Images/Stock/CoverArt.png ${CMAKE_BINARY_DIR}/bin/CoverArt.png COPYONLY)
add_executable(icarus ${SOURCES} ${HEADERS}) find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h")
target_include_directories(icarus PUBLIC ${JWT_CPP_INCLUDE})
target_link_libraries(icarus "-lstdc++fs" tag oatpp mysqlclient ${CONAN_LIBS} ${CPR_LIBRARIES} bcrypt) 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) * [cpr](https://www.github.com/whoshuu/cpr)
* [TagLib](https://github.com/taglib/taglib) * [TagLib](https://github.com/taglib/taglib)
* [jwt-cpp](https://github.com/Thalhammer/jwt-cpp) * [jwt-cpp](https://github.com/Thalhammer/jwt-cpp)
* libmariadb
* [libbcrypt](https://github.com/rg3/libbcrypt) * [libbcrypt](https://github.com/rg3/libbcrypt)
* [oatpp](https://github.com/oatpp/oatpp) * [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 ## Building and Running
``` ```
git clone --recursive https://github.com/kdeng00/icarus 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 make
cd ../.. cd ../..
mkdir build mkdir build
cd build cd build
conan install ..
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SYSTEM_CURL=ON -DBUILD_CPR_TESTS=OFF -DOATPP_BUILD_TESTS=OFF cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DUSE_SYSTEM_CURL=ON -DBUILD_CPR_TESTS=OFF -DOATPP_BUILD_TESTS=OFF
make cmake --build .
bin/icarus bin/icarus
``` ```
Runs the server on localhost port 5002 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 <memory>
#include "oatpp/core/macro/component.hpp" #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/parser/json/mapping/ObjectMapper.hpp"
#include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/web/server/HttpConnectionHandler.hpp"
@@ -12,28 +12,35 @@ namespace component {
class AppComponent { class AppComponent {
public: public:
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,
serverConnectionProvider)([&] { serverConnectionProvider)([&]
return oatpp::network::server::SimpleTCPConnectionProvider:: {
createShared(appPort()); return oatpp::network::tcp::server::ConnectionProvider::createShared({"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(); return oatpp::web::server::HttpRouter::createShared();
}()); }());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>,
serverConnectionHandler)([] { serverConnectionHandler)([]
{
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router);
return oatpp::web::server::HttpConnectionHandler::createShared(router); return oatpp::web::server::HttpConnectionHandler::createShared(router);
}()); }());
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>,
apiObjectMapper)([] { apiObjectMapper)([]
{
return oatpp::parser::json::mapping::ObjectMapper::createShared(); return oatpp::parser::json::mapping::ObjectMapper::createShared();
}()); }());
private: private:
constexpr int appPort() noexcept { return 5002; } template<typename Val>
constexpr Val appPort() noexcept
{
return 5002;
}
}; };
} }
+29 -11
View File
@@ -1,7 +1,6 @@
#ifndef ALBUMCONTROLLER_H_ #ifndef ALBUMCONTROLLER_H_
#define ALBUMCONTROLLER_H_ #define ALBUMCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -16,6 +15,7 @@
#include "oatpp/web/mime/multipart/InMemoryPartReader.hpp" #include "oatpp/web/mime/multipart/InMemoryPartReader.hpp"
#include "oatpp/web/mime/multipart/Reader.hpp" #include "oatpp/web/mime/multipart/Reader.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "oatpp/core/Types.hpp"
#include "database/AlbumRepository.h" #include "database/AlbumRepository.h"
#include "dto/AlbumDto.hpp" #include "dto/AlbumDto.hpp"
@@ -26,37 +26,50 @@
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/AlbumFilter.h" #include "type/AlbumFilter.h"
namespace fs = std::filesystem; using namespace dto;
namespace controller { namespace controller
class AlbumController : public oatpp::web::server::api::ApiController { {
class AlbumController : public oatpp::web::server::api::ApiController
{
public: public:
AlbumController(const model::BinaryPath& bConf, AlbumController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all album records in json format // endpoint for retrieving all album records in json format
ENDPOINT("GET", "/api/v1/album", albumRecords, ENDPOINT("GET", "/api/v1/album", albumRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed"); type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
std::cout << "starting process of retrieving album\n"; std::cout << "starting process of retrieving album\n";
database::AlbumRepository albRepo(m_bConf); database::AlbumRepository albRepo(m_bConf);
auto albsDb = albRepo.retrieveRecords(); auto albsDb = albRepo.retrieveRecords();
auto albums = oatpp::data::mapping::type::
List<dto::AlbumDto::ObjectWrapper>::createShared(); auto albums = oatpp::Vector<oatpp::Object<AlbumDto>>::createShared();
albums->reserve(albsDb.size());
for (auto& albDb : albsDb) { for (auto& albDb : albsDb) {
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb); auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
albums->pushBack(alb); albums->push_back(alb);
} }
return createDtoResponse(Status::CODE_200, albums); return createDtoResponse(Status::CODE_200, albums);
@@ -64,11 +77,16 @@ namespace controller {
// endpoint for retrieving single album record by the album id in json format // endpoint for retrieving single album record by the album id in json format
ENDPOINT("GET", "/api/v1/album/{id}", albumRecord, ENDPOINT("GET", "/api/v1/album/{id}", albumRecord,
REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(Int32, id)) { REQUEST(std::shared_ptr<IncomingRequest>, request), PATH(Int32, id))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed"); type::Scope::retrieveAlbum), Status::CODE_403, "Not allowed");
+32 -17
View File
@@ -19,6 +19,7 @@
#include "database/ArtistRepository.h" #include "database/ArtistRepository.h"
#include "dto/ArtistDto.hpp" #include "dto/ArtistDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/ArtistManager.h" #include "manager/ArtistManager.h"
#include "manager/TokenManager.h" #include "manager/TokenManager.h"
#include "model/Models.h" #include "model/Models.h"
@@ -27,37 +28,47 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
namespace controller { namespace controller
class ArtistController : public oatpp::web::server::api::ApiController { {
class ArtistController : public oatpp::web::server::api::ApiController
{
public: public:
ArtistController(const model::BinaryPath& bConf, ArtistController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all artist records in json format // endpoint for retrieving all artist records in json format
ENDPOINT("GET", "/api/v1/artist", artistRecords, ENDPOINT("GET", "/api/v1/artist", artistRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving artist\n";
database::ArtistRepository artRepo(m_bConf); database::ArtistRepository artRepo(m_bConf);
auto artsDb = artRepo.retrieveRecords(); auto artsDb = artRepo.retrieveRecords();
auto artists = oatpp::data::mapping::type:: auto artists = oatpp::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
List<dto::ArtistDto::ObjectWrapper>::createShared(); artists->reserve(artsDb.size());
for (auto& artDb : artsDb) { for (auto& artDb : artsDb) {
auto art = dto::ArtistDto::createShared(); auto art = dto::conversion::DtoConversions::toArtistDto(artDb);
art->id = artDb.id;
art->artist = artDb.artist.c_str();
artists->pushBack(art); artists->push_back(art);
} }
return createDtoResponse(Status::CODE_200, artists); 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 for retrieving single artist record by the artist id in json format
ENDPOINT("GET", "/api/v1/artist/{id}", artistRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::ArtistRepository artRepo(m_bConf);
model::Artist artDb(id); model::Artist artDb(id);
@@ -80,11 +96,10 @@ namespace controller {
type::ArtistFilter::id) , Status::CODE_403, "artist does not exist"); type::ArtistFilter::id) , Status::CODE_403, "artist does not exist");
std::cout << "artist exist\n"; std::cout << "artist exist\n";
artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id); artDb = artRepo.retrieveRecord(artDb, type::ArtistFilter::id);
auto artist = dto::ArtistDto::createShared(); auto artist = dto::conversion::DtoConversions::toArtistDto(artDb);
artist->id = artDb.id;
artist->artist = artDb.artist.c_str();
return createDtoResponse(Status::CODE_200, artist); return createDtoResponse(Status::CODE_200, artist);
} }
+34 -22
View File
@@ -1,7 +1,6 @@
#ifndef COVERARTCONTROLLER_H_ #ifndef COVERARTCONTROLLER_H_
#define COVERARTCONTROLLER_H_ #define COVERARTCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -19,44 +18,51 @@
#include "database/CoverArtRepository.h" #include "database/CoverArtRepository.h"
#include "dto/CoverArtDto.hpp" #include "dto/CoverArtDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/CoverArtManager.h" #include "manager/CoverArtManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/CoverFilter.h" #include "type/CoverFilter.h"
namespace fs = std::filesystem;
namespace controller { namespace controller
class CoverArtController : public oatpp::web::server::api::ApiController { {
class CoverArtController : public oatpp::web::server::api::ApiController
{
public: public:
CoverArtController(const model::BinaryPath& bConf, CoverArtController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all cover art records in json format // endpoint for retrieving all cover art records in json format
ENDPOINT("GET", "/api/v1/coverart", coverArtRecords, ENDPOINT("GET", "/api/v1/coverart", coverArtRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving cover art\n";
database::CoverArtRepository covRepo(m_bConf); database::CoverArtRepository covRepo(m_bConf);
auto covsDb = covRepo.retrieveRecords(); auto covsDb = covRepo.retrieveRecords();
auto coverArts = oatpp::data::mapping::type:: auto coverArts = oatpp::Vector<oatpp::Object<dto::CoverArtDto>>::createShared();
List<dto::CoverArtDto::ObjectWrapper>::createShared(); coverArts->reserve(covsDb.size());
for (auto& covDb : covsDb) { for (auto& covDb : covsDb) {
auto cov = dto::CoverArtDto::createShared(); auto cov = dto::conversion::DtoConversions::toCoverDto(covDb);
cov->id = covDb.id;
cov->songTitle = covDb.songTitle.c_str();
coverArts->pushBack(cov); coverArts->push_back(cov);
} }
return createDtoResponse(Status::CODE_200, coverArts); return createDtoResponse(Status::CODE_200, coverArts);
@@ -64,39 +70,45 @@ namespace controller {
// endpoint for retrieving single cover art record by the cover art id in json format // endpoint for retrieving single cover art record by the cover art id in json format
ENDPOINT("GET", "/api/v1/coverart/{id}", coverArtRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::CoverArtRepository covRepo(m_bConf);
model::Cover covDb; model::Cover covDb;
covDb.id = id; covDb.id = id;
OATPP_ASSERT_HTTP(covRepo.doesCoverArtExist(covDb, 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"; std::cout << "cover art exists\n";
covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id); covDb = covRepo.retrieveRecord(covDb, type::CoverFilter::id);
auto coverArt = dto::CoverArtDto::createShared(); auto coverArt = dto::conversion::DtoConversions::toCoverDto(covDb);
coverArt->id = covDb.id;
coverArt->songTitle = covDb.songTitle.c_str();
return createDtoResponse(Status::CODE_200, coverArt); return createDtoResponse(Status::CODE_200, coverArt);
} }
ENDPOINT("GET", "/api/v1/coverart/download/{id}", downloadCoverArt, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::CoverArtRepository covRepo(m_bConf);
model::Cover covDb; model::Cover covDb;
+23 -18
View File
@@ -1,7 +1,6 @@
#ifndef GENRECONTROLLER_H_ #ifndef GENRECONTROLLER_H_
#define GENRECONTROLLER_H_ #define GENRECONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -19,45 +18,51 @@
#include "database/GenreRepository.h" #include "database/GenreRepository.h"
#include "dto/GenreDto.hpp" #include "dto/GenreDto.hpp"
#include "dto/conversion/DtoConversions.h"
#include "manager/GenreManager.h" #include "manager/GenreManager.h"
#include "manager/TokenManager.h"
#include "manager/YearManager.h" #include "manager/YearManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/GenreFilter.h" #include "type/GenreFilter.h"
namespace fs = std::filesystem; namespace controller
{
namespace controller { class GenreController : public oatpp::web::server::api::ApiController
class GenreController : public oatpp::web::server::api::ApiController { {
public: public:
GenreController(const model::BinaryPath& bConf, GenreController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all genre records in json format // endpoint for retrieving all genre records in json format
ENDPOINT("GET", "/api/v1/genre", genreRecords, ENDPOINT("GET", "/api/v1/genre", genreRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::retrieveGenre), Status::CODE_403, "Not allowed"); type::Scope::retrieveGenre), Status::CODE_403, "Not allowed");
std::cout << "starting process of retrieving genre\n"; std::cout << "starting process of retrieving genre\n";
database::GenreRepository gnrRepo(m_bConf); database::GenreRepository gnrRepo(m_bConf);
auto gnrsDb = gnrRepo.retrieveRecords(); auto gnrsDb = gnrRepo.retrieveRecords();
auto genres = oatpp::data::mapping::type:: auto genres = oatpp::Vector<oatpp::Object<dto::GenreDto>>::createShared();
List<dto::GenreDto::ObjectWrapper>::createShared(); genres->reserve(gnrsDb.size());
for (auto& gnrDb : gnrsDb) { for (auto& gnrDb : gnrsDb) {
auto gnr = dto::GenreDto::createShared(); auto gnr = dto::conversion::DtoConversions::toGenreDto(gnrDb);
gnr->id = gnrDb.id;
gnr->category = gnrDb.category.c_str();
genres->pushBack(gnr); genres->push_back(gnr);
} }
return createDtoResponse(Status::CODE_200, genres); return createDtoResponse(Status::CODE_200, genres);
@@ -65,9 +70,11 @@ namespace controller {
// endpoint for retrieving single genre record by the genre id in json format // endpoint for retrieving single genre record by the genre id in json format
ENDPOINT("GET", "/api/v1/genre/{id}", genreRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
@@ -82,9 +89,7 @@ namespace controller {
std::cout << "genre exist\n"; std::cout << "genre exist\n";
gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id); gnrDb = gnrRepo.retrieveRecord(gnrDb, type::GenreFilter::id);
auto genre = dto::GenreDto::createShared(); auto genre = dto::conversion::DtoConversions::toGenreDto(gnrDb);
genre->id = gnrDb.id;
genre->category= gnrDb.category.c_str();
return createDtoResponse(Status::CODE_200, genre); return createDtoResponse(Status::CODE_200, genre);
} }
+15 -7
View File
@@ -9,23 +9,30 @@
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "dto/conversion/DtoConversions.h"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
#include "dto/conversion/DtoConversions.h" #include "dto/conversion/DtoConversions.h"
#include "manager/TokenManager.h" #include "manager/TokenManager.h"
#include "manager/UserManager.h" #include "manager/UserManager.h"
#include "model/Models.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: public:
LoginController(const model::BinaryPath& bConf, LoginController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
:oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
ENDPOINT("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"); OATPP_LOGI("icarus", "logging in");
manager::UserManager usrMgr(m_bConf); manager::UserManager usrMgr(m_bConf);
@@ -33,13 +40,14 @@ namespace controller {
if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) { if (!usrMgr.doesUserExist(user) || !usrMgr.validatePassword(user)) {
auto logRes = dto::LoginResultDto::createShared(); auto logRes = dto::LoginResultDto::createShared();
logRes->message = "invalid credentials"; logRes->message = "invalid credentials";
std::cout << "user does not exist\n"; std::cout << "user does not exist\n";
return createDtoResponse(Status::CODE_401, logRes); return createDtoResponse(Status::CODE_401, logRes);
} }
std::cout << "user exists\n";
manager::TokenManager tok; manager::TokenManager tok;
auto token = tok.retrieveToken(m_bConf); auto token = tok.retrieveToken(m_bConf);
+17 -5
View File
@@ -6,6 +6,7 @@
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
@@ -13,19 +14,30 @@
#include "manager/UserManager.h" #include "manager/UserManager.h"
#include "model/Models.h" #include "model/Models.h"
namespace controller { using namespace dto;
class RegisterController : public oatpp::web::server::api::ApiController {
namespace controller
{
class RegisterController : public oatpp::web::server::api::ApiController
{
public: public:
RegisterController(const model::BinaryPath& bConf, RegisterController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) : OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
ENDPOINT("POST", "api/v1/register", registerUser, ENDPOINT("POST", "api/v1/register", registerUser,
BODY_DTO(dto::UserDto::ObjectWrapper, usr)) { BODY_DTO(oatpp::Object<UserDto>, usr))
{
manager::UserManager usrMgr(m_bConf); 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)) { if (usrMgr.doesUserExist(user)) {
return createResponse(Status::CODE_401, "user already exists"); return createResponse(Status::CODE_401, "user already exists");
} }
+66 -32
View File
@@ -16,6 +16,8 @@
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp" #include "oatpp/core/macro/component.hpp"
#include "oatpp/web/mime/multipart/InMemoryPartReader.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/mime/multipart/Reader.hpp"
#include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp" #include "oatpp/web/protocol/http/outgoing/StreamingBody.hpp"
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
@@ -31,36 +33,46 @@
#include "type/SongFilter.h" #include "type/SongFilter.h"
#include "type/SongUpload.h" #include "type/SongUpload.h"
namespace fs = std::filesystem;
namespace controller { using namespace dto;
class SongController : public oatpp::web::server::api::ApiController {
namespace controller
{
class SongController : public oatpp::web::server::api::ApiController
{
public: public:
SongController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) SongController(const model::BinaryPath& bConf,
: 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) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for uploading a song // endpoint for uploading a song
ENDPOINT("POST", "/api/v1/song/data", songUpload, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str();
auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
type::Scope::upload), Status::CODE_403, "Not allowed"); type::Scope::upload),
Status::CODE_403, "Not allowed");
auto mp = auto mp =
std::make_shared<oatpp::web::mime::multipart::Multipart> std::make_shared<oatpp::web::mime::multipart::PartList>
(request->getHeaders()); (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); request->transferBody(&mp_reader);
@@ -78,6 +90,7 @@ namespace controller {
manager::SongManager songMgr(m_bConf); manager::SongManager songMgr(m_bConf);
const auto result = songMgr.saveSong(sng); const auto result = songMgr.saveSong(sng);
if (!result.first) { if (!result.first) {
switch (result.second) { switch (result.second) {
case type::SongUpload::AlreadyExist: case type::SongUpload::AlreadyExist:
@@ -94,23 +107,28 @@ namespace controller {
// endpoint for retrieving all song records in json format // endpoint for retrieving all song records in json format
ENDPOINT("GET", "/api/v1/song", songRecords, ENDPOINT("GET", "/api/v1/song", songRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; 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"; std::cout << "starting process of retrieving songs\n";
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
auto songsDb = songRepo.retrieveRecords(); auto songsDb = songRepo.retrieveRecords();
auto songs = oatpp::data::mapping::type::List<dto::SongDto::ObjectWrapper>::createShared(); auto songs = oatpp::Vector<oatpp::Object<dto::SongDto>>::createShared();
std::cout << "creating object to send\n"; std::cout << "creating object to send\n";
for (auto& songDb : songsDb) { for (auto& songDb : songsDb) {
auto song = dto::conversion::DtoConversions::toSongDto(songDb); auto song = dto::conversion::DtoConversions::toSongDto(songDb);
songs->pushBack(song); songs->push_back(song);
} }
return createDtoResponse(Status::CODE_200, songs); return createDtoResponse(Status::CODE_200, songs);
@@ -118,12 +136,15 @@ namespace controller {
// endpoint for retrieving song record by the song id in json format // endpoint for retrieving song record by the song id in json format
ENDPOINT("GET", "/api/v1/song/{id}", songRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; 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); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
@@ -141,16 +162,20 @@ namespace controller {
} }
ENDPOINT("GET", "/api/v1/song/data/{id}", downloadSong, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::download),
type::Scope::download), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -167,10 +192,12 @@ namespace controller {
ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate, ENDPOINT("UPDATE", "/api/v1/song/{id}", songUpdate,
REQUEST(std::shared_ptr<IncomingRequest>, request), REQUEST(std::shared_ptr<IncomingRequest>, request),
BODY_DTO(dto::SongDto::ObjectWrapper, songDto), PATH(Int32, id)) { BODY_DTO(oatpp::Object<SongDto>, songDto), PATH(Int32, id))
{
songDto->id = id; songDto->id = id;
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth,
@@ -179,6 +206,7 @@ namespace controller {
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto); auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
manager::SongManager songMgr(m_bConf); manager::SongManager songMgr(m_bConf);
auto result = songMgr.updateSong(updatedSong); auto result = songMgr.updateSong(updatedSong);
if (!result) { if (!result) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -188,18 +216,21 @@ namespace controller {
// endpoint to delete a song // endpoint to delete a song
ENDPOINT("DELETE", "api/v1/song/data/{id}", songDelete, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::deleteSong),
type::Scope::deleteSong), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
model::Song song(id); model::Song song(id);
manager::SongManager sngMgr(m_bConf); manager::SongManager sngMgr(m_bConf);
auto result = sngMgr.deleteSong(song); auto result = sngMgr.deleteSong(song);
if (!result) { if (!result) {
return songDoesNotExist(); return songDoesNotExist();
} }
@@ -209,23 +240,26 @@ namespace controller {
// endpoint for streaming a song // endpoint for streaming a song
ENDPOINT("GET", "/api/v1/song/stream/{id}", streamSong, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, OATPP_ASSERT_HTTP(tok.isTokenValid(auth, type::Scope::stream),
type::Scope::stream), Status::CODE_403, "Not allowed"); Status::CODE_403, "Not allowed");
database::SongRepository songRepo(m_bConf); database::SongRepository songRepo(m_bConf);
model::Song songDb(id); model::Song songDb(id);
if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) { if (!songRepo.doesSongExist(songDb, type::SongFilter::id)) {
return songDoesNotExist(); return songDoesNotExist();
} }
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id); songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
auto dSize = 1024; constexpr auto dSize = 1024;
auto callback = std::make_shared<callback::StreamCallback>(songDb.songPath); auto callback = std::make_shared<callback::StreamCallback>(songDb.songPath);
auto db = std::make_shared<oatpp::web::protocol::http::outgoing::StreamingBody>( auto db = std::make_shared<oatpp::web::protocol::http::outgoing::StreamingBody>(
@@ -242,8 +276,8 @@ namespace controller {
#include OATPP_CODEGEN_END(ApiController) #include OATPP_CODEGEN_END(ApiController)
private: private:
std::shared_ptr<oatpp::web::protocol::http::outgoing::Response> std::shared_ptr<oatpp::web::protocol::http::outgoing::Response>
songDoesNotExist() { songDoesNotExist()
{
return createResponse(Status::CODE_404, "Song not found"); return createResponse(Status::CODE_404, "Song not found");
} }
+29 -20
View File
@@ -1,7 +1,6 @@
#ifndef YEARCONTROLLER_H_ #ifndef YEARCONTROLLER_H_
#define YEARCONTROLLER_H_ #define YEARCONTROLLER_H_
#include <filesystem>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <limits> #include <limits>
@@ -18,45 +17,53 @@
#include "oatpp/web/server/api/ApiController.hpp" #include "oatpp/web/server/api/ApiController.hpp"
#include "database/YearRepository.h" #include "database/YearRepository.h"
#include "dto/conversion/DtoConversions.h"
#include "dto/YearDto.hpp" #include "dto/YearDto.hpp"
#include "manager/TokenManager.h"
#include "manager/YearManager.h" #include "manager/YearManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/Scopes.h" #include "type/Scopes.h"
#include "type/YearFilter.h" #include "type/YearFilter.h"
namespace fs = std::filesystem;
namespace controller { namespace controller
class YearController : public oatpp::web::server::api::ApiController { {
class YearController : public oatpp::web::server::api::ApiController
{
public: public:
YearController(const model::BinaryPath& bConf, YearController(const model::BinaryPath& bConf,
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf) { } oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
#include OATPP_CODEGEN_BEGIN(ApiController) #include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all year records in json format // endpoint for retrieving all year records in json format
ENDPOINT("GET", "/api/v1/year", yearRecords, ENDPOINT("GET", "/api/v1/year", yearRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request)) { REQUEST(std::shared_ptr<IncomingRequest>, request))
{
auto authHeader = request->getHeader("Authorization"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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"; std::cout << "starting process of retrieving year\n";
database::YearRepository yrRepo(m_bConf); database::YearRepository yrRepo(m_bConf);
auto yrsDb = yrRepo.retrieveRecords(); auto yrsDb = yrRepo.retrieveRecords();
auto yearRecs = oatpp::data::mapping::type:: auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
List<dto::YearDto::ObjectWrapper>::createShared(); yearRecs->reserve(yrsDb.size());
for (auto &yrDb : yrsDb) { for (auto &yrDb : yrsDb) {
auto yr = dto::YearDto::createShared(); auto yr = dto::conversion::DtoConversions::toYearDto(yrDb);
yr->id = yrDb.id;
yr->year = yrDb.year;
yearRecs->pushBack(yr); yearRecs->push_back(yr);
} }
return createDtoResponse(Status::CODE_200, yearRecs); 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 for retrieving single year record by the year id in json format
ENDPOINT("GET", "/api/v1/year/{id}", yearRecord, 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"); auto authHeader = request->getHeader("Authorization");
OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope"); OATPP_ASSERT_HTTP(authHeader, Status::CODE_403, "Nope");
auto auth = authHeader->std_str(); auto auth = authHeader->std_str();
manager::TokenManager tok; manager::TokenManager tok;
OATPP_ASSERT_HTTP(tok.isTokenValid(auth, 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); database::YearRepository yrRepo(m_bConf);
model::Year yrDb(id); model::Year yrDb(id);
OATPP_ASSERT_HTTP(yrRepo.doesYearExist(yrDb, 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"; std::cout << "year exist\n";
yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id); yrDb = yrRepo.retrieveRecord(yrDb, type::YearFilter::id);
auto year = dto::YearDto::createShared(); auto year = dto::conversion::DtoConversions::toYearDto(yrDb);
year->id = yrDb.id;
year->year= yrDb.year;
return createDtoResponse(Status::CODE_200, year); return createDtoResponse(Status::CODE_200, year);
} }
+7 -5
View File
@@ -1,14 +1,16 @@
#ifndef ALBUMDTO_H_ #ifndef ALBUMDTO_H_
#define ALBUMDTO_H_ #define ALBUMDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp" #include <oatpp/core/Types.hpp>
#include "oatpp/core/macro/codegen.hpp" #include <oatpp/core/macro/codegen.hpp>
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class AlbumDto : public oatpp::data::mapping::type::Object { class AlbumDto : public oatpp::DTO
DTO_INIT(AlbumDto, Object) {
DTO_INIT(AlbumDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, title); DTO_FIELD(String, title);
+7 -4
View File
@@ -1,14 +1,17 @@
#ifndef ARTISTDTO_H_ #ifndef ARTISTDTO_H_
#define ARTISTDTO_H_ #define ARTISTDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp" // #include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class ArtistDto : public oatpp::data::mapping::type::Object { class ArtistDto : public oatpp::DTO
DTO_INIT(ArtistDto, Object) {
DTO_INIT(ArtistDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, artist); DTO_FIELD(String, artist);
+6 -4
View File
@@ -1,14 +1,16 @@
#ifndef COVERARTDTO_H_ #ifndef COVERARTDTO_H_
#define COVERARTDTO_H_ #define COVERARTDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class CoverArtDto : public oatpp::data::mapping::type::Object { class CoverArtDto : public oatpp::DTO
DTO_INIT(CoverArtDto, Object) {
DTO_INIT(CoverArtDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, songTitle); DTO_FIELD(String, songTitle);
+6 -4
View File
@@ -1,14 +1,16 @@
#ifndef GENREDTO_H_ #ifndef GENREDTO_H_
#define GENREDTO_H_ #define GENREDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class GenreDto : public oatpp::data::mapping::type::Object { class GenreDto : public oatpp::DTO
DTO_INIT(GenreDto, Object) {
DTO_INIT(GenreDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(String, category); DTO_FIELD(String, category);
+29 -25
View File
@@ -1,43 +1,47 @@
#ifndef LOGINRESULTDTO_H_ #ifndef LOGINRESULTDTO_H_
#define 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" #include "model/Models.h"
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class LoginResultDto : public oatpp::data::mapping::type::Object { class LoginResultDto : public oatpp::DTO
DTO_INIT(LoginResultDto, Object) {
DTO_INIT(LoginResultDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(oatpp::Int32, id);
DTO_FIELD(String, username); DTO_FIELD(oatpp::String, username);
DTO_FIELD(String, token); DTO_FIELD(oatpp::String, token);
DTO_FIELD(String, token_type); DTO_FIELD(oatpp::String, token_type);
DTO_FIELD(Int32, expiration); DTO_FIELD(oatpp::Int32, expiration);
DTO_FIELD(String, message); DTO_FIELD(oatpp::String, message);
}; };
class RegisterResultDto : public oatpp::data::mapping::type::Object { class RegisterResultDto : public oatpp::DTO
DTO_INIT(RegisterResultDto, Object) {
DTO_INIT(RegisterResultDto, DTO)
DTO_FIELD(String, username); DTO_FIELD(oatpp::String, username);
DTO_FIELD(Boolean, registered); DTO_FIELD(oatpp::Boolean, registered);
DTO_FIELD(String, message); DTO_FIELD(oatpp::String, message);
}; };
class UserDto : public oatpp::data::mapping::type::Object { class UserDto : public oatpp::DTO
DTO_INIT(UserDto, Object) {
DTO_INIT(UserDto, DTO)
DTO_FIELD(Int32, userId); DTO_FIELD(oatpp::Int32, userId);
DTO_FIELD(String, firstname); DTO_FIELD(oatpp::String, firstname);
DTO_FIELD(String, lastname); DTO_FIELD(oatpp::String, lastname);
DTO_FIELD(String, phone); DTO_FIELD(oatpp::String, phone);
DTO_FIELD(String, email); DTO_FIELD(oatpp::String, email);
DTO_FIELD(String, username); DTO_FIELD(oatpp::String, username);
DTO_FIELD(String, password); DTO_FIELD(oatpp::String, password);
}; };
#include OATPP_CODEGEN_END(DTO) #include OATPP_CODEGEN_END(DTO)
+18 -16
View File
@@ -1,28 +1,30 @@
#ifndef SONGDTO_H_ #ifndef SONGDTO_H_
#define SONGDTO_H_ #define SONGDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp" #include <oatpp/core/Types.hpp>
#include "oatpp/core/macro/codegen.hpp" #include <oatpp/core/macro/codegen.hpp>
#include "model/Models.h" #include "model/Models.h"
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class SongDto : public oatpp::data::mapping::type::Object { class SongDto : public oatpp::DTO
DTO_INIT(SongDto, Object) {
DTO_INIT(SongDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(oatpp::Int32, id);
DTO_FIELD(String, title); DTO_FIELD(oatpp::String, title);
DTO_FIELD(String, artist); DTO_FIELD(oatpp::String, artist);
DTO_FIELD(String, album_artist); DTO_FIELD(oatpp::String, album_artist);
DTO_FIELD(String, album); DTO_FIELD(oatpp::String, album);
DTO_FIELD(String, genre); DTO_FIELD(oatpp::String, genre);
DTO_FIELD(Int32, track); DTO_FIELD(oatpp::Int32, track);
DTO_FIELD(Int32, disc); DTO_FIELD(oatpp::Int32, disc);
DTO_FIELD(Int32, year); DTO_FIELD(oatpp::Int32, year);
DTO_FIELD(Int32, duration); DTO_FIELD(oatpp::Int32, duration);
DTO_FIELD(Int32, coverart_id); DTO_FIELD(oatpp::Int32, coverart_id);
}; };
#include OATPP_CODEGEN_END(DTO) #include OATPP_CODEGEN_END(DTO)
+6 -4
View File
@@ -1,14 +1,16 @@
#ifndef YEARDTO_H_ #ifndef YEARDTO_H_
#define YEARDTO_H_ #define YEARDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp" #include "oatpp/core/macro/codegen.hpp"
#include <oatpp/core/Types.hpp>
namespace dto { namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO) #include OATPP_CODEGEN_BEGIN(DTO)
class YearDto : public oatpp::data::mapping::type::Object { class YearDto : public oatpp::DTO
DTO_INIT(YearDto, Object) {
DTO_INIT(YearDto, DTO)
DTO_FIELD(Int32, id); DTO_FIELD(Int32, id);
DTO_FIELD(Int32, year); DTO_FIELD(Int32, year);
+153 -10
View File
@@ -1,27 +1,170 @@
#ifndef DTOCONVERSIONS_H_ #ifndef DTOCONVERSIONS_H_
#define 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/AlbumDto.hpp"
#include "dto/ArtistDto.hpp"
#include "dto/CoverArtDto.hpp"
#include "dto/GenreDto.hpp"
#include "dto/LoginResultDto.hpp" #include "dto/LoginResultDto.hpp"
#include "dto/SongDto.hpp" #include "dto/SongDto.hpp"
#include "dto/YearDto.hpp"
#include "model/Models.h" #include "model/Models.h"
namespace dto { namespace conversion { using namespace model;
class DtoConversions { using namespace dto;
namespace dto::conversion
{
class DtoConversions
{
public: 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( return logRes;
const model::RegisterResult&); }
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 #endif
+10 -9
View File
@@ -3,15 +3,16 @@
#include <iostream> #include <iostream>
#include <attachedpictureframe.h> #include <taglib/attachedpictureframe.h>
#include <tag.h> #include <taglib/tag.h>
#include <tfile.h> #include <taglib/tfile.h>
#include <tfilestream.h> #include <taglib/tfilestream.h>
#include <fileref.h> #include <taglib/fileref.h>
#include <tbytevector.h> #include <taglib/tbytevector.h>
#include <tbytevectorstream.h> #include <taglib/tbytevectorstream.h>
#include <tpropertymap.h> #include <taglib/tpropertymap.h>
#include <id3v2tag.h> #include <taglib/id3v2tag.h>
namespace utility { namespace utility {
class ImageFile : public TagLib::File { class ImageFile : public TagLib::File {
+5 -5
View File
@@ -4,11 +4,11 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <attachedpictureframe.h> #include <taglib/attachedpictureframe.h>
#include <textidentificationframe.h> #include <taglib/textidentificationframe.h>
#include <fileref.h> #include <taglib/fileref.h>
#include <mpegfile.h> #include <taglib/mpegfile.h>
#include <tag.h> #include <taglib/tag.h>
#include "model/Models.h" #include "model/Models.h"
+100 -8
View File
@@ -1,22 +1,114 @@
#ifndef INITIALIZATION_H_ #ifndef INITIALIZATION_H_
#define INITIALIZATION_H_ #define INITIALIZATION_H_
#include <iostream>
#include <filesystem>
#include <string> #include <string>
#include <vector>
#include <utility>
#include "database/BaseRepository.h"
#include "manager/DirectoryManager.h"
#include "manager/TokenManager.h"
#include "model/Models.h" #include "model/Models.h"
#include "type/PathType.h"
namespace verify { namespace fs = std::filesystem;
class Initialization {
namespace verify
{
template<typename Config = model::BinaryPath>
class Initialization
{
public: 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: private:
static bool confirmConfigAuth(const model::BinaryPath&); static bool confirmConfigAuth(const Config &bConf)
static bool confirmConfigDatabase(const model::BinaryPath&); {
static bool confirmConfigPaths(const model::BinaryPath&); 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 <iostream>
#include <filesystem> #include <exception>
#include <memory> #include <memory>
#include <string> #include <string>
#include <mysql/mysql.h> #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 "component/AppComponent.hpp"
#include "controller/ArtistController.hpp" #include "controller/ArtistController.hpp"
@@ -21,12 +23,14 @@
#include "model/Models.h" #include "model/Models.h"
#include "verify/Initialization.h" #include "verify/Initialization.h"
namespace fs = std::filesystem;
void run(const model::BinaryPath& bConf) { void run(const model::BinaryPath& bConf)
{
component::AppComponent component; component::AppComponent component;
OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>, router); auto router = oatpp::web::server::HttpRouter::createShared();
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
auto albumController = std::make_shared<controller::AlbumController>(bConf); auto albumController = std::make_shared<controller::AlbumController>(bConf);
auto artistController = std::make_shared<controller::ArtistController>(bConf); auto artistController = std::make_shared<controller::ArtistController>(bConf);
@@ -46,30 +50,35 @@ void run(const model::BinaryPath& bConf) {
sngController->addEndpointsToRouter(router); sngController->addEndpointsToRouter(router);
yearController->addEndpointsToRouter(router); yearController->addEndpointsToRouter(router);
OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider); OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
oatpp::network::server::Server server(connectionProvider, connectionHandler); oatpp::network::Server server(connectionProvider, connectionHandler);
OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData()); OATPP_LOGI("icarus", "Server running on port %s", connectionProvider->getProperty("port").getData());
server.run(); server.run();
} }
int main(int argc, char **argv) { int main(int argc, char **argv)
{
oatpp::base::Environment::init(); oatpp::base::Environment::init();
model::BinaryPath bConf(std::move(argv[0])); model::BinaryPath bConf(std::move(argv[0]));
if (argc > 1) { if (argc > 1)
if (!verify::Initialization::skipVerification(argv[1])) { {
verify::Initialization::checkIcarus(bConf); if (!verify::Initialization<>::skipVerification(argv[1]))
} else { {
verify::Initialization<>::checkIcarus(bConf);
}
else
{
std::cout << "skiping verifyication\n"; std::cout << "skiping verifyication\n";
} }
} else { }
verify::Initialization::checkIcarus(bConf); else
{
verify::Initialization<>::checkIcarus(bConf);
} }
run(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 <iostream>
#include <iterator> #include <iterator>
#include <fstream> #include <fstream>
#include <filesystem>
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <sstream> #include <sstream>
@@ -11,8 +10,6 @@
#include "manager/DirectoryManager.h" #include "manager/DirectoryManager.h"
namespace fs = std::filesystem;
namespace manager { namespace manager {
model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf) { model::Token TokenManager::retrieveToken(const model::BinaryPath& bConf) {
auto cred = parseAuthCredentials(bConf); auto cred = parseAuthCredentials(bConf);
@@ -93,7 +90,9 @@ namespace manager {
cpr::Response TokenManager::sendRequest(std::string_view uri, nlohmann::json& obj) { 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"}, cpr::Header{{"Content-type", "application/json"},
{"Connection", "keep-alive"}}); {"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);
}
}