Fixed bookings being marked as modified #20
This commit is contained in:
@@ -1,23 +1,12 @@
|
|||||||
#include "createbookingreply.h"
|
#include "createbookingreply.h"
|
||||||
|
|
||||||
#include <QJsonParseError>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonValue>
|
|
||||||
|
|
||||||
CreateBookingReply::CreateBookingReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung) :
|
CreateBookingReply::CreateBookingReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung) :
|
||||||
ZeiterfassungReply(zeiterfassung),
|
ZeiterfassungReply(zeiterfassung),
|
||||||
m_reply(std::move(reply)),
|
m_reply(std::move(reply))
|
||||||
m_bookingId(-1)
|
|
||||||
{
|
{
|
||||||
connect(m_reply.get(), &QNetworkReply::finished, this, &CreateBookingReply::requestFinished);
|
connect(m_reply.get(), &QNetworkReply::finished, this, &CreateBookingReply::requestFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CreateBookingReply::bookingId() const
|
|
||||||
{
|
|
||||||
return m_bookingId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CreateBookingReply::requestFinished()
|
void CreateBookingReply::requestFinished()
|
||||||
{
|
{
|
||||||
if(m_reply->error() != QNetworkReply::NoError)
|
if(m_reply->error() != QNetworkReply::NoError)
|
||||||
@@ -27,35 +16,8 @@ void CreateBookingReply::requestFinished()
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// empty response so nothing to check
|
||||||
QJsonParseError error;
|
setSuccess(true);
|
||||||
QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll(), &error);
|
|
||||||
if(error.error != QJsonParseError::NoError)
|
|
||||||
{
|
|
||||||
setSuccess(false);
|
|
||||||
setMessage(tr("Parsing JSON failed: %0").arg(error.errorString()));
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!document.isObject())
|
|
||||||
{
|
|
||||||
setSuccess(false);
|
|
||||||
setMessage(tr("JSON document is not an object!"));
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto obj = document.object();
|
|
||||||
|
|
||||||
if(!obj.contains(QStringLiteral("bookingNr")))
|
|
||||||
{
|
|
||||||
setSuccess(false);
|
|
||||||
setMessage(tr("JSON does not contain bookingNr!"));
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSuccess(true);
|
|
||||||
m_bookingId = obj.value(QStringLiteral("bookingNr")).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
m_reply = Q_NULLPTR;
|
m_reply = Q_NULLPTR;
|
||||||
|
@@ -15,14 +15,11 @@ class ZEITERFASSUNGLIBSHARED_EXPORT CreateBookingReply : public ZeiterfassungRep
|
|||||||
public:
|
public:
|
||||||
CreateBookingReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung);
|
CreateBookingReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung);
|
||||||
|
|
||||||
int bookingId() const;
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void requestFinished();
|
void requestFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<QNetworkReply> m_reply;
|
std::unique_ptr<QNetworkReply> m_reply;
|
||||||
int m_bookingId;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CREATEBOOKINGREPLY_H
|
#endif // CREATEBOOKINGREPLY_H
|
||||||
|
@@ -98,9 +98,9 @@ std::unique_ptr<GetBookingsReply> ZeiterfassungApi::doGetBookings(int userId, co
|
|||||||
std::unique_ptr<CreateBookingReply> ZeiterfassungApi::doCreateBooking(int userId, const QDate &date, const QTime &time, const QTime ×pan,
|
std::unique_ptr<CreateBookingReply> ZeiterfassungApi::doCreateBooking(int userId, const QDate &date, const QTime &time, const QTime ×pan,
|
||||||
const QString &type, const QString &text)
|
const QString &type, const QString &text)
|
||||||
{
|
{
|
||||||
QNetworkRequest request(QUrl(m_url % "json/booking"));
|
QNetworkRequest request(QUrl(m_url % "json/terminalPageController/evoTerminalBooking"));
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/json"));
|
request.setHeader(QNetworkRequest::ContentTypeHeader, QByteArrayLiteral("application/json"));
|
||||||
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
|
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("terminal"));
|
||||||
|
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
obj[QStringLiteral("persNr")] = userId;
|
obj[QStringLiteral("persNr")] = userId;
|
||||||
@@ -111,6 +111,7 @@ std::unique_ptr<CreateBookingReply> ZeiterfassungApi::doCreateBooking(int userId
|
|||||||
obj[QStringLiteral("hourCategory")] = QStringLiteral("");
|
obj[QStringLiteral("hourCategory")] = QStringLiteral("");
|
||||||
obj[QStringLiteral("empfEinh")] = QStringLiteral("");
|
obj[QStringLiteral("empfEinh")] = QStringLiteral("");
|
||||||
obj[QStringLiteral("bewEinh")] = QStringLiteral("");
|
obj[QStringLiteral("bewEinh")] = QStringLiteral("");
|
||||||
|
obj[QStringLiteral("einstuf")] = QStringLiteral("");
|
||||||
obj[QStringLiteral("text")] = text;
|
obj[QStringLiteral("text")] = text;
|
||||||
|
|
||||||
auto reply = std::unique_ptr<QNetworkReply>(m_manager->post(request, QJsonDocument(obj).toJson()));
|
auto reply = std::unique_ptr<QNetworkReply>(m_manager->post(request, QJsonDocument(obj).toJson()));
|
||||||
|
Reference in New Issue
Block a user