forked from ondra/colnod-connector
Comment colnodApi
This commit is contained in:
parent
82d93fd115
commit
2bc1301fcd
@ -8,28 +8,43 @@
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(colnod)
|
||||
|
||||
/**
|
||||
* @brief Helper class for simply work with Colnod API
|
||||
*/
|
||||
class LoginResp : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, username, setUsername, "")
|
||||
TABLE_PROPERTY(QString, password, setPassword, "")
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Helper class for simply work with Colnod API
|
||||
*/
|
||||
class AuthToken : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(QString, id, setId, QString())
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class for easy switching date time formats
|
||||
* Especially between from and to miliseconds
|
||||
*/
|
||||
class Timestamp : public serversdk::DatabaseTable {
|
||||
Q_OBJECT
|
||||
TABLE_PROPERTY(qint64, timestamp, setTimestamp, 0)
|
||||
public:
|
||||
Timestamp() = default;
|
||||
|
||||
void setTimestamp(QDateTime time)
|
||||
void setTimestamp(const QDateTime &time)
|
||||
{
|
||||
setTimestamp(time.toMSecsSinceEpoch());
|
||||
}
|
||||
|
||||
/**
|
||||
* @breif Function for output date in readable form
|
||||
*
|
||||
* @return String in format: 2019-11-12 16:34:03.932
|
||||
*
|
||||
*/
|
||||
QString toDateString()
|
||||
{
|
||||
return QDateTime::fromMSecsSinceEpoch(a_timestamp).toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
@ -39,22 +54,31 @@ class Timestamp : public serversdk::DatabaseTable {
|
||||
class ColnodAPI: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class ColnodTest;
|
||||
public:
|
||||
ColnodAPI() = default;
|
||||
ColnodAPI(serversdk::RequestManager* reqManconst, const bool &dryMode = false, QString userName = "spaceti", QString password = "spaceti1");
|
||||
|
||||
/**
|
||||
* @brief Downloading changed data from Colnod since last Synchronization
|
||||
*
|
||||
* @param time Time of last sync
|
||||
*
|
||||
* @return Function returns data changed after this time
|
||||
*/
|
||||
bool downloadData(const qint64 &time);
|
||||
|
||||
/**
|
||||
* @brief Push all data prepare during synchronization to Colnod
|
||||
* @param data Data which are pushing to Colnod
|
||||
*/
|
||||
void processData(const std::shared_ptr<Data> &data);
|
||||
|
||||
std::shared_ptr<serversdk::Request> requestLogin();
|
||||
|
||||
/**
|
||||
* @brief Endpoint of Colnod API
|
||||
* @param time Returns changed tokens after time
|
||||
* @return Return request, than waiting for finished
|
||||
*/
|
||||
std::shared_ptr<serversdk::Request> getTokensUpdated(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getTokensDeleted(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsUpdated(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsDeleted(const Timestamp &time);
|
||||
|
||||
std::shared_ptr<serversdk::Request> setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens);
|
||||
std::shared_ptr<serversdk::Request> deleteTokens(const QList<QString> &tokenIds);
|
||||
|
||||
// Attributes
|
||||
QString userName() const;
|
||||
@ -65,24 +89,38 @@ public:
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
Q_SLOT void isDataProcessFinished(bool success);
|
||||
std::shared_ptr<serversdk::Request> requestLogin();
|
||||
|
||||
private:
|
||||
// All endpoints of Colnod API that we need to use, simply returns request
|
||||
// than we wait for finish
|
||||
std::shared_ptr<serversdk::Request> getTokensDeleted(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsUpdated(const Timestamp &time);
|
||||
std::shared_ptr<serversdk::Request> getSubjectsDeleted(const Timestamp &time);
|
||||
|
||||
std::shared_ptr<serversdk::Request> setTokens(const QHash<QString, std::shared_ptr<Token>> &tokens);
|
||||
std::shared_ptr<serversdk::Request> deleteTokens(const QList<QString> &tokenIds);
|
||||
|
||||
// Functions which saves response data from Colnod to variable data
|
||||
bool saveUpdatedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveUpdatedSubjects(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveDeletedTokens(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
bool saveDeletedSubjects(const std::shared_ptr<Data>& data, const QByteArray &responseData);
|
||||
|
||||
// Helper func for check format of response
|
||||
bool checkResponse(const QByteArray &responseData);
|
||||
|
||||
std::shared_ptr<serversdk::Request> composeRequest(const QString &endpoint, const QByteArray &data);
|
||||
|
||||
// Helper func for check status of request
|
||||
bool checkRequest(const std::shared_ptr<serversdk::Request> &request);
|
||||
|
||||
bool checkErrors(const std::shared_ptr<serversdk::Request> &request);
|
||||
|
||||
// Prepares request to be sent
|
||||
std::shared_ptr<serversdk::Request> composeRequest(const QString &endpoint, const QByteArray &data);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal which transfer data to Sync Manager
|
||||
*/
|
||||
void downloadDataFinished(std::shared_ptr<Data> = std::shared_ptr<Data>());
|
||||
void partOfDataProcessFinished(bool success = true);
|
||||
void dataProcessFinished(bool success = true);
|
||||
|
||||
private:
|
||||
@ -95,6 +133,5 @@ private:
|
||||
bool mSuccess = true;
|
||||
|
||||
QString authToken;
|
||||
qint16 amountProccessesFinished = 0;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user