aboutsummaryrefslogtreecommitdiff
path: root/jobs/{{base}}.cpp.mustache
blob: 31b867faa08b8563b18adfb431cb0a0d91c87778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{{#@filePartial}}preamble{{/@filePartial}}

#include "{{filenameBase}}.h"

{{^models}}#include "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}} % {{.}}{{/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("{{baseName}}"));
{{/            properties}}
    return Success;
}{{/       returnFile?}}
{{/properties?}}{{/normalResponse?}}{{/responses}}{{/operation}}{{/operations}}