15 changed files with 88 additions and 219 deletions
@ -1,36 +0,0 @@
|
||||
#include "HttpOrderService.h" |
||||
#include <stdexcept> |
||||
#include <iostream> |
||||
|
||||
namespace nxl::autostore::infrastructure { |
||||
|
||||
HttpOrderService::HttpOrderService(const std::string& baseUrl) |
||||
: baseUrl(baseUrl) |
||||
{} |
||||
|
||||
void HttpOrderService::orderItem(const domain::Item& item) |
||||
{ |
||||
if (item.orderUrl.empty()) { |
||||
throw std::runtime_error("Order URL is empty for item: " + item.name); |
||||
} |
||||
|
||||
std::string payload = |
||||
R"({"itemName": ")" + item.name + R"(", "itemId": ")" + item.id + "\"}"; |
||||
sendPostRequest(item.orderUrl, payload); |
||||
} |
||||
|
||||
void HttpOrderService::sendPostRequest(const std::string& url, |
||||
const std::string& payload) |
||||
{ |
||||
// In a real implementation, this would use an HTTP client library
|
||||
// For now, we'll simulate the HTTP call
|
||||
std::cout << "POST request to: " << url << std::endl; |
||||
std::cout << "Payload: " << payload << std::endl; |
||||
|
||||
// Simulate HTTP error handling
|
||||
if (url.find("error") != std::string::npos) { |
||||
throw std::runtime_error("Failed to send order request to: " + url); |
||||
} |
||||
} |
||||
|
||||
} // namespace nxl::autostore::infrastructure
|
||||
@ -1,20 +0,0 @@
|
||||
#pragma once |
||||
|
||||
#include "application/interfaces/IOrderService.h" |
||||
#include "domain/entities/Item.h" |
||||
#include <string> |
||||
|
||||
namespace nxl::autostore::infrastructure { |
||||
|
||||
class HttpOrderService : public application::IOrderService |
||||
{ |
||||
public: |
||||
explicit HttpOrderService(const std::string& baseUrl = ""); |
||||
void orderItem(const domain::Item& item) override; |
||||
|
||||
private: |
||||
std::string baseUrl; |
||||
void sendPostRequest(const std::string& url, const std::string& payload); |
||||
}; |
||||
|
||||
} // namespace nxl::autostore::infrastructure
|
||||
Loading…
Reference in new issue