2023-07-21 16:17:01 +08:00
|
|
|
|
#ifndef SERVICELOGIC_H
|
|
|
|
|
#define SERVICELOGIC_H
|
|
|
|
|
|
2024-01-24 23:19:53 +08:00
|
|
|
|
#include "Application.h"
|
2023-07-21 16:17:01 +08:00
|
|
|
|
#include "ResponseUtility.h"
|
|
|
|
|
#include "StringUtility.h"
|
|
|
|
|
#include <boost/beast/http/message.hpp>
|
|
|
|
|
#include <boost/beast/http/string_body.hpp>
|
|
|
|
|
#include <boost/beast/http/vector_body.hpp>
|
|
|
|
|
#include <boost/beast/version.hpp>
|
|
|
|
|
#include <boost/uuid/uuid_generators.hpp>
|
|
|
|
|
#include <boost/uuid/uuid_io.hpp>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
using StringRequest = boost::beast::http::request<boost::beast::http::string_body>;
|
|
|
|
|
|
|
|
|
|
namespace ServiceLogic {
|
|
|
|
|
|
|
|
|
|
template <class Send>
|
2024-01-24 23:19:53 +08:00
|
|
|
|
static void onWechat(const Application::Pointer &app, StringRequest &&request, Send &&send);
|
2023-07-21 16:17:01 +08:00
|
|
|
|
|
|
|
|
|
// Returns a server error response
|
|
|
|
|
boost::beast::http::response<boost::beast::http::string_body>
|
|
|
|
|
serverError(const boost::beast::http::request<boost::beast::http::string_body> &request, std::string_view errorMessage);
|
|
|
|
|
|
2023-12-31 01:13:26 +08:00
|
|
|
|
boost::beast::http::response<boost::beast::http::string_body>
|
|
|
|
|
badRequest(const boost::beast::http::request<boost::beast::http::string_body> &request, std::string_view why);
|
|
|
|
|
|
2023-07-21 16:17:01 +08:00
|
|
|
|
template <class ResponseBody, class RequestBody>
|
|
|
|
|
boost::beast::http::response<ResponseBody> make_200(const boost::beast::http::request<RequestBody> &request,
|
|
|
|
|
typename ResponseBody::value_type body,
|
|
|
|
|
boost::beast::string_view content) {
|
|
|
|
|
boost::beast::http::response<ResponseBody> response{boost::beast::http::status::ok, request.version()};
|
|
|
|
|
response.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
|
|
|
|
|
response.set(boost::beast::http::field::content_type, content);
|
|
|
|
|
response.body() = body;
|
|
|
|
|
response.prepare_payload();
|
|
|
|
|
response.keep_alive(request.keep_alive());
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}; // namespace ServiceLogic
|
|
|
|
|
|
|
|
|
|
#include "ServiceLogic.inl"
|
|
|
|
|
|
|
|
|
|
#endif // SERVICELOGIC_H
|