1 #include "tagscontroller_v2.h" 2 3 #include "db_helper.h" 4 #include "yacreader_libraries.h" 5 6 #include "reading_list.h" 7 #include "../static.h" 8 #include "yacreader_global.h" 9 10 #include "yacreader_server_data_helper.h" 11 12 #include "QsLog.h" 13 14 using stefanfrings::HttpRequest; 15 using stefanfrings::HttpResponse; 16 TagsControllerV2()17TagsControllerV2::TagsControllerV2() { } 18 service(HttpRequest & request,HttpResponse & response)19void TagsControllerV2::service(HttpRequest &request, HttpResponse &response) 20 { 21 response.setHeader("Content-Type", "text/plain; charset=utf-8"); 22 23 QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); 24 QStringList pathElements = path.split('/'); 25 int libraryId = pathElements.at(3).toInt(); 26 27 QList<Label> labels = DBHelper::getLabels(libraryId); 28 29 QJsonArray items; 30 31 for (QList<Label>::const_iterator itr = labels.constBegin(); itr != labels.constEnd(); itr++) { 32 items.append(YACReaderServerDataHelper::labelToJSON(libraryId, *itr)); 33 } 34 35 QJsonDocument output(items); 36 37 response.write(output.toJson(QJsonDocument::Compact)); 38 ; 39 } 40