Add new class for serving the content of tag.

This commit is contained in:
Luis Ángel San Martín 2016-08-22 23:05:36 +02:00
parent 1d73d1f1bf
commit 4e50c5628d
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#include "tagcontentcontroller.h"
#include "db_helper.h"
#include "comic_db.h"
#include "yacreader_server_data_helper.h"
#include <QUrl>
TagContentController::TagContentController()
{
}
void TagContentController::service(HttpRequest &request, HttpResponse &response)
{
response.setHeader("Content-Type", "text/plain; charset=utf-8");
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
int libraryId = pathElements.at(2).toInt();
qulonglong tagId = pathElements.at(4).toULongLong();
serviceContent(libraryId, tagId, response);
response.write("",true);
}
void TagContentController::serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response)
{
QList<ComicDB> tagComics = DBHelper::getLabelComics(library, tagId);
for(const ComicDB &comic : tagComics)
{
response.write(YACReaderServerDataHelper::comicToYSFormat(library, comic).toUtf8());
}
}

View File

@ -0,0 +1,22 @@
#ifndef TAGCONTENTCONTROLLER_H
#define TAGCONTENTCONTROLLER_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class TagContentController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(TagContentController);
public:
/** Constructor */
TagContentController();
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
private:
void serviceContent(const int &library, const qulonglong &tagId, HttpResponse &response);
};
#endif // TAGCONTENTCONTROLLER_H