yacreader/YACReaderLibrary/server/controllers/v2/readinglistcontentcontroller_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

43 lines
1.2 KiB
C++

#include "readinglistcontentcontroller_v2.h"
#include "db_helper.h"
#include "comic_db.h"
#include "yacreader_server_data_helper.h"
using stefanfrings::HttpRequest;
using stefanfrings::HttpResponse;
ReadingListContentControllerV2::ReadingListContentControllerV2()
{
}
void ReadingListContentControllerV2::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(3).toInt();
qulonglong readingListId = pathElements.at(5).toULongLong();
serviceContent(libraryId, readingListId, response);
response.write("", true);
}
void ReadingListContentControllerV2::serviceContent(const int &library, const qulonglong &readingListId, HttpResponse &response)
{
QList<ComicDB> comics = DBHelper::getReadingListFullContent(library, readingListId);
QJsonArray items;
for (const ComicDB &comic : comics) {
items.append(YACReaderServerDataHelper::comicToJSON(library, comic));
}
QJsonDocument output(items);
response.write(output.toJson(QJsonDocument::Compact));
}