added a new controller for serving the tags in a library

This commit is contained in:
Luis Ángel San Martín
2016-01-25 22:23:49 +01:00
parent cfffc1bae8
commit 4350d6797e
6 changed files with 119 additions and 3 deletions

View File

@ -0,0 +1,30 @@
#include "tagscontroller.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
#include "reading_list_item.h"
#include "../static.h"
#include "yacreader_global.h"
#include "QsLog.h"
TagsController::TagsController() {}
void TagsController::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();
QList<LabelItem *> tags = DBHelper::getLabelItems(libraryId);
foreach(LabelItem * tag, tags)
{
response.writeText(QString("%1\t%2\t%3\r\n").arg(tag->getId()).arg(tag->name()).arg(labelColorToRGBString(tag->colorid())));
}
response.writeText("",true);
}

View File

@ -0,0 +1,22 @@
#ifndef TAGSCONTROLLER_H
#define TAGSCONTROLLER_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class TagsController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(TagsController)
public:
/** Constructor */
TagsController();
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
};
#endif // TAGSCONTROLLER_H