mirror of
https://github.com/YACReader/yacreader
synced 2025-07-17 20:44:32 -04:00
Add new controller for getting a folder
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
#include "foldermetadatacontroller_v2.h"
|
||||
|
||||
#include "db_helper.h"
|
||||
#include "folder.h"
|
||||
|
||||
#include "yacreader_libraries.h"
|
||||
#include "yacreader_server_data_helper.h"
|
||||
|
||||
FolderMetadataControllerV2::FolderMetadataControllerV2() { }
|
||||
|
||||
void FolderMetadataControllerV2::service(stefanfrings::HttpRequest &request, stefanfrings::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 folderId = pathElements.at(5).toULongLong();
|
||||
|
||||
auto folder = DBHelper::getFolder(libraryId, folderId);
|
||||
if (!folder.knownId) {
|
||||
response.setStatus(404, "not found");
|
||||
response.write("404 not found", true);
|
||||
return;
|
||||
}
|
||||
|
||||
auto libraryUuid = DBHelper::getLibraries().getLibraryIdFromLegacyId(libraryId);
|
||||
|
||||
auto json = YACReaderServerDataHelper::folderToJSON(libraryId, libraryUuid, folder);
|
||||
|
||||
QJsonDocument output(json);
|
||||
|
||||
response.write(output.toJson(QJsonDocument::Compact));
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef FOLDERMETADATACONTROLLERV2_H
|
||||
#define FOLDERMETADATACONTROLLERV2_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderMetadataControllerV2 : public stefanfrings::HttpRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderMetadataControllerV2)
|
||||
public:
|
||||
/** Constructor */
|
||||
FolderMetadataControllerV2();
|
||||
|
||||
/** Generates the response */
|
||||
void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override;
|
||||
};
|
||||
|
||||
#endif // FOLDERMETADATACONTROLLERV2_H
|
Reference in New Issue
Block a user