yacreader/YACReaderLibrary/server/controllers/v2/librariescontroller_v2.cpp
Felix Kauselmann 1b344d70e5 Update server code integration for QtWebApp 1.7.11
- Adapt server code for QtWebapp namespace 'stefanfrings'
- Implement custom modifications needed by v1 controller
  via template engine
- Unify iphone and ipad templates
2020-08-20 18:22:57 +02:00

40 lines
988 B
C++

#include "librariescontroller_v2.h"
#include "db_helper.h" //get libraries
#include "yacreader_libraries.h"
#include "template.h"
#include "../static.h"
#include "QsLog.h"
using stefanfrings::HttpRequest;
using stefanfrings::HttpResponse;
LibrariesControllerV2::LibrariesControllerV2() { }
void LibrariesControllerV2::service(HttpRequest & /* request */, HttpResponse &response)
{
response.setHeader("Content-Type", "application/json");
YACReaderLibraries libraries = DBHelper::getLibraries();
QList<QString> names = DBHelper::getLibrariesNames();
QJsonArray librariesJson;
int currentId = 0;
foreach (QString name, names) {
currentId = libraries.getId(name);
QJsonObject library;
library["name"] = name;
library["id"] = currentId;
librariesJson.append(library);
}
QJsonDocument output(librariesJson);
response.setStatus(200, "OK");
response.write(output.toJson(QJsonDocument::Compact), true);
}