Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation without Proxy Pattern.
- Loading branch information
1 parent
5d27e46
commit 1f857f7
Showing
5 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// local | ||
#include "api_handler.h" | ||
|
||
namespace constants | ||
{ | ||
const QString FILES_ENDPOINT = "/api/files"; | ||
const QString DOWNLOAD_FILE_ENDPOINT = "/api/download/file/"; | ||
} // constants namespace | ||
|
||
APIHandler::APIHandler(const QString &hostUrl) | ||
: m_hostUrl(hostUrl) | ||
{ | ||
m_networkManager = std::make_unique<QNetworkAccessManager>(); | ||
} | ||
|
||
QNetworkReply *APIHandler::GetFilesList() | ||
{ | ||
const QString url = m_hostUrl + constants::FILES_ENDPOINT; | ||
return m_networkManager->get(QNetworkRequest(url)); | ||
} | ||
|
||
QNetworkReply *APIHandler::DownloadFile(const QString &fileName) | ||
{ | ||
const QString url = m_hostUrl + constants::DOWNLOAD_FILE_ENDPOINT + fileName; | ||
return m_networkManager->get(QNetworkRequest(url)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//--------------------------------------------------------------------------------------------------------------------- | ||
/// @file | ||
/// | ||
/// @brief API Handler Class | ||
/// | ||
/// @author Ali Ibrahim (ali103575@gmail.com) | ||
/// | ||
/// @version 1.0 | ||
/// @date 01-15-2023 | ||
//--------------------------------------------------------------------------------------------------------------------- | ||
|
||
#ifndef API_HANDLER_H | ||
#define API_HANDLER_H | ||
|
||
// local | ||
|
||
// qt | ||
#include <QNetworkAccessManager> | ||
#include <QNetworkReply> | ||
#include <QString> | ||
|
||
// stdlib | ||
#include <memory> | ||
|
||
class APIHandler | ||
{ | ||
public: | ||
APIHandler(const QString &hostUrl); | ||
virtual ~APIHandler() = default; | ||
QNetworkReply *GetFilesList(); | ||
QNetworkReply *DownloadFile(const QString &fileName); | ||
|
||
private: | ||
QString m_hostUrl; | ||
std::unique_ptr<QNetworkAccessManager> m_networkManager; | ||
}; | ||
|
||
#endif // API_HANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters