generated from Sithas/conan_template
Почти завершенная регистрация
This commit is contained in:
+30
-14
@@ -18,24 +18,16 @@ string MySQLUserDAO::Create(const User& created_user)
|
||||
|
||||
optional<User> MySQLUserDAO::GetByGUID(string guid)
|
||||
{
|
||||
return nullopt;
|
||||
mysqlx::SqlResult sql_result = session_.sql("SELECT * FROM `up_and_down`.`users` WHERE (guid = '" + guid + "') LIMIT 1;"s).execute();
|
||||
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
std::optional<User> MySQLUserDAO::GetByLogin(std::string login)
|
||||
optional<User> MySQLUserDAO::GetByLogin(string login)
|
||||
{
|
||||
auto sql_result = session_.sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login + "') LIMIT 1;"s).execute();
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
mysqlx::SqlResult sql_result = session_.sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login + "') LIMIT 1;"s).execute();
|
||||
|
||||
if (rows.size())
|
||||
{
|
||||
auto row_data = *rows.begin();
|
||||
|
||||
string replicated_login = row_data[1].get<string>();
|
||||
|
||||
cout << "SUCCESS!" << endl;
|
||||
}
|
||||
|
||||
return nullopt;
|
||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||
}
|
||||
|
||||
vector<User> MySQLUserDAO::GetAll()
|
||||
@@ -54,4 +46,28 @@ bool MySQLUserDAO::Delete(string id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<User> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
||||
{
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
|
||||
if (!rows.size())
|
||||
{
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
auto row_data = *rows.begin();
|
||||
|
||||
string user_guid = row_data[0].get<string>();
|
||||
string user_login = row_data[1].get<string>();
|
||||
string user_hashed_password = row_data[2].get<string>();
|
||||
|
||||
User user;
|
||||
|
||||
user.SetGUID(user_guid);
|
||||
user.SetLogin(user_login);
|
||||
user.SetHashedPassword(user_hashed_password);
|
||||
|
||||
return optional<User>(std::move(user));
|
||||
}
|
||||
} // uad
|
||||
@@ -10,16 +10,19 @@ class MySQLUserDAO : public IUserDAO
|
||||
public:
|
||||
explicit MySQLUserDAO(mysqlx::Session& session);
|
||||
|
||||
std::string Create(const User& created_user);
|
||||
std::string Create(const User& created_user) override;
|
||||
|
||||
std::optional<User> GetByGUID(std::string guid);
|
||||
std::optional<User> GetByGUID(std::string guid) override;
|
||||
|
||||
std::optional<User> GetByLogin(std::string login);
|
||||
std::optional<User> GetByLogin(std::string login) override;
|
||||
|
||||
std::vector<User> GetAll();
|
||||
std::vector<User> GetAll() override;
|
||||
|
||||
bool Update(const User& u);
|
||||
bool Update(const User& u) override;
|
||||
|
||||
bool Delete(std::string id);
|
||||
bool Delete(std::string id) override;
|
||||
|
||||
private:
|
||||
std::optional<User> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user