71 lines
2.4 KiB
C++
71 lines
2.4 KiB
C++
#include "OrderRouter.h"
|
|
#include "lib/api/service_helpers/AdminServiceUtils.h"
|
|
#include "lib/api/services/AdminService.server.pb.h"
|
|
#include "lib/config/config.h"
|
|
#include "lib/config/protos/jetfix.pb.h"
|
|
#include "lib/utils/bts_assert.h"
|
|
|
|
namespace bts {
|
|
namespace orderman {
|
|
|
|
struct OrderRouter::PImpl {
|
|
PImpl() {}
|
|
api::admin::AdminData data;
|
|
};
|
|
|
|
OrderRouter::OrderRouter() : me(new PImpl()) {}
|
|
|
|
void OrderRouter::update(api::admin::AdminData const &new_data) {
|
|
LOG(Gen, Info, "OrderRouter:update called");
|
|
me->data.CopyFrom(new_data);
|
|
}
|
|
|
|
OrderRouter::RouteQueryResult
|
|
OrderRouter::get_routing_record(UserID user_id, AccountID account_id,
|
|
api::Security const &sec) const {
|
|
api::admin::AdminServiceOperationResult result;
|
|
api::orderman::RoutingRecord rr =
|
|
bts::admin::AdminServiceUtils::get_routing_record(
|
|
me->data, account_id.value() == 0 ? 1 : account_id.value(),
|
|
user_id.value() == 0 ? 1 : user_id.value(), sec, result);
|
|
if (result.is_success())
|
|
return RouteQueryResult{true, std::string(""), rr};
|
|
else
|
|
return RouteQueryResult{false, result.error_text(), rr};
|
|
}
|
|
|
|
OrderRouter::ReverseRoutingQueryResult OrderRouter::get_reverse_routing_record(
|
|
std::string const &session, std::string const &operator_id,
|
|
std::string const &account, api::Security const *sec) const {
|
|
ReverseRoutingQueryResult rv{true, "", "", UserID(0), "", AccountID(0)};
|
|
api::Venue exchange =
|
|
sec == nullptr ? api::Venue::VENUE_GLBX : sec->exchange();
|
|
auto match = bts::admin::AdminServiceUtils::find_user_account_matches(
|
|
me->data, session, account, operator_id, exchange);
|
|
if (match.first != nullptr) {
|
|
rv.account = match.first->name();
|
|
rv.account_id = AccountID(match.first->id());
|
|
} else {
|
|
rv.ok = false;
|
|
rv.error_msg = "Could not resolve account";
|
|
}
|
|
if (match.second != nullptr) {
|
|
rv.user = match.second->name();
|
|
rv.user_id = UserID(match.second->id());
|
|
} else {
|
|
rv.ok = false;
|
|
rv.error_msg = (!rv.ok ? std::string(", ") : std::string("")) +
|
|
"Could not resolve user";
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
bool OrderRouter::is_valid_session(std::string const &session) const {
|
|
return bts::admin::AdminServiceUtils::find_connection(me->data, session) !=
|
|
nullptr;
|
|
}
|
|
|
|
OrderRouter::~OrderRouter() {}
|
|
} // namespace orderman
|
|
} // namespace bts
|