generated from Sithas/conan_template
Рабочая сборка с третьей ручкой
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "../entities/User.h"
|
||||
#include "../entities/user.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
|
||||
+6
-6
@@ -4,22 +4,22 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "../entities/User.h"
|
||||
#include "../entities/user.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IUserDAO
|
||||
{
|
||||
public:
|
||||
virtual std::string Create(const User& created_user) = 0;
|
||||
virtual std::string Create(const user& created_user) = 0;
|
||||
|
||||
virtual std::optional<User> GetByUUID(const std::string& uuid) = 0;
|
||||
virtual std::optional<user> GetByUUID(const std::string& uuid) = 0;
|
||||
|
||||
virtual std::optional<User> GetByLogin(const std::string& login) = 0;
|
||||
virtual std::optional<user> GetByLogin(const std::string& login) = 0;
|
||||
|
||||
virtual std::pair<bool, std::vector<User>> GetAll(size_t limit, size_t offset) = 0;
|
||||
virtual std::pair<bool, std::vector<user>> GetAll(size_t limit, size_t offset) = 0;
|
||||
|
||||
virtual bool Update(const User& u) = 0;
|
||||
virtual bool Update(const user& u) = 0;
|
||||
|
||||
virtual bool Delete(const std::string& uuid) = 0;
|
||||
|
||||
|
||||
+21
-21
@@ -13,7 +13,7 @@ MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) : session_(session)
|
||||
{
|
||||
}
|
||||
|
||||
string MySQLUserDAO::Create(const User& created_user)
|
||||
string MySQLUserDAO::Create(const user& created_user)
|
||||
{
|
||||
boost::uuids::random_generator generator;
|
||||
boost::uuids::uuid uuid = generator();
|
||||
@@ -23,13 +23,13 @@ string MySQLUserDAO::Create(const User& created_user)
|
||||
"INSERT INTO `up_and_down`.`users` (`uuid`, `login`, `hashed_password`) VALUES (?, ?, ?);"s;
|
||||
|
||||
session_.sql(sql_script)
|
||||
.bind(uuid_str, created_user.GetLogin(), created_user.GetHashedPassword())
|
||||
.bind(uuid_str, created_user.login, created_user.hashed_password)
|
||||
.execute();
|
||||
|
||||
return uuid_str;
|
||||
}
|
||||
|
||||
optional<User> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||
optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||
{
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
sql("SELECT * FROM `up_and_down`.`users` WHERE (uuid = '" + uuid +
|
||||
@@ -38,7 +38,7 @@ optional<User> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
optional<User> MySQLUserDAO::GetByLogin(const string& login)
|
||||
optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
||||
{
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login
|
||||
@@ -47,25 +47,25 @@ optional<User> MySQLUserDAO::GetByLogin(const string& login)
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
pair<bool, vector<User>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
{
|
||||
mysqlx::SqlResult sql_result = session_
|
||||
.sql("SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s)
|
||||
.bind(limit, offset)
|
||||
.execute();
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
pair<bool, vector<User>> ret;
|
||||
pair<bool, vector<user>> ret;
|
||||
|
||||
if (!rows.size())
|
||||
{
|
||||
ret.first = true;
|
||||
ret.second = vector<User>{};
|
||||
ret.second = vector<user>{};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.first = rows.size() != limit + 1;
|
||||
ret.second = vector<User>{};
|
||||
ret.second = vector<user>{};
|
||||
|
||||
ret.second.reserve(limit);
|
||||
|
||||
@@ -76,13 +76,13 @@ pair<bool, vector<User>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
break;
|
||||
}
|
||||
|
||||
User user;
|
||||
user user;
|
||||
|
||||
string user_uuid = row[0].get<string>();
|
||||
string user_login = row[1].get<string>();
|
||||
|
||||
user.SetLogin(user_login);
|
||||
user.SetUUID(user_uuid);
|
||||
user.login = user_login;
|
||||
user.uuid = user_uuid;
|
||||
|
||||
ret.second.push_back(std::move(user));
|
||||
--limit;
|
||||
@@ -91,15 +91,15 @@ pair<bool, vector<User>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool MySQLUserDAO::Update(const User& u)
|
||||
bool MySQLUserDAO::Update(const user& u)
|
||||
{
|
||||
auto schema = session_.getSchema("up_and_down");
|
||||
auto table = schema.getTable("users");
|
||||
mysqlx::Result res = table.update()
|
||||
.set("login", u.GetLogin())
|
||||
.set("hashed_password", u.GetHashedPassword())
|
||||
.set("login", u.login)
|
||||
.set("hashed_password", u.hashed_password)
|
||||
.where("uuid = :uuid")
|
||||
.bind("uuid", u.GetUUID())
|
||||
.bind("uuid", u.uuid)
|
||||
.execute();
|
||||
|
||||
return !!res.getAffectedItemsCount();
|
||||
@@ -117,7 +117,7 @@ bool MySQLUserDAO::Delete(const string& uuid)
|
||||
return !!res.getAffectedItemsCount();
|
||||
}
|
||||
|
||||
std::optional<User> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
||||
std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
||||
{
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
|
||||
@@ -132,12 +132,12 @@ std::optional<User> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& s
|
||||
string user_login = row_data[1].get<string>();
|
||||
string user_hashed_password = row_data[2].get<string>();
|
||||
|
||||
User user;
|
||||
user single_user;
|
||||
|
||||
user.SetUUID(user_uuid);
|
||||
user.SetLogin(user_login);
|
||||
user.SetHashedPassword(user_hashed_password);
|
||||
single_user.uuid = user_uuid;
|
||||
single_user.login = user_login;
|
||||
single_user.hashed_password = user_hashed_password;
|
||||
|
||||
return optional<User>(std::move(user));
|
||||
return optional<user>(std::move(single_user));
|
||||
}
|
||||
} // uad
|
||||
|
||||
@@ -10,19 +10,19 @@ class MySQLUserDAO : public IUserDAO
|
||||
public:
|
||||
explicit MySQLUserDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Create(const User& created_user) override;
|
||||
std::string Create(const user& created_user) override;
|
||||
|
||||
std::optional<User> GetByUUID(const std::string& uuid) override;
|
||||
std::optional<user> GetByUUID(const std::string& uuid) override;
|
||||
|
||||
std::optional<User> GetByLogin(const std::string& login) override;
|
||||
std::optional<user> GetByLogin(const std::string& login) override;
|
||||
|
||||
std::pair<bool, std::vector<User>> GetAll(size_t limit, size_t offset) override;
|
||||
std::pair<bool, std::vector<user>> GetAll(size_t limit, size_t offset) override;
|
||||
|
||||
bool Update(const User& u) override;
|
||||
bool Update(const user& u) override;
|
||||
|
||||
bool Delete(const std::string& uuid) override;
|
||||
|
||||
private:
|
||||
std::optional<User> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
std::optional<user> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user