1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#pragma once
#ifdef USE_WEBSERVER
#include <cpprest/http_listener.h>
#include <cpprest/filestream.h>
#include "screen_playlist.hh"
class RequestHandler
{
public:
RequestHandler(Songs& songs);
RequestHandler(std::string url, Songs& songs);
virtual ~RequestHandler();
pplx::task<void>open() { return m_listener.open(); }
pplx::task<void>close() { return m_listener.close(); }
protected:
private:
void Get(web::http::http_request request);
void Put(web::http::http_request request);
void Post(web::http::http_request request);
void Delete(web::http::http_request request);
void Error(pplx::task<void>& t);
web::json::value ExtractJsonFromRequest(web::http::http_request request);
void HandleFile(web::http::http_request request, std::string filePath = "");
web::json::value SongsToJsonObject();
std::map<std::string, std::string> GenerateLocaleDict();
std::vector<std::string> GetTranslationKeys();
std::shared_ptr<Song> GetSongFromJSON(web::json::value);
web::http::experimental::listener::http_listener m_listener;
Songs& m_songs;
};
#else
class Songs;
class RequestHandler
{
public:
RequestHandler(Songs&) {}
};
#endif
|