Files
UpAndDown/src/endpoints_handlers/Controller.h
T

32 lines
802 B
C++

#pragma once
#include <boost/beast.hpp>
#include "./IController.h"
namespace uad
{
template <class Body, class Allocator, class ResponseType>
class Controller : public IController<Body, Allocator, ResponseType>
{
public:
using HTTPMethodsToExecutors = std::unordered_map<boost::beast::http::verb, std::shared_ptr<IExecutor<Body, Allocator, ResponseType>>>;
private:
HTTPMethodsToExecutors executors_;
public:
Controller() = default;
explicit Controller(HTTPMethodsToExecutors&& executors): executors_(std::move(executors)) {}
std::optional<std::shared_ptr<IExecutor<Body, Allocator, ResponseType>>> FindExecutor(
boost::beast::http::verb method
) override
{
if (!executors_.count(method)) return std::nullopt;
return std::make_optional(executors_.at(method));
}
};
}