Завершенная регистрация

This commit is contained in:
Антон
2025-08-30 09:49:24 +03:00
parent ec3817fad6
commit 9112bc21db
2 changed files with 32 additions and 8 deletions
+23 -6
View File
@@ -1,3 +1,5 @@
#include <boost/uuid.hpp>
#include "MySQLUserDAO.h" #include "MySQLUserDAO.h"
#include <iostream> #include <iostream>
@@ -7,32 +9,47 @@ using namespace string_literals;
namespace uad namespace uad
{ {
MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session): session_(session) MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) : session_(session)
{ {
} }
string MySQLUserDAO::Create(const User& created_user) string MySQLUserDAO::Create(const User& created_user)
{ {
return ""s; boost::uuids::random_generator generator;
boost::uuids::uuid uuid = generator();
std::string uuid_str = boost::uuids::to_string(uuid);
string sql_script =
"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())
.execute();
return uuid_str;
} }
optional<User> MySQLUserDAO::GetByUUID(string uuid) optional<User> MySQLUserDAO::GetByUUID(string uuid)
{ {
mysqlx::SqlResult sql_result = session_.sql("SELECT * FROM `up_and_down`.`users` WHERE (uuid = '" + uuid + "') LIMIT 1;"s).execute(); mysqlx::SqlResult sql_result = session_.
sql("SELECT * FROM `up_and_down`.`users` WHERE (uuid = '" + uuid +
"') LIMIT 1;"s).execute();
return GetSingleUserBySQLResult(std::move(sql_result)); return GetSingleUserBySQLResult(std::move(sql_result));
} }
optional<User> MySQLUserDAO::GetByLogin(string login) optional<User> MySQLUserDAO::GetByLogin(string login)
{ {
mysqlx::SqlResult sql_result = session_.sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login + "') LIMIT 1;"s).execute(); mysqlx::SqlResult sql_result = session_.
sql("SELECT * FROM `up_and_down`.`users` WHERE (login = '" + login
+ "') LIMIT 1;"s).execute();
return GetSingleUserBySQLResult(std::move(sql_result)); return GetSingleUserBySQLResult(std::move(sql_result));
} }
vector<User> MySQLUserDAO::GetAll() vector<User> MySQLUserDAO::GetAll()
{ {
vector<User> users {}; vector<User> users{};
return {}; return {};
} }
@@ -70,4 +87,4 @@ std::optional<User> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& s
return optional<User>(std::move(user)); return optional<User>(std::move(user));
} }
} // uad } // uad
@@ -4,6 +4,7 @@
#include <boost/json.hpp> #include <boost/json.hpp>
#include <mysqlx/xdevapi.h> #include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h> #include <mysqlx/common/api.h>
#include <boost/uuid.hpp>
#include "IExecutor.h" #include "IExecutor.h"
#include "../DAO/IUserDAO.h" #include "../DAO/IUserDAO.h"
@@ -94,13 +95,19 @@ public:
user.SetLogin(login); user.SetLogin(login);
user.SetPassword(password); user.SetPassword(password);
const auto uuid_stringified = user_dao_->Create(user);
http::response<ResponseType> res{ http::response<ResponseType> res{
http::status::created, req.version() http::status::created, req.version()
}; };
response_body.as_object().emplace( response_body.as_object().emplace(
"Result", "uuid",
"OK.Created." uuid_stringified
);
response_body.as_object().emplace(
"login",
user.GetLogin()
); );
res.body() = serialize(response_body); res.body() = serialize(response_body);