minor changes
This commit is contained in:
@@ -13,22 +13,18 @@ namespace Managers
|
||||
class ActionManager
|
||||
{
|
||||
public:
|
||||
ActionManager(char**);
|
||||
ActionManager(char**, int);
|
||||
|
||||
Models::IcarusAction retrieveIcarusAction() const;
|
||||
std::vector<Models::Flags> retrieveFlags() const;
|
||||
std::string retrieveAction() const;
|
||||
private:
|
||||
bool isNumber(std::string);
|
||||
|
||||
void initialize();
|
||||
void validateAction();
|
||||
void validateFlags();
|
||||
|
||||
std::vector<std::string> parsedFlags();
|
||||
|
||||
void printAction();
|
||||
void printFlags(std::vector<std::string>);
|
||||
void printFlags();
|
||||
|
||||
std::string action;
|
||||
@@ -41,6 +37,7 @@ namespace Managers
|
||||
};
|
||||
std::vector<Models::Flags> flags;
|
||||
char **params;
|
||||
int paramCount;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Managers
|
||||
class CommitManager
|
||||
{
|
||||
public:
|
||||
CommitManager(Models::IcarusAction);
|
||||
CommitManager(Models::IcarusAction&);
|
||||
|
||||
void commitAction();
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace Managers
|
||||
private:
|
||||
Models::Token parseToken(Models::API);
|
||||
|
||||
void initializeMapActions();
|
||||
void deleteSong();
|
||||
void downloadSong();
|
||||
void retrieveObjects();
|
||||
@@ -39,7 +38,13 @@ namespace Managers
|
||||
uploadAct
|
||||
};
|
||||
|
||||
std::map<std::string, ActionValues> mapActions;
|
||||
std::map<std::string, ActionValues> mapActions =
|
||||
std::map<std::string, ActionValues>{
|
||||
{"delete", deleteAct}, {"download", downloadAct},
|
||||
{"retrieve", retrieveAct},
|
||||
{"upload", uploadAct}
|
||||
};
|
||||
|
||||
Models::IcarusAction icaAction;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Models
|
||||
std::string genre;
|
||||
int year;
|
||||
int duration;
|
||||
char *songData;
|
||||
std::string data;
|
||||
std::string songPath;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace Syncers
|
||||
Download(Models::API);
|
||||
Download(std::string);
|
||||
|
||||
void downloadSong(int);
|
||||
void downloadSong(const Models::Token token, Models::Song);
|
||||
private:
|
||||
std::string retrieveUrl(Models::Song);
|
||||
|
||||
@@ -18,29 +18,18 @@ namespace Syncers
|
||||
{
|
||||
public:
|
||||
Upload();
|
||||
Upload(std::string);
|
||||
Upload(Models::API);
|
||||
Upload(Models::UploadForm);
|
||||
|
||||
void uploadSong();
|
||||
void uploadSong(const Models::Token, Models::Song);
|
||||
private:
|
||||
Managers::FileManager fMgr;
|
||||
Models::API api;
|
||||
Models::Song song;
|
||||
std::string apiUrl{""}; // Not being used
|
||||
std::string apiEndPoint{""}; // Not being used
|
||||
std::string songPath; // Not being used
|
||||
std::string url; // Not being used
|
||||
int port{9349}; // Not being used
|
||||
|
||||
std::string retrieveUrl();
|
||||
|
||||
void configureSongDemo();
|
||||
void printSongDetails();
|
||||
void printJsonData(nlohmann::json);
|
||||
|
||||
nlohmann::json serializeObject(); // Not being used
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
ActionManager actMgr{argv};
|
||||
ActionManager actMgr{argv, argc};
|
||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||
|
||||
CommitManager commitMgr{chosenAction};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include<algorithm>
|
||||
#include<iostream>
|
||||
#include<exception>
|
||||
#include<utility>
|
||||
#include<cstring>
|
||||
|
||||
using std::cout;
|
||||
@@ -16,10 +16,9 @@ using Models::IcarusAction;
|
||||
namespace Managers
|
||||
{
|
||||
#pragma
|
||||
ActionManager::ActionManager(char **param)
|
||||
ActionManager::ActionManager(char **param, int paramCount) :
|
||||
params(std::move(param)), paramCount(paramCount)
|
||||
{
|
||||
this->params = param;
|
||||
|
||||
initialize();
|
||||
}
|
||||
#pragma Constructors
|
||||
@@ -34,15 +33,6 @@ namespace Managers
|
||||
|
||||
return icarusAction;
|
||||
}
|
||||
vector<Flags> ActionManager::retrieveFlags() const
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
string ActionManager::retrieveAction() const
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
bool ActionManager::isNumber(string val)
|
||||
{
|
||||
@@ -57,28 +47,10 @@ namespace Managers
|
||||
{
|
||||
validateFlags();
|
||||
|
||||
action = string{params[1]};
|
||||
action = std::move(string{params[1]});
|
||||
transform(action.begin(), action.end(),
|
||||
action.begin(), ::tolower);
|
||||
}
|
||||
void ActionManager::validateAction()
|
||||
{
|
||||
cout<<"Validating action"<<endl;
|
||||
|
||||
if (std::any_of(supportedActions.begin(), supportedActions.end(),
|
||||
[&](string val)
|
||||
{
|
||||
return !val.compare(action);
|
||||
}))
|
||||
{
|
||||
//cout<<"Action: "<<action<<" is valid"<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Action is not valid"<<endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
void ActionManager::validateFlags()
|
||||
{
|
||||
cout<<"Validating flags"<<endl;
|
||||
@@ -118,19 +90,10 @@ namespace Managers
|
||||
vector<string> ActionManager::parsedFlags()
|
||||
{
|
||||
auto parsed = vector<string>{};
|
||||
try
|
||||
|
||||
for (auto i = 2; i < paramCount; ++i)
|
||||
{
|
||||
for (auto i = 2; true; ++i)
|
||||
{
|
||||
string val{*(params + i)};
|
||||
//cout<<"Parsed flag "<<val<<endl;
|
||||
parsed.push_back(val);
|
||||
}
|
||||
}
|
||||
catch (std::exception e)
|
||||
{
|
||||
auto msg = e.what();
|
||||
cout<<"This happend: "<<msg<<endl<<endl;
|
||||
parsed.push_back(std::move(*(params + i)));
|
||||
}
|
||||
|
||||
return parsed;
|
||||
@@ -148,21 +111,6 @@ namespace Managers
|
||||
cout<<"Action is "<<action<<endl;
|
||||
}
|
||||
}
|
||||
void ActionManager::printFlags(vector<string> flagVals)
|
||||
{
|
||||
if (flagVals.empty())
|
||||
{
|
||||
printf("Flags and values are empty\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Printing flags and values..\n");
|
||||
for (auto flgVal : flagVals)
|
||||
{
|
||||
cout<<flgVal<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ActionManager::printFlags()
|
||||
{
|
||||
cout<<"\nPrinting flags..."<<endl;
|
||||
|
||||
@@ -34,11 +34,8 @@ using Syncers::Upload;
|
||||
namespace Managers
|
||||
{
|
||||
#pragma
|
||||
CommitManager::CommitManager(IcarusAction icaAct)
|
||||
{
|
||||
icaAction = icaAct;
|
||||
initializeMapActions();
|
||||
}
|
||||
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
||||
{ }
|
||||
#pragma Constructors;
|
||||
|
||||
|
||||
@@ -46,7 +43,7 @@ namespace Managers
|
||||
void CommitManager::commitAction()
|
||||
{
|
||||
auto action = icaAction.action;
|
||||
cout<<"Commitning "<<action<<" action"<<endl;
|
||||
cout<<"Commiting "<<action<<" action"<<endl;
|
||||
switch (mapActions[action])
|
||||
{
|
||||
case deleteAct:
|
||||
@@ -55,7 +52,7 @@ namespace Managers
|
||||
case downloadAct:
|
||||
downloadSong();
|
||||
break;
|
||||
case retrieveAct: // No plans to imeplement
|
||||
case retrieveAct:
|
||||
retrieveObjects();
|
||||
break;
|
||||
case uploadAct:
|
||||
@@ -75,14 +72,6 @@ namespace Managers
|
||||
return tk.requestToken();
|
||||
}
|
||||
|
||||
void CommitManager::initializeMapActions()
|
||||
{
|
||||
mapActions = map<string, ActionValues>{
|
||||
{"delete", deleteAct}, {"download", downloadAct},
|
||||
{"retrieve", retrieveAct},
|
||||
{"upload", uploadAct}
|
||||
};
|
||||
}
|
||||
void CommitManager::deleteSong()
|
||||
{
|
||||
APIParser apiPrs{icaAction};
|
||||
|
||||
@@ -11,9 +11,8 @@ using Models::IcarusAction;
|
||||
namespace Parsers
|
||||
{
|
||||
#pragma
|
||||
APIParser::APIParser(IcarusAction icaAct)
|
||||
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
||||
{
|
||||
this->icaAct = icaAct;
|
||||
api = API{};
|
||||
parseAPI();
|
||||
}
|
||||
@@ -38,7 +37,7 @@ namespace Parsers
|
||||
|
||||
if (arg.compare("-h") == 0)
|
||||
{
|
||||
api.url = (value[value.size()-1 == '/']) ? value : value + "/";
|
||||
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,26 +33,6 @@ namespace Syncers
|
||||
|
||||
|
||||
#pragma
|
||||
void Download::downloadSong(const int id)
|
||||
{
|
||||
string urlRoot = "http://192.168.1.5";
|
||||
int port = 9349;
|
||||
string endpoint = "api/song/data/" + std::to_string(id);
|
||||
string url = urlRoot + ":" + std::to_string(port) + "/" +
|
||||
endpoint;
|
||||
auto r = cpr::Get(cpr::Url{url});
|
||||
const char* newBuff = r.text.c_str();
|
||||
int bufferLength = r.text.size();
|
||||
|
||||
ofstream saveSong{downloadFilePath, ofstream::binary};
|
||||
saveSong.write(newBuff, bufferLength);
|
||||
|
||||
cout<<"HTTP status code: "<<r.status_code<<endl;
|
||||
cout<<"Header info: "<<r.header["content-type"]<<endl;
|
||||
cout<<"Header info: "<<endl;
|
||||
cout<<r.header["content-type"]<<endl;
|
||||
cout<<r.header["content-disposition"]<<endl;
|
||||
}
|
||||
void Download::downloadSong(const Token token, Song song)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <cpr/cpr.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "Utilities/Conversions.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::ofstream;
|
||||
@@ -13,6 +15,7 @@ using std::ofstream;
|
||||
using Managers::CommitManager;
|
||||
using Models::API;
|
||||
using Models::Token;
|
||||
using Utilities::Conversions;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
|
||||
+3
-68
@@ -24,41 +24,12 @@ using namespace cpr;
|
||||
namespace Syncers
|
||||
{
|
||||
Upload::Upload() { }
|
||||
Upload::Upload(string filePath)
|
||||
Upload::Upload(API api) : api(api)
|
||||
{
|
||||
this->songPath = filePath;
|
||||
this->fMgr = FileManager(songPath);
|
||||
}
|
||||
Upload::Upload(API api)
|
||||
{
|
||||
this->api = api;
|
||||
this->api.endpoint = "song/data";
|
||||
}
|
||||
Upload::Upload(UploadForm formData)
|
||||
{
|
||||
this->url = formData.url;
|
||||
this->songPath = formData.filePath;
|
||||
}
|
||||
|
||||
|
||||
void Upload::uploadSong()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto r = cpr::Post(cpr::Url{url},
|
||||
cpr::Multipart{{"key", "small value"},
|
||||
{"file", cpr::File{songPath}}});
|
||||
cout << r.status_code<< std::endl;
|
||||
|
||||
cout<<"Success"<<endl;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
cout<<e.what()<<endl;
|
||||
}
|
||||
cout<<"Finished"<<endl;
|
||||
|
||||
}
|
||||
void Upload::uploadSong(const Models::Token token, Song song)
|
||||
{
|
||||
try
|
||||
@@ -86,33 +57,12 @@ namespace Syncers
|
||||
|
||||
string Upload::retrieveUrl()
|
||||
{
|
||||
string url = api.url + "api/" + api.version + "/" +
|
||||
api.endpoint;
|
||||
const string url{api.url + "api/" + api.version + "/" +
|
||||
api.endpoint};
|
||||
|
||||
return url;
|
||||
}
|
||||
#pragma
|
||||
void Upload::configureSongDemo()
|
||||
{
|
||||
int id = 0;
|
||||
string title = "What of it?";
|
||||
string artist = "Kuoth";
|
||||
string album = "I";
|
||||
string genre = "Untitled";
|
||||
int year = 2019;
|
||||
int duration = 260;
|
||||
|
||||
this->song = Models::Song{};
|
||||
this->song.id = id;
|
||||
this->song.title = title;
|
||||
this->song.artist = artist;
|
||||
this->song.album = album;
|
||||
this->song.genre = genre;
|
||||
this->song.year = year;
|
||||
this->song.duration = duration;
|
||||
this->song.songData = fMgr.retrieveFileBuffer();
|
||||
cout<<*song.songData<<endl;
|
||||
}
|
||||
void Upload::printSongDetails()
|
||||
{
|
||||
cout<<"Song details: "<<endl;
|
||||
@@ -138,21 +88,6 @@ namespace Syncers
|
||||
|
||||
cout<<endl<<endl;;
|
||||
}
|
||||
|
||||
json Upload::serializeObject()
|
||||
{
|
||||
json jObj{};
|
||||
jObj["id"] = song.id;
|
||||
jObj["title"] = song.title;
|
||||
jObj["artist"] = song.artist;
|
||||
jObj["album"] = song.album;
|
||||
jObj["genre"] = song.genre;
|
||||
jObj["year"] = song.year;
|
||||
jObj["duration"] = song.duration;
|
||||
jObj["song_data"] = *song.songData;
|
||||
|
||||
return jObj;
|
||||
}
|
||||
#pragma Testing
|
||||
#pragma Functions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user