Implemented PresenceStatus in API
This commit is contained in:
@@ -48,6 +48,7 @@ void GetBookingsReply::requestFinished()
|
||||
|
||||
setSuccess(true);
|
||||
m_bookings.clear();
|
||||
m_bookings.reserve(arr.count());
|
||||
for(const auto &val : arr)
|
||||
{
|
||||
auto obj = val.toObject();
|
||||
|
69
replies/getpresencestatusreply.cpp
Normal file
69
replies/getpresencestatusreply.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "getpresencestatusreply.h"
|
||||
|
||||
#include <QJsonParseError>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
#include <QJsonObject>
|
||||
|
||||
GetPresenceStatusReply::GetPresenceStatusReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung) :
|
||||
ZeiterfassungReply(zeiterfassung),
|
||||
m_reply(std::move(reply))
|
||||
{
|
||||
connect(m_reply.get(), &QNetworkReply::finished, this, &GetPresenceStatusReply::requestFinished);
|
||||
}
|
||||
|
||||
const QVector<ZeiterfassungApi::PresenceStatus> &GetPresenceStatusReply::presenceStatuses() const
|
||||
{
|
||||
return m_presenceStatuses;
|
||||
}
|
||||
|
||||
void GetPresenceStatusReply::requestFinished()
|
||||
{
|
||||
if(m_reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
setSuccess(false);
|
||||
setMessage(tr("Request error occured: %0").arg(m_reply->error()));
|
||||
goto end;
|
||||
}
|
||||
|
||||
{
|
||||
QJsonParseError error;
|
||||
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.isArray())
|
||||
{
|
||||
setSuccess(false);
|
||||
setMessage(tr("JSON document is not an array!"));
|
||||
goto end;
|
||||
}
|
||||
|
||||
auto arr = document.array();
|
||||
|
||||
setSuccess(true);
|
||||
m_presenceStatuses.clear();
|
||||
m_presenceStatuses.reserve(arr.count());
|
||||
for(const auto &val : arr)
|
||||
{
|
||||
auto obj = val.toObject();
|
||||
|
||||
m_presenceStatuses.append({
|
||||
obj.value(QStringLiteral("persNr")).toInt(),
|
||||
obj.value(QStringLiteral("firstName")).toString(),
|
||||
obj.value(QStringLiteral("lastName")).toString(),
|
||||
obj.value(QStringLiteral("presence")).toString()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
m_reply = Q_NULLPTR;
|
||||
|
||||
Q_EMIT finished();
|
||||
}
|
28
replies/getpresencestatusreply.h
Normal file
28
replies/getpresencestatusreply.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef GETPRESENCESTATUSREPLY_H
|
||||
#define GETPRESENCESTATUSREPLY_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "zeiterfassungreply.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
class GetPresenceStatusReply : public ZeiterfassungReply
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GetPresenceStatusReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung);
|
||||
|
||||
const QVector<ZeiterfassungApi::PresenceStatus> &presenceStatuses() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void requestFinished();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QNetworkReply> m_reply;
|
||||
QVector<ZeiterfassungApi::PresenceStatus> m_presenceStatuses;
|
||||
};
|
||||
|
||||
#endif // GETPRESENCESTATUSREPLY_H
|
@@ -66,6 +66,7 @@ void GetProjectsReply::requestFinished()
|
||||
|
||||
setSuccess(true);
|
||||
m_projects.clear();
|
||||
m_projects.reserve(elementsArr.count());
|
||||
for(const auto &val : elementsArr)
|
||||
{
|
||||
auto obj = val.toObject();
|
||||
|
@@ -49,6 +49,7 @@ void GetTimeAssignmentsReply::requestFinished()
|
||||
|
||||
setSuccess(true);
|
||||
m_timeAssignments.clear();
|
||||
m_timeAssignments.reserve(arr.count());
|
||||
for(const auto &val : arr)
|
||||
{
|
||||
auto obj = val.toObject();
|
||||
|
@@ -45,7 +45,8 @@ SOURCES += main.cpp \
|
||||
replies/getprojectsreply.cpp \
|
||||
replies/getauswertungreply.cpp \
|
||||
replies/zeiterfassungreply.cpp \
|
||||
replies/deletetimeassignmentreply.cpp
|
||||
replies/deletetimeassignmentreply.cpp \
|
||||
replies/getpresencestatusreply.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -77,7 +78,8 @@ HEADERS += \
|
||||
replies/getauswertungreply.h \
|
||||
replies/zeiterfassungreply.h \
|
||||
replies/deletetimeassignmentreply.h \
|
||||
cpp14polyfills.h
|
||||
cpp14polyfills.h \
|
||||
replies/getpresencestatusreply.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui \
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "replies/deletetimeassignmentreply.h"
|
||||
#include "replies/getauswertungreply.h"
|
||||
#include "replies/getbookingsreply.h"
|
||||
#include "replies/getpresencestatusreply.h"
|
||||
#include "replies/getprojectsreply.h"
|
||||
#include "replies/gettimeassignmentsreply.h"
|
||||
#include "replies/loginpagereply.h"
|
||||
@@ -297,3 +298,13 @@ std::unique_ptr<GetAuswertungReply> ZeiterfassungApi::doGetAuswertung(int userId
|
||||
|
||||
return std::make_unique<GetAuswertungReply>(std::move(reply), this);
|
||||
}
|
||||
|
||||
std::unique_ptr<GetPresenceStatusReply> ZeiterfassungApi::doGetPresenceStatus()
|
||||
{
|
||||
QNetworkRequest request(QUrl(m_url % "json/presencestatus"));
|
||||
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("presenceStatus"));
|
||||
|
||||
auto reply = std::unique_ptr<QNetworkReply>(m_manager->get(request));
|
||||
|
||||
return std::make_unique<GetPresenceStatusReply>(std::move(reply), this);
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@ class UpdateTimeAssignmentReply;
|
||||
class DeleteTimeAssignmentReply;
|
||||
class GetProjectsReply;
|
||||
class GetAuswertungReply;
|
||||
class GetPresenceStatusReply;
|
||||
|
||||
class ZeiterfassungApi : public QObject
|
||||
{
|
||||
@@ -73,6 +74,14 @@ public:
|
||||
QString value;
|
||||
};
|
||||
|
||||
struct PresenceStatus
|
||||
{
|
||||
int userId;
|
||||
QString firstName;
|
||||
QString lastName;
|
||||
QString presence;
|
||||
};
|
||||
|
||||
std::unique_ptr<LoginPageReply> doLoginPage();
|
||||
std::unique_ptr<LoginReply> doLogin(const QString &username, const QString &password);
|
||||
std::unique_ptr<UserInfoReply> doUserInfo();
|
||||
@@ -97,6 +106,7 @@ public:
|
||||
|
||||
std::unique_ptr<GetProjectsReply> doGetProjects(int userId, const QDate &date);
|
||||
std::unique_ptr<GetAuswertungReply> doGetAuswertung(int userId, const QDate &date);
|
||||
std::unique_ptr<GetPresenceStatusReply> doGetPresenceStatus();
|
||||
|
||||
private:
|
||||
QString m_url;
|
||||
|
Reference in New Issue
Block a user