diff options
Diffstat (limited to 'jobs/{{base}}.cpp.mustache')
-rw-r--r-- | jobs/{{base}}.cpp.mustache | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/jobs/{{base}}.cpp.mustache b/jobs/{{base}}.cpp.mustache new file mode 100644 index 00000000..f3a6dc59 --- /dev/null +++ b/jobs/{{base}}.cpp.mustache @@ -0,0 +1,76 @@ +{{#@filePartial}}preamble{{/@filePartial}} + +#include "{{filenameBase}}.h" + +{{^models}}#include "jobs/converters.h"{{/models}} +{{#operations}}#include <QtCore/QStringBuilder>{{/operations}} + +using namespace QMatrixClient; +{{#models}}{{#model}} +{{classname}}::operator QJsonValue() const +{ + QJsonObject o; + {{#vars}}o.insert("{{name}}", toJson({{name}})); + {{/vars}} + return o; +} + +{{classname}} FromJson<{{classname}}>::operator()(QJsonValue jv) +{ + QJsonObject o = jv.toObject(); + {{classname}} result; + {{#vars}}result.{{name}} = fromJson<{{datatype}}>(o.value("{{name}}")); + {{/vars}} + return result; +} +{{/model}}{{/models}}{{#operations}} +static const auto basePath = QStringLiteral("{{basePathWithoutHost}}"); +{{# operation}}{{#responses}}{{#normalResponse?}}{{#properties?}} +class {{camelCaseOperationId}}Job::Private +{ + public: + {{#properties}}{{dataType}} {{paramName}}; + {{/properties}} +}; +{{/ properties?}}{{/normalResponse?}}{{/responses}} +{{camelCaseOperationId}}Job::{{camelCaseOperationId}}Job({{#allParams}}{{#avoidCopy?}}const {{dataType}}&{{/avoidCopy?}}{{^avoidCopy?}}{{dataType}}{{/avoidCopy?}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + : BaseJob(HttpVerb::{{#@cap}}{{#@tolower}}{{httpMethod}}{{/@tolower}}{{/@cap}}, "{{camelCaseOperationId}}Job", + basePath{{#pathParts}} % {{part}}{{/pathParts}}, + Query {{^queryParams}}{ }{{/queryParams}}{{#queryParams?}}{ + {{#queryParams}}{ "{{baseName}}", toJson({{paramName}}).toString() }{{#hasMore}}, + {{/hasMore}}{{/queryParams}} + }{{/queryParams?}}{{#skipAuth}}, Data { }, false{{/skipAuth}} + ){{#responses}}{{#normalResponse?}}{{#properties?}}, d(new Private){{/properties?}}{{/normalResponse?}}{{/responses}} +{{#bodyParams?}}{ + Data _data;{{#bodyParams}} +{{^required?}}{{#string?}} if (!{{paramName}}.isEmpty()) + {{/string?}}{{/required?}} _data.insert("{{baseName}}", toJson({{paramName}}));{{/bodyParams}} + setRequestData(_data); +}{{/bodyParams?}}{{^bodyParams?}}{ }{{/bodyParams?}} +{{# responses}}{{#normalResponse?}}{{#properties?}} +{{camelCaseOperationId}}Job::~{{camelCaseOperationId}}Job() +{ + delete d; +} +{{# properties}} +const {{dataType}}& {{camelCaseOperationId}}Job::{{paramName}}() const +{ + return d->{{paramName}}; +} +{{/ properties}}{{#returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseReply(QByteArray data) +{ + {{#properties}}{{paramName}}{{/properties}} = data; + return Success; +}{{/ returnFile?}}{{^returnFile?}} +BaseJob::Status {{camelCaseOperationId}}Job::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + {{# properties}}{{#required?}}if (!json.contains("{{paramName}}")) + return { JsonParseError, + "The key '{{paramName}}' not found in the response" };{{/required?}} + d->{{paramName}} = fromJson<{{dataType}}>(json.value("{{paramName}}")); +{{/ properties}} + return Success; +}{{/ returnFile?}} +{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}} |