Need to work on the ability to fetch records for Artist, Genre, and Year

This commit is contained in:
kdeng00
2019-09-06 22:38:14 -04:00
parent de838da040
commit e9241cf6a5
8 changed files with 200 additions and 6 deletions
+5
View File
@@ -27,6 +27,7 @@ set(SOURCES
)
set(HEADERS
include/component/AppComponent.hpp
include/controller/AlbumController.hpp
include/controller/CoverArtController.hpp
include/controller/LoginController.hpp
include/controller/SongController.hpp
@@ -37,9 +38,13 @@ set(HEADERS
include/database/GenreRepository.h
include/database/SongRepository.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/manager/AlbumManager.h
include/manager/ArtistManager.h
include/manager/CoverArtManager.h
+92
View File
@@ -0,0 +1,92 @@
#ifndef COVERARTCONTROLLER_H_
#define COVERARTCONTROLLER_H_
#include <filesystem>
#include <iostream>
#include <fstream>
#include <limits>
#include <string>
#include <memory>
#include <vector>
#include "oatpp/core/data/stream/ChunkedBuffer.hpp"
#include "oatpp/core/data/stream/FileStream.hpp"
#include "oatpp/core/macro/codegen.hpp"
#include "oatpp/core/macro/component.hpp"
#include "oatpp/web/mime/multipart/InMemoryPartReader.hpp"
#include "oatpp/web/mime/multipart/Reader.hpp"
#include "oatpp/web/server/api/ApiController.hpp"
#include "database/AlbumRepository.h"
#include "dto/AlbumDto.hpp"
#include "manager/AlbumManager.h"
#include "model/Models.h"
#include "type/Scopes.h"
#include "type/AlbumFilter.h"
namespace fs = std::filesystem;
namespace controller
{
class AlbumController : public oatpp::web::server::api::ApiController
{
public:
AlbumController(std::string p, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_exe_path(p)
{ }
AlbumController(const model::BinaryPath& bConf, OATPP_COMPONENT(std::shared_ptr<ObjectMapper>, objectMapper))
: oatpp::web::server::api::ApiController(objectMapper), m_bConf(bConf)
{ }
#include OATPP_CODEGEN_BEGIN(ApiController)
// endpoint for retrieving all album records in json format
ENDPOINT("GET", "/api/v1/album", albumRecords,
REQUEST(std::shared_ptr<IncomingRequest>, request))
{
std::cout << "starting process of retrieving album" << std::endl;
database::AlbumRepository albRepo(m_bConf);
auto albsDb = albRepo.retrieveRecords();
auto albums = oatpp::data::mapping::type::List<dto::AlbumDto::ObjectWrapper>::createShared();
for (auto& albDb : albsDb) {
auto alb = dto::AlbumDto::createShared();
alb->id = albDb.id;
alb->title = albDb.songTitle.c_str();
alb->year = albDb.year;
albums->pushBack(alb);
}
return createDtoResponse(Status::CODE_200, albums);
}
// endpoint for retrieving single album record by the album id in json format
ENDPOINT("GET", "/api/v1/album/{id}", albumRecord,
PATH(Int32, id)) {
database::AlbumRepository albRepo(m_bConf);
model::Album albDb(id);
OATPP_ASSERT_HTTP(albRepo.doesAlbumExist(albDb, type::AlbumFilter::id) , Status::CODE_403, "album does not exist");
std::cout << "album exists" << std::endl;
albDb = albRepo.retrieveRecord(albDb, type::AlbumFilter::id);
auto album = dto::AlbumDto::createShared();
album->id = albDb.id;
album->title = albDb.songTitle.c_str();
album->year = albDb.year;
return createDtoResponse(Status::CODE_200, album);
}
#include OATPP_CODEGEN_END(ApiController)
private:
std::string m_exe_path;
model::BinaryPath m_bConf;
const long m_dataSize = std::numeric_limits<long long int>::max();
};
}
#endif
+3 -5
View File
@@ -114,8 +114,7 @@ namespace controller
PATH(Int32, id)) {
database::SongRepository songRepo(m_bConf);
model::Song songDb;
songDb.id = id;
model::Song songDb(id);
OATPP_ASSERT_HTTP(songRepo.doesSongExist(songDb, type::SongFilter::id) , Status::CODE_403, "song does not exist");
@@ -140,8 +139,7 @@ namespace controller
PATH(Int32, id)) {
database::SongRepository songRepo(m_bConf);
model::Song songDb;
songDb.id = id;
model::Song songDb(id);
songDb = songRepo.retrieveRecord(songDb, type::SongFilter::id);
std::ifstream fl(songDb.songPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
@@ -153,7 +151,7 @@ namespace controller
std::ostreambuf_iterator<char>(buf));
fl.close();
// TODO: no need to make this shared
// TODO: no need to make this shared. Why? Because it already is. Sharing shared? Like wetting water
auto rawSong = std::make_shared<oatpp::String>(oatpp::String(buf.str().data(), (v_int32)buf.str().size(), true));
auto response = createResponse(Status::CODE_200, *rawSong);
+23
View File
@@ -0,0 +1,23 @@
#ifndef ALBUMDTO_H_
#define ALBUMDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class AlbumDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(AlbumDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(String, title);
DTO_FIELD(Int32, year);
};
#include OATPP_CODEGEN_END(DTO)
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef ARTISTDTO_H_
#define ARTISTDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class ArtistDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(ArtistDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(String, artist);
};
#include OATPP_CODEGEN_END(DTO)
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef GENREDTO_H_
#define GENREDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class GenreDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(GenreDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(String, category);
};
#include OATPP_CODEGEN_END(DTO)
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef YEARDTO_H_
#define YEARDTO_H_
#include "oatpp/core/data/mapping/type/Object.hpp"
#include "oatpp/core/macro/codegen.hpp"
namespace dto
{
#include OATPP_CODEGEN_BEGIN(DTO)
class YearDto : public oatpp::data::mapping::type::Object
{
DTO_INIT(YearDto, Object)
DTO_FIELD(Int32, id);
DTO_FIELD(Int32, year);
};
#include OATPP_CODEGEN_END(DTO)
}
#endif
+11 -1
View File
@@ -8,7 +8,10 @@ namespace model
{
struct Song
{
int id;
Song() = default;
Song(const int id) : id(id) { }
int id;
std::string title;
std::string artist;
std::string album;
@@ -34,6 +37,9 @@ namespace model
struct Album
{
Album() = default;
Album(const int id) : id(id) { }
int id;
std::string title;
int year;
@@ -55,6 +61,9 @@ namespace model
struct Cover
{
Cover() = default;
Cover(const int id) : id(id) { }
int id;
std::string songTitle;
std::string imagePath;
@@ -96,6 +105,7 @@ namespace model
BinaryPath(const char *p) : path(std::move(p)) { }
BinaryPath(std::string& p) : path(std::move(p)) { }
BinaryPath(const std::string& p) : path(std::move(p)) { }
std::string path;
};
}