20#ifndef ORES_REFDATA_CORE_MESSAGING_ASSET_CLASS_HANDLER_HPP
21#define ORES_REFDATA_CORE_MESSAGING_ASSET_CLASS_HANDLER_HPP
24#include "ores.logging/make_logger.hpp"
25#include "ores.nats/domain/message.hpp"
26#include "ores.nats/service/client.hpp"
27#include "ores.database/domain/context.hpp"
28#include "ores.security/jwt/jwt_authenticator.hpp"
29#include "ores.service/messaging/handler_helpers.hpp"
30#include "ores.service/service/request_context.hpp"
31#include "ores.refdata.api/messaging/asset_class_protocol.hpp"
32#include "ores.refdata.core/service/asset_class_service.hpp"
34namespace ores::refdata::messaging {
37inline auto& asset_class_handler_lg() {
38 static auto instance = ores::logging::make_logger(
39 "ores.refdata.messaging.asset_class_handler");
44using ores::service::messaging::reply;
45using ores::service::messaging::decode;
46using ores::service::messaging::error_reply;
47using ores::service::messaging::log_handler_entry;
50class asset_class_handler {
54 std::optional<ores::security::jwt::jwt_authenticator> verifier)
55 : nats_(nats), ctx_(
std::move(ctx)), verifier_(
std::move(verifier)) {}
58 [[maybe_unused]]
const auto correlation_id =
59 log_handler_entry(asset_class_handler_lg(), msg);
60 auto ctx_expected = ores::service::service::make_request_context(
61 ctx_, msg, verifier_);
63 error_reply(nats_, msg, ctx_expected.error());
66 const auto& ctx = *ctx_expected;
67 service::asset_class_service svc(ctx);
68 get_asset_classes_response resp;
69 auto req = decode<get_asset_classes_request>(msg);
71 BOOST_LOG_SEV(asset_class_handler_lg(), warn)
72 <<
"Failed to decode: " << msg.
subject;
73 reply(nats_, msg, resp);
77 resp.asset_classes = svc.list_asset_classes(
78 req->coding_scheme_code,
79 static_cast<std::uint32_t
>(req->offset),
80 static_cast<std::uint32_t
>(req->limit));
81 resp.total_available_count =
82 static_cast<int>(svc.count_asset_classes(req->coding_scheme_code));
83 BOOST_LOG_SEV(asset_class_handler_lg(), debug)
85 }
catch (
const std::exception& e) {
86 BOOST_LOG_SEV(asset_class_handler_lg(), error)
87 << msg.
subject <<
" failed: " << e.what();
89 reply(nats_, msg, resp);
95 std::optional<ores::security::jwt::jwt_authenticator> verifier_;
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Context for the operations on a postgres database.
Definition context.hpp:47
A received NATS message.
Definition message.hpp:40
std::string subject
The subject the message was published to.
Definition message.hpp:44
NATS client: connection, pub/sub, request/reply, and JetStream.
Definition client.hpp:73