Skip to content

Commit

Permalink
Port client updates to server (OpenAPITools#5634)
Browse files Browse the repository at this point in the history
  • Loading branch information
etherealjoy authored and MikailBag committed Mar 23, 2020
1 parent 71e6703 commit c1c6cbe
Show file tree
Hide file tree
Showing 46 changed files with 1,085 additions and 1,346 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{>licenseInfo}}
#include "{{prefix}}Helpers.h"
#include <QDebug>
#include <QJsonParseError>
#include "{{prefix}}Helpers.h"

{{#cppNamespaceDeclarations}}
namespace {{this}} {
Expand Down Expand Up @@ -178,6 +179,17 @@ bool fromStringValue(const QString &inStr, double &value) {
return ok;
}

bool fromStringValue(const QString &inStr, {{prefix}}Object &value)
{
QJsonParseError err;
QJsonDocument::fromJson(inStr.toUtf8(),&err);
if ( err.error == QJsonParseError::NoError ){
value.fromJson(inStr);
return true;
}
return false;
}

bool fromStringValue(const QString &inStr, {{prefix}}Enum &value) {
value.fromJson(inStr);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{>licenseInfo}}

#include <QDebug>
#include <QFile>
#include <QJsonDocument>
Expand All @@ -11,138 +10,125 @@
namespace {{this}} {
{{/cppNamespaceDeclarations}}

void
{{prefix}}HttpFileElement::setMimeType(const QString &mime){
void {{prefix}}HttpFileElement::setMimeType(const QString &mime) {
mime_type = mime;
}

void
{{prefix}}HttpFileElement::setFileName(const QString &name){
void {{prefix}}HttpFileElement::setFileName(const QString &name) {
local_filename = name;
}

void
{{prefix}}HttpFileElement::setVariableName(const QString &name){
void {{prefix}}HttpFileElement::setVariableName(const QString &name) {
variable_name = name;
}

void
{{prefix}}HttpFileElement::setRequestFileName(const QString &name){
void {{prefix}}HttpFileElement::setRequestFileName(const QString &name) {
request_filename = name;
}

bool
{{prefix}}HttpFileElement::isSet() const {
bool {{prefix}}HttpFileElement::isSet() const {
return !local_filename.isEmpty() || !request_filename.isEmpty();
}

QString
{{prefix}}HttpFileElement::asJson() const{
QString {{prefix}}HttpFileElement::asJson() const {
QFile file(local_filename);
QByteArray bArray;
bool result = false;
if(file.exists()) {
if (file.exists()) {
result = file.open(QIODevice::ReadOnly);
bArray = file.readAll();
file.close();
}
if(!result) {
if (!result) {
qDebug() << "Error opening file " << local_filename;
}
return QString(bArray);
}

QJsonValue
{{prefix}}HttpFileElement::asJsonValue() const{
QJsonValue {{prefix}}HttpFileElement::asJsonValue() const {
QFile file(local_filename);
QByteArray bArray;
bool result = false;
if(file.exists()) {
bool result = false;
if (file.exists()) {
result = file.open(QIODevice::ReadOnly);
bArray = file.readAll();
file.close();
}
if(!result) {
if (!result) {
qDebug() << "Error opening file " << local_filename;
}
return QJsonDocument::fromBinaryData(bArray.data()).object();
}

bool
{{prefix}}HttpFileElement::fromStringValue(const QString &instr){
bool {{prefix}}HttpFileElement::fromStringValue(const QString &instr) {
QFile file(local_filename);
bool result = false;
if(file.exists()) {
if (file.exists()) {
file.remove();
}
result = file.open(QIODevice::WriteOnly);
file.write(instr.toUtf8());
file.close();
if(!result) {
if (!result) {
qDebug() << "Error creating file " << local_filename;
}
return result;
}

bool
{{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
bool {{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
QFile file(local_filename);
bool result = false;
if(file.exists()) {
if (file.exists()) {
file.remove();
}
result = file.open(QIODevice::WriteOnly);
file.write(QJsonDocument(jval.toObject()).toBinaryData());
file.close();
if(!result) {
if (!result) {
qDebug() << "Error creating file " << local_filename;
}
return result;
}

QByteArray
{{prefix}}HttpFileElement::asByteArray() const {
QByteArray {{prefix}}HttpFileElement::asByteArray() const {
QFile file(local_filename);
QByteArray bArray;
bool result = false;
if(file.exists()) {
if (file.exists()) {
result = file.open(QIODevice::ReadOnly);
bArray = file.readAll();
file.close();
}
if(!result) {
if (!result) {
qDebug() << "Error opening file " << local_filename;
}
}
return bArray;
}

bool
{{prefix}}HttpFileElement::fromByteArray(const QByteArray& bytes){
bool {{prefix}}HttpFileElement::fromByteArray(const QByteArray &bytes) {
QFile file(local_filename);
bool result = false;
if(file.exists()){
if (file.exists()) {
file.remove();
}
result = file.open(QIODevice::WriteOnly);
file.write(bytes);
file.close();
if(!result) {
if (!result) {
qDebug() << "Error creating file " << local_filename;
}
return result;
}

bool
{{prefix}}HttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray& bytes){
bool {{prefix}}HttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray &bytes) {
setMimeType(mime);
setFileName(localFName);
setVariableName(varName);
setRequestFileName(reqFname);
return fromByteArray(bytes);
}

QByteArray
{{prefix}}HttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime){
QByteArray {{prefix}}HttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime) {
setMimeType(mime);
setFileName(localFName);
setVariableName(varName);
Expand All @@ -151,5 +137,5 @@ QByteArray
}

{{#cppNamespaceDeclarations}}
}
{{/cppNamespaceDeclarations}}
} // namespace {{this}}
{{/cppNamespaceDeclarations}}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QMetaType>
#include <QString>


{{#cppNamespaceDeclarations}}
namespace {{this}} {
{{/cppNamespaceDeclarations}}
Expand All @@ -25,16 +24,16 @@ public:
bool isSet() const;
bool fromStringValue(const QString &instr);
bool fromJsonValue(const QJsonValue &jval);
bool fromByteArray(const QByteArray& bytes);
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray& bytes);
bool fromByteArray(const QByteArray &bytes);
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray &bytes);
QString asJson() const;
QJsonValue asJsonValue() const;
QByteArray asByteArray() const;
QByteArray loadFromFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime);
};

{{#cppNamespaceDeclarations}}
}
} // namespace {{this}}
{{/cppNamespaceDeclarations}}

Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}HttpFileElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
#ifndef {{prefix}}_ENUM_H
#define {{prefix}}_ENUM_H

#include <QString>
#include <QJsonValue>
#include <QMetaType>
#include <QString>

{{#cppNamespaceDeclarations}}
namespace {{this}} {
{{/cppNamespaceDeclarations}}

class {{prefix}}Enum {
public:
{{prefix}}Enum() {
}
public:
{{prefix}}Enum() {}

{{prefix}}Enum(QString jsonString) {
fromJson(jsonString);
}

virtual ~{{prefix}}Enum(){
}
virtual ~{{prefix}}Enum() {}

virtual QJsonValue asJsonValue() const {
return QJsonValue(jstr);
Expand All @@ -47,12 +43,13 @@ class {{prefix}}Enum {
virtual bool isValid() const {
return true;
}
private :

private:
QString jstr;
};

{{#cppNamespaceDeclarations}}
}
} // namespace {{this}}
{{/cppNamespaceDeclarations}}

Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}Enum)
Expand Down
Loading

0 comments on commit c1c6cbe

Please sign in to comment.