generated from Sithas/conan_template
Рабочая сборка с третьей ручкой
This commit is contained in:
+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
|
||||
|
||||
Reference in New Issue
Block a user