add a count parsing request to the ProcessRequest GET
This commit is contained in:
parent
c095982797
commit
123f180a6d
|
|
@ -41,6 +41,17 @@ void HttpSession::processRequest(http::request<http::string_body>&& request) {
|
|||
// Получаем случайный объект из БД
|
||||
json response = db->getRandomRecord();
|
||||
res.body() = response.dump(4);
|
||||
} else if (request.method() == http::verb::get && request.target().starts_with("/cards")) {
|
||||
std::string number{request.target()};
|
||||
auto start = number.find("?count=") + 7;
|
||||
auto end number.find("?", start);
|
||||
if (end == std::string::npos) {
|
||||
end = number.length();
|
||||
}
|
||||
int count = std::stoi(target.substr(start, end - start));
|
||||
count = std::max(1, std::min(count, 1000)); // валидация
|
||||
json response = db->getRandomRecords(count, 10, 1000);
|
||||
res.body() = response.dump(4);
|
||||
} else if (request.method() == http::verb::get && request.target() == "/health") {
|
||||
json response = {
|
||||
{"status", "ok"},
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <memory>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "database.hpp"
|
||||
|
|
|
|||
Loading…
Reference in New Issue