Switching to C++ #60

Merged
kdeng00 merged 36 commits from experiment into master 2019-09-03 16:17:20 -04:00
30 changed files with 233 additions and 59 deletions
Showing only changes of commit dfd4906371 - Show all commits
+17
View File
@@ -0,0 +1,17 @@
#ifndef ALBUMREPOSITORY_H_
#define ALBUMREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
namespace Database
{
class albumRepository : public base_repository
{
public:
albumRepository(const Model::BinaryPath&);
private:
};
}
#endif
+1 -1
View File
@@ -15,7 +15,7 @@ namespace Database
coverArtRepository(const std::string&);
coverArtRepository(const Model::BinaryPath&);
Model::Cover retrieveRecord(Model::Cover&, coverFilter);
Model::Cover retrieveRecord(Model::Cover&, Type::coverFilter);
void deleteRecord(const Model::Cover&);
void saveRecord(const Model::Cover&);
+17
View File
@@ -0,0 +1,17 @@
#ifndef GENREREPOSITORY_H_
#define GENREREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
namespace Database
{
class genreRepository : public base_repository
{
public:
genreRepository(const Model::BinaryPath&);
private:
};
}
#endif
+1 -1
View File
@@ -20,7 +20,7 @@ namespace Database
std::vector<Model::Song> retrieveRecords();
Model::Song retrieveRecord(Model::Song&, songFilter);
Model::Song retrieveRecord(Model::Song&, Type::songFilter);
void deleteRecord(const Model::Song&);
void saveRecord(const Model::Song&);
+17
View File
@@ -0,0 +1,17 @@
#ifndef YEARREPOSITORY_H_
#define YEARREPOSITORY_H_
#include "database/base_repository.h"
#include "models/models.h"
namespace Database
{
class yearRepository : public base_repository
{
public:
yearRepository(const Model::BinaryPath&);
private:
};
}
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef ALBUMMANAGER_H_
#define ALBUMMANAGER_H_
#include "models/models.h"
namespace Manager
{
class albumManager
{
public:
albumManager(const Model::BinaryPath&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef ARTISTMANAGER_H_
#define ARTISTMANAGER_H_
#include "models/models.h"
namespace Manager
{
class artistManager
{
public:
artistManager(const Model::BinaryPath&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef GENREMANAGER_H_
#define GENREMANAGER_H_
#include "models/models.h"
namespace Manager
{
class genreManager
{
public:
genreManager(const Model::BinaryPath&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
+1 -1
View File
@@ -22,7 +22,7 @@ namespace Manager
Model::loginResult retrieve_token(std::string_view);
Model::loginResult retrieve_token(const Model::BinaryPath&);
bool is_token_valid(std::string&, Scope);
bool is_token_valid(std::string&, Type::Scope);
private:
Model::auth_credentials parse_auth_credentials(std::string_view);
Model::auth_credentials parse_auth_credentials(const Model::BinaryPath&);
+17
View File
@@ -0,0 +1,17 @@
#ifndef YEARMANAGER_H_
#define YEARMANAGER_H_
#include "models/models.h"
namespace Manager
{
class yearManager
{
public:
yearManager(const Model::BinaryPath&);
private:
Model::BinaryPath m_bConf;
};
}
#endif
+8 -5
View File
@@ -1,11 +1,14 @@
#ifndef COVERFILTER_H_
#define COVERFILTER_H_
enum class coverFilter
namespace Type
{
id = 0,
songTitle,
imagePath
};
enum class coverFilter
{
id = 0,
songTitle,
imagePath
};
}
#endif
+7 -4
View File
@@ -1,10 +1,13 @@
#ifndef SCOPES_H_
#define SCOPES_H_
enum class Scope
namespace Type
{
upload = 0,
download
};
enum class Scope
{
upload = 0,
download
};
}
#endif
+11 -8
View File
@@ -1,14 +1,17 @@
#ifndef SONGFILTER_H_
#define SONGFILTER_H_
enum class songFilter
namespace Type
{
id = 0,
title,
album,
artist,
genre,
year
};
enum class songFilter
{
id = 0,
title,
album,
artist,
genre,
year
};
}
#endif
+17 -9
View File
@@ -1,3 +1,6 @@
#ifndef IMAGEFILE_H_
#define IMAGEFILE_H_
#include <iostream>
#include <attachedpictureframe.h>
@@ -10,15 +13,20 @@
#include <tpropertymap.h>
#include <id3v2tag.h>
class imageFile : public TagLib::File
namespace Utility
{
public:
imageFile(const char *file);
class imageFile : public TagLib::File
{
public:
imageFile(const char *file);
TagLib::ByteVector data();
TagLib::ByteVector data();
private:
virtual TagLib::Tag *tag() const { return 0; }
virtual TagLib::AudioProperties *audioProperties() const { return 0; }
virtual bool save() { return false; }
};
private:
virtual TagLib::Tag *tag() const { return 0; }
virtual TagLib::AudioProperties *audioProperties() const { return 0; }
virtual bool save() { return false; }
};
}
#endif
+10 -7
View File
@@ -6,14 +6,17 @@
#include "models/models.h"
class metadata_retriever
namespace Utility
{
public:
Model::Song retrieve_metadata(std::string&);
Model::Cover update_cover_art(const Model::Song&, Model::Cover& cov, const std::string&);
class metadata_retriever
{
public:
Model::Song retrieve_metadata(std::string&);
Model::Cover update_cover_art(const Model::Song&, Model::Cover& cov, const std::string&);
void update_metadata(Model::Song updated_song, const Model::Song old_song);
private:
};
void update_metadata(Model::Song updated_song, const Model::Song old_song);
private:
};
}
#endif
+3 -3
View File
@@ -53,7 +53,7 @@ namespace Controller
auto auth = authHeader->std_str();
Manager::token_manager tok;
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Scope::upload), Status::CODE_403, "Not allowed");
OATPP_ASSERT_HTTP(tok.is_token_valid(auth, Type::Scope::upload), Status::CODE_403, "Not allowed");
auto mp = std::make_shared<oatpp::web::mime::multipart::Multipart>(request->getHeaders());
@@ -117,7 +117,7 @@ namespace Controller
Model::Song songDb;
songDb.id = id;
songDb = songRepo.retrieveRecord(songDb, songFilter::id);
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
auto song = songDto::createShared();
song->id = songDb.id;
@@ -139,7 +139,7 @@ namespace Controller
Database::songRepository songRepo(m_bConf);
Model::Song songDb;
songDb.id = id;
songDb = songRepo.retrieveRecord(songDb, songFilter::id);
songDb = songRepo.retrieveRecord(songDb, Type::songFilter::id);
std::ifstream fl(songDb.songPath.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
fl.seekg(0);
+5
View File
@@ -0,0 +1,5 @@
#include "database/albumRepository.h"
Database::albumRepository::albumRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
{ }
+4 -4
View File
@@ -11,7 +11,7 @@ Database::coverArtRepository::coverArtRepository(const std::string& path) : base
Database::coverArtRepository::coverArtRepository(const Model::BinaryPath& bConf) : base_repository(bConf)
{ }
Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, coverFilter filter = coverFilter::id)
Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, Type::coverFilter filter = Type::coverFilter::id)
{
std::stringstream qry;
auto conn = setup_mysql_connection();
@@ -19,16 +19,16 @@ Model::Cover Database::coverArtRepository::retrieveRecord(Model::Cover& cov, cov
std::unique_ptr<char*> param;
switch (filter) {
case coverFilter::id:
case Type::coverFilter::id:
qry << "CoverArtId = " << cov.id;
break;
case coverFilter::songTitle:
case Type::coverFilter::songTitle:
param = std::make_unique<char*>(new char[cov.songTitle.size()]);
mysql_real_escape_string(conn, *param, cov.songTitle.c_str(), cov.songTitle.size());
std::cout << *param << std::endl;
qry << "SongTitle = '" << *param << "'";
break;
case coverFilter::imagePath:
case Type::coverFilter::imagePath:
param = std::make_unique<char*>(new char[cov.imagePath.size()]);
mysql_real_escape_string(conn, *param, cov.imagePath.c_str(), cov.imagePath.size());
std::cout << *param << std::endl;
+5
View File
@@ -0,0 +1,5 @@
#include "database/genreRepository.h"
Database::genreRepository::genreRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
{ }
+3 -3
View File
@@ -27,7 +27,7 @@ std::vector<Model::Song> Database::songRepository::retrieveRecords()
return songs;
}
Model::Song Database::songRepository::retrieveRecord(Model::Song& song, songFilter filter)
Model::Song Database::songRepository::retrieveRecord(Model::Song& song, Type::songFilter filter)
{
std::stringstream qry;
auto conn = setup_mysql_connection();
@@ -35,10 +35,10 @@ Model::Song Database::songRepository::retrieveRecord(Model::Song& song, songFilt
std::unique_ptr<char*> param;
switch (filter) {
case songFilter::id:
case Type::songFilter::id:
qry << "SongId = " << song.id;
break;
case songFilter::title:
case Type::songFilter::title:
param = std::make_unique<char*>(new char[song.title.size()]);
mysql_real_escape_string(conn, *param, song.title.c_str(), song.title.size());
std::cout << *param << std::endl;
+5
View File
@@ -0,0 +1,5 @@
#include "database/yearRepository.h"
Database::yearRepository::yearRepository(const Model::BinaryPath& bConf)
: base_repository(bConf)
{ }
+5
View File
@@ -0,0 +1,5 @@
#include "managers/albumManager.h"
Manager::albumManager::albumManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
+5
View File
@@ -0,0 +1,5 @@
#include "managers/artistManager.h"
Manager::artistManager::artistManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
+2 -2
View File
@@ -13,7 +13,7 @@ Manager::coverArtManager::coverArtManager(const Model::BinaryPath& bConf) : m_bC
Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::string& rootPath, const std::string& stockCoverPath)
{
metadata_retriever meta;
Utility::metadata_retriever meta;
Model::Cover cov;
cov.imagePath = rootPath;
cov = meta.update_cover_art(song, cov, stockCoverPath);
@@ -23,7 +23,7 @@ Model::Cover Manager::coverArtManager::saveCover(const Model::Song& song, std::s
std::cout << "saving record to the database" << std::endl;
covRepo.saveRecord(cov);
std::cout << "retrieving record from database" << std::endl;
cov = covRepo.retrieveRecord(cov, coverFilter::songTitle);
cov = covRepo.retrieveRecord(cov, Type::coverFilter::songTitle);
return cov;
}
+5
View File
@@ -0,0 +1,5 @@
#include "managers/genreManager.h"
Manager::genreManager::genreManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
+3 -3
View File
@@ -26,7 +26,7 @@ Manager::song_manager::song_manager(const Model::BinaryPath& bConf)
void Manager::song_manager::saveSong(Model::Song& song)
{
saveSongTemp(song);
metadata_retriever meta;
Utility::metadata_retriever meta;
auto data = std::move(song.data);
song = meta.retrieve_metadata(song.songPath);
song.data = std::move(data);
@@ -62,12 +62,12 @@ void Manager::song_manager::deleteSong(Model::Song& song)
Database::coverArtRepository covRepo(m_bConf);
Database::songRepository songRepo(m_bConf);
song = songRepo.retrieveRecord(song, songFilter::id);
song = songRepo.retrieveRecord(song, Type::songFilter::id);
songRepo.deleteRecord(song);
Model::Cover cov;
cov.id = song.coverArtId;
cov = covRepo.retrieveRecord(cov, coverFilter::id);
cov = covRepo.retrieveRecord(cov, Type::coverFilter::id);
covRepo.deleteRecord(cov);
auto paths = Manager::directory_manager::pathConfigContent(m_bConf);
+3 -3
View File
@@ -86,7 +86,7 @@ Model::loginResult Manager::token_manager::retrieve_token(const Model::BinaryPat
return lr;
}
bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
bool Manager::token_manager::is_token_valid(std::string& auth, Type::Scope scope)
{
auto authPair = fetch_auth_header(auth);
@@ -103,10 +103,10 @@ bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
auto scopes = extract_scopes(jwt::decode(token));
switch (scope) {
case Scope::upload:
case Type::Scope::upload:
return token_supports_scope(scopes, "upload:songs");
break;
case Scope::download:
case Type::Scope::download:
return token_supports_scope(scopes, "download:songs");
default:
break;
+5
View File
@@ -0,0 +1,5 @@
#include "managers/yearManager.h"
Manager::yearManager::yearManager(const Model::BinaryPath& bConf)
: m_bConf(bConf)
{ }
+2 -2
View File
@@ -1,10 +1,10 @@
#include "utilities/imageFile.h"
imageFile::imageFile(const char *file) : TagLib::File(file)
Utility::imageFile::imageFile(const char *file) : TagLib::File(file)
{
}
TagLib::ByteVector imageFile::data()
TagLib::ByteVector Utility::imageFile::data()
{
return readBlock(length());
}
+3 -3
View File
@@ -17,7 +17,7 @@
namespace fs = std::filesystem;
Model::Song metadata_retriever::retrieve_metadata(std::string& song_path)
Model::Song Utility::metadata_retriever::retrieve_metadata(std::string& song_path)
{
TagLib::FileRef file(song_path.c_str());
Model::Song song;
@@ -48,7 +48,7 @@ Model::Song metadata_retriever::retrieve_metadata(std::string& song_path)
return song;
}
Model::Cover metadata_retriever::update_cover_art(const Model::Song& song, Model::Cover& cov, const std::string& stockCoverPath)
Model::Cover Utility::metadata_retriever::update_cover_art(const Model::Song& song, Model::Cover& cov, const std::string& stockCoverPath)
{
TagLib::MPEG::File sngF(song.songPath.c_str());
auto tag = sngF.ID3v2Tag();
@@ -94,7 +94,7 @@ Model::Cover metadata_retriever::update_cover_art(const Model::Song& song, Model
return cov;
}
void metadata_retriever::update_metadata(Model::Song sng_updated, const Model::Song sng_old)
void Utility::metadata_retriever::update_metadata(Model::Song sng_updated, const Model::Song sng_old)
{
std::cout<<"updating metadata"<<std::endl;
TagLib::FileRef file(sng_old.songPath.c_str());