generated from Sithas/conan_template
Доработка интерфейса ДАО
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- Посмотреть пулл соединений(Object pool) при использовании базы данных(посмотреть api MySQL-Connector)
|
- Посмотреть пулл соединений(Object pool) при использовании базы данных(посмотреть api MySQL-Connector)
|
||||||
- Посмотреть, что дает MySQL, какие там есть возможность
|
- Посмотреть, что дает MySQL, какие там есть возможность
|
||||||
- Посмотреть и подумать, что лучше - корутины или многопоточность?
|
- Посмотреть и подумать, что лучше - корутины или многопоточность?
|
||||||
|
- Покрыть тестами класс User и AuthRegistrationExecutor
|
||||||
|
|
||||||
# UseCase'ы приложения:
|
# UseCase'ы приложения:
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public:
|
|||||||
|
|
||||||
virtual std::optional<User> GetByGUID(std::string guid) = 0;
|
virtual std::optional<User> GetByGUID(std::string guid) = 0;
|
||||||
|
|
||||||
|
virtual std::optional<User> GetByLogin(std::string login) = 0;
|
||||||
|
|
||||||
virtual std::vector<User> GetAll() = 0;
|
virtual std::vector<User> GetAll() = 0;
|
||||||
|
|
||||||
virtual bool Update(const User& u) = 0;
|
virtual bool Update(const User& u) = 0;
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ optional<User> MySQLUserDAO::GetByGUID(string guid)
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<User> MySQLUserDAO::GetByLogin(std::string login)
|
||||||
|
{
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
vector<User> MySQLUserDAO::GetAll()
|
vector<User> MySQLUserDAO::GetAll()
|
||||||
{
|
{
|
||||||
vector<User> users {};
|
vector<User> users {};
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public:
|
|||||||
|
|
||||||
std::optional<User> GetByGUID(std::string guid);
|
std::optional<User> GetByGUID(std::string guid);
|
||||||
|
|
||||||
|
std::optional<User> GetByLogin(std::string login);
|
||||||
|
|
||||||
std::vector<User> GetAll();
|
std::vector<User> GetAll();
|
||||||
|
|
||||||
bool Update(const User& u);
|
bool Update(const User& u);
|
||||||
|
|||||||
@@ -26,18 +26,27 @@ public:
|
|||||||
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
boost::beast::http::request<Body, boost::beast::http::basic_fields<Allocator>>&& req
|
||||||
) override
|
) override
|
||||||
{
|
{
|
||||||
|
using namespace boost;
|
||||||
|
using namespace boost::json;
|
||||||
|
using namespace boost::beast;
|
||||||
|
|
||||||
auto body = req.body();
|
auto body = req.body();
|
||||||
boost::json::object json_as_object = boost::json::parse(body).as_object();
|
object json_as_object = json::parse(body).as_object();
|
||||||
|
|
||||||
std::string login = boost::json::serialize(json_as_object.at("login").as_string());
|
std::string login = serialize(json_as_object.at("login").as_string());
|
||||||
std::string password = boost::json::serialize(json_as_object.at("password").as_string());
|
std::string password = serialize(json_as_object.at("password").as_string());
|
||||||
|
|
||||||
boost::beast::http::response<ResponseType> res{
|
User user;
|
||||||
boost::beast::http::status::ok, req.version()
|
|
||||||
|
user.SetLogin(login);
|
||||||
|
user.SetPassword(password);
|
||||||
|
|
||||||
|
http::response<ResponseType> res{
|
||||||
|
http::status::ok, req.version()
|
||||||
};
|
};
|
||||||
|
|
||||||
res.body() = "{ \"detail\": \"ok\"}";
|
res.body() = "{ \"detail\": \"ok\"}";
|
||||||
res.set(boost::beast::http::field::content_type, "application/json");
|
res.set(http::field::content_type, "application/json");
|
||||||
res.content_length(res.body().size());
|
res.content_length(res.body().size());
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
+16
-5
@@ -1,28 +1,39 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "User.h"
|
#include "User.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
const std::string& User::GetGUID() const noexcept
|
const string& User::GetGUID() const noexcept
|
||||||
{
|
{
|
||||||
return guid_;
|
return guid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::SetGUID(const std::string& new_guid)
|
void User::SetGUID(const string& new_guid)
|
||||||
{
|
{
|
||||||
guid_ = new_guid;
|
guid_ = new_guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& User::GetLogin() const noexcept
|
const string& User::GetLogin() const noexcept
|
||||||
{
|
{
|
||||||
return login_;
|
return login_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::SetLogin(const std::string& login)
|
void User::SetLogin(const string& login)
|
||||||
{
|
{
|
||||||
login_ = login;
|
login_ = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& User::GetHashedPassword() const noexcept
|
void User::SetPassword(const string& password)
|
||||||
|
{
|
||||||
|
size_t calculated_hash = hash<string>{}(password);
|
||||||
|
hashed_password_ = ToHex((byte*)&calculated_hash, sizeof(calculated_hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
const string& User::GetHashedPassword() const noexcept
|
||||||
{
|
{
|
||||||
return hashed_password_;
|
return hashed_password_;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "../helpers/helpers.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
std::string guid_;
|
std::string guid_;
|
||||||
std::string login_;
|
std::string login_;
|
||||||
const std::string hashed_password_;
|
std::string hashed_password_;
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] const std::string& GetGUID() const noexcept;
|
[[nodiscard]] const std::string& GetGUID() const noexcept;
|
||||||
|
|
||||||
@@ -18,6 +20,8 @@ public:
|
|||||||
|
|
||||||
void SetLogin(const std::string& login);
|
void SetLogin(const std::string& login);
|
||||||
|
|
||||||
|
void SetPassword(const std::string& password);
|
||||||
|
|
||||||
[[nodiscard]] const std::string& GetHashedPassword() const noexcept;
|
[[nodiscard]] const std::string& GetHashedPassword() const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user