From 20c7ecadd48910cd715ee2ec1f4817b69a9b0e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 23 Apr 2018 19:24:56 +0200 Subject: [PATCH] Add new controller for requesting the "full" information for a comic. For now it doesn't serve the full information, only the information shown in the current/next comic view in iOS. I will see if I create two separated controllers or just on sending all the information when more information is needed in another iOS view. --- .../v2/comicfullinfocontroller_v2.cpp | 46 +++++++++++++++++++ .../v2/comicfullinfocontroller_v2.h | 24 ++++++++++ YACReaderLibrary/server/requestmapper.cpp | 10 ++-- YACReaderLibrary/server/server.pri | 6 ++- .../server/yacreader_server_data_helper.cpp | 14 ++++++ .../server/yacreader_server_data_helper.h | 3 +- 6 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp create mode 100644 YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.h diff --git a/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp new file mode 100644 index 00000000..dceec7dc --- /dev/null +++ b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.cpp @@ -0,0 +1,46 @@ +#include "comicfullinfocontroller_v2.h" + + + +#include + +#include "db_helper.h" +#include "comic_db.h" +#include "folder.h" + +#include "yacreader_server_data_helper.h" + +#include "qnaturalsorting.h" + +#include +using namespace std; + + + +ComicFullinfoController_v2::ComicFullinfoController_v2() {} + +void ComicFullinfoController_v2::service(HttpRequest& request, HttpResponse& response) +{ + response.setHeader("Content-Type", "application/json"); + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + int libraryId = pathElements.at(3).toInt(); + qulonglong comicId = pathElements.at(5).toULongLong(); + + serviceContent(libraryId, comicId, response); + + response.setStatus(200,"OK"); + response.write("",true); +} + +void ComicFullinfoController_v2::serviceContent(const int &libraryId, const qulonglong &comicId, HttpResponse &response) +{ + ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + + QJsonObject json = YACReaderServerDataHelper::fullComicToJSON(libraryId, comic); + + QJsonDocument output(json); + + response.write(output.toJson()); +} diff --git a/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.h b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.h new file mode 100644 index 00000000..4bc5b343 --- /dev/null +++ b/YACReaderLibrary/server/controllers/v2/comicfullinfocontroller_v2.h @@ -0,0 +1,24 @@ +#ifndef COMICFULLINFOCONTROLLER_V2_H +#define COMICFULLINFOCONTROLLER_V2_H + + + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + + + +class ComicFullinfoController_v2 : public HttpRequestHandler { + Q_OBJECT + Q_DISABLE_COPY(ComicFullinfoController_v2) +public: + ComicFullinfoController_v2(); + + void service(HttpRequest& request, HttpResponse& response); + +private: + void serviceContent(const int &library, const qulonglong &comicId, HttpResponse &response); +}; + +#endif // COMICFULLINFOCONTROLLER_V2_H diff --git a/YACReaderLibrary/server/requestmapper.cpp b/YACReaderLibrary/server/requestmapper.cpp index 2ba07b9d..8bc9f912 100644 --- a/YACReaderLibrary/server/requestmapper.cpp +++ b/YACReaderLibrary/server/requestmapper.cpp @@ -36,6 +36,7 @@ #include "controllers/v2/readingcomicscontroller_v2.h" #include "controllers/v2/readinglistscontroller_v2.h" #include "controllers/v2/readinglistcontentcontroller_v2.h" +#include "controllers/v2/comicfullinfocontroller_v2.h" #include "db_helper.h" #include "yacreader_libraries.h" @@ -218,8 +219,9 @@ void RequestMapper::serviceV2(HttpRequest& request, HttpResponse& response) QRegExp folderInfo("/v2/library/.+/folder/[0-9]+/info/?"); //get folder info QRegExp comicDownloadInfo("/v2/library/.+/comic/[0-9]+/?"); //get comic info (basic/download info) - QRegExp comicFullInfo("/v2/library/.+/comic/[0-9]+/info/?"); //get comic info (full info) - QRegExp comicOpen("/v2/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic + QRegExp comicOpenForDownloading("/v2/library/.+/comic/[0-9]+/info/?"); //get comic info (full info + opening) + QRegExp comicOpenForRemoteReading("/v2/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic + QRegExp comicFullInfo("/v2/library/.+/comic/[0-9]+/fullinfo/?"); //get comic info (full info + opening) QRegExp comicUpdate("/v2/library/.+/comic/[0-9]+/update/?"); //get comic info QRegExp comicClose("/v2/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory QRegExp cover("/v2/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation) @@ -278,9 +280,11 @@ void RequestMapper::serviceV2(HttpRequest& request, HttpResponse& response) { ComicDownloadInfoControllerV2().service(request, response); } - else if(comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path))//start download or start remote reading + else if(comicOpenForDownloading.exactMatch(path) || comicOpenForRemoteReading.exactMatch(path))//start download or start remote reading { ComicControllerV2().service(request, response); + } else if(comicFullInfo.exactMatch(path)) { + ComicFullinfoController_v2().service(request, response); } else if(comicPage.exactMatch(path) || comicPageRemote.exactMatch(path)) { diff --git a/YACReaderLibrary/server/server.pri b/YACReaderLibrary/server/server.pri index 5dc28257..0f79a805 100644 --- a/YACReaderLibrary/server/server.pri +++ b/YACReaderLibrary/server/server.pri @@ -43,7 +43,8 @@ HEADERS += \ $$PWD/controllers/v2/favoritescontroller_v2.h \ $$PWD/controllers/v2/readingcomicscontroller_v2.h \ $$PWD/controllers/v2/readinglistscontroller_v2.h \ - $$PWD/controllers/v2/readinglistcontentcontroller_v2.h + $$PWD/controllers/v2/readinglistcontentcontroller_v2.h \ + $$PWD/controllers/v2/comicfullinfocontroller_v2.h SOURCES += \ @@ -81,7 +82,8 @@ SOURCES += \ $$PWD/controllers/v2/favoritescontroller_v2.cpp \ $$PWD/controllers/v2/readingcomicscontroller_v2.cpp \ $$PWD/controllers/v2/readinglistscontroller_v2.cpp \ - $$PWD/controllers/v2/readinglistcontentcontroller_v2.cpp + $$PWD/controllers/v2/readinglistcontentcontroller_v2.cpp \ + $$PWD/controllers/v2/comicfullinfocontroller_v2.cpp include(lib/logging/logging.pri) diff --git a/YACReaderLibrary/server/yacreader_server_data_helper.cpp b/YACReaderLibrary/server/yacreader_server_data_helper.cpp index fcde5a9f..2829e28e 100644 --- a/YACReaderLibrary/server/yacreader_server_data_helper.cpp +++ b/YACReaderLibrary/server/yacreader_server_data_helper.cpp @@ -57,4 +57,18 @@ QJsonObject YACReaderServerDataHelper::comicToJSON(const qulonglong libraryId, c return json; } +QJsonObject YACReaderServerDataHelper::fullComicToJSON(const qulonglong libraryId, const ComicDB & comic) +{ + QJsonObject json = comicToJSON(libraryId, comic); + + json["volume"] = comic.info.volume.toString(); + json["total_volume_count"] = comic.info.count.toInt(); + json["genre"] = comic.info.genere.toString(); + json["date"] = comic.info.date.toString(); + + json["synopsis"] = comic.info.synopsis.toString(); + + return json; +} + YACReaderServerDataHelper::YACReaderServerDataHelper() {} diff --git a/YACReaderLibrary/server/yacreader_server_data_helper.h b/YACReaderLibrary/server/yacreader_server_data_helper.h index e68cfa07..04eadc08 100644 --- a/YACReaderLibrary/server/yacreader_server_data_helper.h +++ b/YACReaderLibrary/server/yacreader_server_data_helper.h @@ -11,8 +11,9 @@ public: static QString folderToYSFormat(const qulonglong libraryId, const Folder & folder); static QString comicToYSFormat(const qulonglong libraryId, const ComicDB & comic); - static QJsonObject folderToJSON(const qulonglong libraryId, const Folder & folder); + static QJsonObject folderToJSON(const qulonglong libraryId, const Folder & folder); static QJsonObject comicToJSON(const qulonglong libraryId, const ComicDB & comic); + static QJsonObject fullComicToJSON(const qulonglong libraryId, const ComicDB & comic); private: YACReaderServerDataHelper();