mirror of
https://github.com/YACReader/yacreader
synced 2025-07-14 11:04:25 -04:00
added a new controller for serving the tags in a library
This commit is contained in:
30
YACReaderLibrary/server/controllers/tagscontroller.cpp
Normal file
30
YACReaderLibrary/server/controllers/tagscontroller.cpp
Normal 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);
|
||||
}
|
22
YACReaderLibrary/server/controllers/tagscontroller.h
Normal file
22
YACReaderLibrary/server/controllers/tagscontroller.h
Normal 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
|
Reference in New Issue
Block a user