You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
#include "HttpOrderService.h" |
|
#include <stdexcept> |
|
|
|
namespace nxl::autostore::infrastructure { |
|
|
|
HttpOrderService::HttpOrderService(ILoggerPtr logger) : log{std::move(logger)} |
|
{} |
|
|
|
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(std::string_view url, |
|
std::string_view payload) |
|
{ |
|
// In a real implementation, this would use an HTTP client library |
|
// For now, we'll simulate the HTTP call |
|
log->i("POST request to: %s", url); |
|
log->v(1, "Payload: %s", payload); |
|
|
|
// Simulate HTTP error handling |
|
if (url.find("error") != std::string::npos) { |
|
throw std::runtime_error("Failed to send order request to: " |
|
+ std::string(url)); |
|
} |
|
} |
|
|
|
} // namespace nxl::autostore::infrastructure
|