Saving changes

This commit is contained in:
kdeng00
2020-12-19 08:07:56 -05:00
parent b8caefac81
commit 8306851dcb
12 changed files with 282 additions and 205 deletions
-3
View File
@@ -1,6 +1,3 @@
[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
-1
Submodule 3rdparty/oatpp deleted from 27c46444db
-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
+9 -9
View File
@@ -1,7 +1,6 @@
#ifndef ALBUMCONTROLLER_H_
#define ALBUMCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -27,16 +26,17 @@
#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)
OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper)) :
oatpp::web::server::api::ApiController(objectMapper),
m_bConf(bConf)
{
}
@@ -67,7 +67,7 @@ namespace controller {
albums->reserve(albsDb.size());
for (auto& albDb : albsDb) {
auto alb = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
auto alb = dto::conversion::DtoConversions::toAlbumDto(albDb);
albums->push_back(alb);
}
@@ -99,7 +99,7 @@ namespace controller {
std::cout << "album exists\n";
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id);
auto album = dto::conversion::DtoConversions::toAlbumDto<oatpp::Object<AlbumDto>>(albDb);
auto album = dto::conversion::DtoConversions::toAlbumDto(albDb);
return createDtoResponse(Status::CODE_200, album);
}
+29 -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,40 +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::Vector<oatpp::Object<dto::ArtistDto>>::createShared();
// List<dto::ArtistDto::ObjectWrapper>::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->push_back(art);
artists->push_back(art);
// artists.push_back(art);
}
return createDtoResponse(Status::CODE_200, artists);
@@ -68,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);
@@ -83,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);
}
+32 -19
View File
@@ -1,7 +1,6 @@
#ifndef COVERARTCONTROLLER_H_
#define COVERARTCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -19,41 +18,49 @@
#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::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->push_back(cov);
}
@@ -63,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;
+21 -15
View File
@@ -1,7 +1,6 @@
#ifndef GENRECONTROLLER_H_
#define GENRECONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -19,42 +18,49 @@
#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::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->push_back(gnr);
}
@@ -64,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,
@@ -81,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 -5
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,8 +40,11 @@ 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);
}
+67 -30
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,40 +33,57 @@
#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();
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());
oatpp::web::mime::multipart::Reader mp_reader = mp.get();
/**
mp_reader.setPartReader("file",
oatpp::web::mime::multipart::createInMemoryPartReader(m_dataSize));
*/
mp_reader.setDefaultPartReader(
oatpp::web::mime::multipart::createInMemoryPartReader(30 * 1024 * 1024));
request->transferBody(&mp_reader);
auto file = mp->getNamedPart("file");
// auto file = mp->readNextPartSimple();
OATPP_ASSERT_HTTP(file, Status::CODE_400, "file is null");
@@ -78,6 +97,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,22 +114,24 @@ 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();
// auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
std::cout << "creating object to send\n";
for (auto& songDb : songsDb) {
auto song = dto::conversion::DtoConversions::toSongDto(songDb);
@@ -121,12 +143,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);
@@ -144,16 +169,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();
}
@@ -169,12 +198,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)) {
BODY_DTO(oatpp::data::mapping::type::ObjectWrapper<dto::SongDto>, 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,
@@ -183,6 +213,7 @@ namespace controller {
auto updatedSong = dto::conversion::DtoConversions::toSong(songDto);
manager::SongManager songMgr(m_bConf);
auto result = songMgr.updateSong(updatedSong);
if (!result) {
return songDoesNotExist();
}
@@ -192,18 +223,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();
}
@@ -213,16 +247,19 @@ 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();
}
@@ -246,8 +283,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");
}
+28 -24
View File
@@ -1,7 +1,6 @@
#ifndef YEARCONTROLLER_H_
#define YEARCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
@@ -18,49 +17,52 @@
#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();
// List<dto::YearDto>::createShared();
auto yearRecs = oatpp::Vector<oatpp::Object<dto::YearDto>>::createShared();
// List<dto::YearDto::ObjectWrapper>::createShared();
// List<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);
}
@@ -69,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);
}
+80 -49
View File
@@ -1,20 +1,19 @@
#ifndef DTOCONVERSIONS_H_
#define DTOCONVERSIONS_H_
#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"
#include "oatpp/core/data/mapping/ObjectMapper.hpp"
using model::User;
using model::Song;
using model::Token;
using model::RegisterResult;
using namespace model;
using namespace dto;
@@ -22,41 +21,31 @@ using namespace dto;
namespace dto { namespace conversion {
class DtoConversions {
public:
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User&, const model::Token&);
// static oatpp::data::mapping::type::ObjectWrapper<dto::LoginResultDto> toLoginResultDto(const model::User &user, const model::Token &token)
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const model::User &user, const model::Token &token)
// static dto::LoginResultDto::ObjectWrapper toLoginResultDto(const User &user, const Token &token)
template<typename D = LoginResultDto>
template<typename D = oatpp::Object<LoginResultDto>>
static D toLoginResultDto(const User &user, const Token &token)
{
// const model::Token& token) {
auto logRes = LoginResultDto::createShared();
/**
logRes->username = user.username.c_str();
logRes->token = token.accessToken.c_str();
logRes->token_type = token.tokenType.c_str();
logRes->expiration = token.expiration;
*/
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;
return logRes;
}
// static dto::RegisterResultDto::ObjectWrapper toRegisterResultDto(
template<typename D = RegisterResultDto>
template<typename D = oatpp::Object<RegisterResultDto>>
static D toRegisterResultDto(
const model::RegisterResult &regRes)
{
auto result = RegisterResultDto::createShared();
/**
result->message = regRes.message.c_str();
result->message = (!regRes.message.empty()) ? regRes.message.c_str() : "None";
result->registered = regRes.registered;
result->username = regRes.username.c_str();
*/
result->username = (!regRes.username.empty()) ? regRes.username.c_str() : "None";
return result;
}
// static dto::AlbumDto::ObjectWrapper toAlbumDto(const model::Album&);
template<typename D = oatpp::Object<AlbumDto>>
static D toAlbumDto(const Album &album)
{
@@ -69,11 +58,42 @@ namespace dto { namespace conversion {
return result;
}
template<typename D = SongDto>
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() : "";
@@ -85,42 +105,53 @@ namespace dto { namespace conversion {
result->track = (song.track != 0) ? song.track : 0;
result->disc = (song.disc != 0) ? song.disc : 0;
result->coverart_id = (song.coverArtId != 0) ? song.coverArtId : 0;
*/
return result;
}
// static model::Song toSong(dto::SongDto::ObjectWrapper&);
template<typename D = oatpp::Object<SongDto>, typename Song = Song>
static model::Song toSong(D songDto)
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;
int id = songDto->id;
song.id = (songDto->id.getPtr() == nullptr) ? 0 : id;
auto title = songDto->title.get();
/**
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();
*/
song.title = (songDto->title == nullptr) ? "" : songDto->title;
song.album = (songDto->album == nullptr) ? "" : songDto->album.c_str();
song.artist = (songDto->artist == nullptr) ? "" : songDto->artist.c_str();
song.albumArtist = (songDto->album_artist == nullptr) ?
"" : songDto->album_artist.c_str();
song.genre = (songDto->genre == nullptr) ? "" : songDto->genre.c_str();
song.year = (songDto->year.getPtr() == nullptr) ? 0 : songDto->year.getValue();
song.track = (songDto->track.getPtr() == nullptr) ? 0 : songDto->track.getValue();
song.disc = (songDto->disc.getPtr() == nullptr) ? 0 : songDto->disc.getValue();
song.coverArtId = (songDto->coverart_id.getPtr() == nullptr) ?
0 : songDto->coverart_id.getValue();
*/
return song;
}
// static model::User toUser(dto::UserDto::ObjectWrapper&);
template<typename D = UserDto>
static User toUser(D &userDto)
template<typename D = oatpp::Object<UserDto>>
static User toUser(const D &userDto)
{
model::User user;
User user;
int id = userDto->userId;
/**
user.id = (userDto->userId.getPtr() == nullptr) ? 0 : userDto->userId->getValue();
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();
+1 -7
View File
@@ -18,16 +18,14 @@
#include "component/AppComponent.hpp"
// #include "controller/ArtistController.hpp"
#include "controller/ArtistController.hpp"
#include "controller/AlbumController.hpp"
/**
#include "controller/CoverArtController.hpp"
#include "controller/GenreController.hpp"
#include "controller/LoginController.hpp"
#include "controller/RegisterController.hpp"
#include "controller/SongController.hpp"
#include "controller/YearController.hpp"
*/
#include "model/Models.h"
#include "verify/Initialization.h"
@@ -42,7 +40,6 @@ void run(const model::BinaryPath& bConf) {
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
auto albumController = std::make_shared<controller::AlbumController>(bConf);
/**
auto artistController = std::make_shared<controller::ArtistController>(bConf);
auto coverArtController = std::make_shared<controller::CoverArtController>(bConf);
auto gnrController = std::make_shared<controller::GenreController>(bConf);
@@ -50,10 +47,8 @@ void run(const model::BinaryPath& bConf) {
auto regController = std::make_shared<controller::RegisterController>(bConf);
auto sngController = std::make_shared<controller::SongController>(bConf);
auto yearController = std::make_shared<controller::YearController>(bConf);
*/
albumController->addEndpointsToRouter(router);
/**
artistController->addEndpointsToRouter(router);
coverArtController->addEndpointsToRouter(router);
gnrController->addEndpointsToRouter(router);
@@ -61,7 +56,6 @@ void run(const model::BinaryPath& bConf) {
regController->addEndpointsToRouter(router);
sngController->addEndpointsToRouter(router);
yearController->addEndpointsToRouter(router);
*/
// OATPP_COMPONENT(std::shared_ptr<oatpp::network::server::ConnectionHandler>, connectionHandler);