generated from Sithas/conan_template
База для ручки PostUserMedicationsExecutor.h
This commit is contained in:
+2
-2
@@ -38,8 +38,8 @@ add_executable(App ./src/main.cpp
|
|||||||
./src/db/mysql_connector.cpp
|
./src/db/mysql_connector.cpp
|
||||||
./src/db/mysql_connector.h
|
./src/db/mysql_connector.h
|
||||||
./src/DAO/IUserDAO.h
|
./src/DAO/IUserDAO.h
|
||||||
./src/entities/user.h
|
src/dtos/user_dto.h
|
||||||
./src/entities/medication.h
|
src/dtos/medication_dto.h
|
||||||
./src/DAO/MySQLUserDAO.cpp
|
./src/DAO/MySQLUserDAO.cpp
|
||||||
./src/DAO/MySQLUserDAO.h
|
./src/DAO/MySQLUserDAO.h
|
||||||
./src/endpoints_handlers/IExecutor.h
|
./src/endpoints_handlers/IExecutor.h
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
#include "../entities/user.h"
|
#include "../dtos/user_dto.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,16 +3,16 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../entities/medication.h"
|
#include "../dtos/medication_dto.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
class IMedicationsDAO
|
class IMedicationsDAO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]] virtual std::vector<medication> GetAll() const = 0;
|
[[nodiscard]] virtual std::vector<medication_dto> GetAll() const = 0;
|
||||||
|
|
||||||
[[nodiscard]] virtual std::string Create(const medication& m) const = 0;
|
[[nodiscard]] virtual std::string Create(const medication_dto& m) const = 0;
|
||||||
|
|
||||||
virtual ~IMedicationsDAO() = default;
|
virtual ~IMedicationsDAO() = default;
|
||||||
};
|
};
|
||||||
|
|||||||
+6
-6
@@ -4,22 +4,22 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "../entities/user.h"
|
#include "../dtos/user_dto.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
class IUserDAO
|
class IUserDAO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual std::string Create(const user& created_user) = 0;
|
virtual std::string Create(const user_dto& created_user) = 0;
|
||||||
|
|
||||||
virtual std::optional<user> GetByUUID(const std::string& uuid) = 0;
|
virtual std::optional<user_dto> GetByUUID(const std::string& uuid) = 0;
|
||||||
|
|
||||||
virtual std::optional<user> GetByLogin(const std::string& login) = 0;
|
virtual std::optional<user_dto> 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_dto>> GetAll(size_t limit, size_t offset) = 0;
|
||||||
|
|
||||||
virtual bool Update(const user& u) = 0;
|
virtual bool Update(const user_dto& u) = 0;
|
||||||
|
|
||||||
virtual bool Delete(const std::string& uuid) = 0;
|
virtual bool Delete(const std::string& uuid) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -10,20 +10,20 @@ MySQLMedicationsDAO::MySQLMedicationsDAO(mysqlx::Session& session): session_(ses
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<medication> MySQLMedicationsDAO::GetAll() const
|
std::vector<medication_dto> MySQLMedicationsDAO::GetAll() const
|
||||||
{
|
{
|
||||||
static const string sql_script = "SELECT uuid, name, dose, unit, is_urgent FROM up_and_down.medications;";
|
static const string sql_script = "SELECT uuid, name, dose, unit, is_urgent FROM up_and_down.medications;";
|
||||||
|
|
||||||
mysqlx::SqlResult sql_result = session_.sql(sql_script).execute();
|
mysqlx::SqlResult sql_result = session_.sql(sql_script).execute();
|
||||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||||
|
|
||||||
vector<medication> ret;
|
vector<medication_dto> ret;
|
||||||
|
|
||||||
if (rows.empty()) return ret;
|
if (rows.empty()) return ret;
|
||||||
|
|
||||||
for (const auto& row : rows)
|
for (const auto& row : rows)
|
||||||
{
|
{
|
||||||
medication m;
|
medication_dto m;
|
||||||
|
|
||||||
m.uuid = row[0].get<string>();
|
m.uuid = row[0].get<string>();
|
||||||
m.name = row[1].get<string>();
|
m.name = row[1].get<string>();
|
||||||
@@ -37,7 +37,7 @@ std::vector<medication> MySQLMedicationsDAO::GetAll() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MySQLMedicationsDAO::Create(const medication& m) const
|
std::string MySQLMedicationsDAO::Create(const medication_dto& m) const
|
||||||
{
|
{
|
||||||
boost::uuids::random_generator generator;
|
boost::uuids::random_generator generator;
|
||||||
boost::uuids::uuid uuid = generator();
|
boost::uuids::uuid uuid = generator();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "IMedicationsDAO.h"
|
#include "IMedicationsDAO.h"
|
||||||
#include "../entities/medication.h"
|
#include "../dtos/medication_dto.h"
|
||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
@@ -14,8 +14,8 @@ class MySQLMedicationsDAO : public IMedicationsDAO
|
|||||||
public:
|
public:
|
||||||
explicit MySQLMedicationsDAO(mysqlx::Session& session);
|
explicit MySQLMedicationsDAO(mysqlx::Session& session);
|
||||||
|
|
||||||
[[nodiscard]] std::vector<medication> GetAll() const override;
|
[[nodiscard]] std::vector<medication_dto> GetAll() const override;
|
||||||
|
|
||||||
[[nodiscard]] std::string Create(const medication& m) const override;
|
[[nodiscard]] std::string Create(const medication_dto& m) const override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -14,7 +14,7 @@ MySQLUserDAO::MySQLUserDAO(mysqlx::Session& session) :
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
string MySQLUserDAO::Create(const user& created_user)
|
string MySQLUserDAO::Create(const user_dto& created_user)
|
||||||
{
|
{
|
||||||
boost::uuids::random_generator generator;
|
boost::uuids::random_generator generator;
|
||||||
boost::uuids::uuid uuid = generator();
|
boost::uuids::uuid uuid = generator();
|
||||||
@@ -31,7 +31,7 @@ string MySQLUserDAO::Create(const user& created_user)
|
|||||||
return uuid_str;
|
return uuid_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
optional<user_dto> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||||
{
|
{
|
||||||
static const string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (uuid = ?) LIMIT 1;"s;
|
static const string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (uuid = ?) LIMIT 1;"s;
|
||||||
mysqlx::SqlResult sql_result = session_.
|
mysqlx::SqlResult sql_result = session_.
|
||||||
@@ -42,7 +42,7 @@ optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
|||||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
optional<user_dto> MySQLUserDAO::GetByLogin(const string& login)
|
||||||
{
|
{
|
||||||
static const std::string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (login = ?) LIMIT 1;"s;
|
static const std::string sql_script = "SELECT * FROM `up_and_down`.`users` WHERE (login = ?) LIMIT 1;"s;
|
||||||
mysqlx::SqlResult sql_result = session_.
|
mysqlx::SqlResult sql_result = session_.
|
||||||
@@ -53,7 +53,7 @@ optional<user> MySQLUserDAO::GetByLogin(const string& login)
|
|||||||
return GetSingleUserBySQLResult(std::move(sql_result));
|
return GetSingleUserBySQLResult(std::move(sql_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
pair<bool, vector<user_dto>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||||
{
|
{
|
||||||
static const string sql_script = "SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s;
|
static const string sql_script = "SELECT * FROM `up_and_down`.`users` LIMIT ? OFFSET ?;"s;
|
||||||
|
|
||||||
@@ -62,18 +62,18 @@ pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
|||||||
.bind(limit, offset)
|
.bind(limit, offset)
|
||||||
.execute();
|
.execute();
|
||||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||||
pair<bool, vector<user>> ret;
|
pair<bool, vector<user_dto>> ret;
|
||||||
|
|
||||||
if (!rows.size())
|
if (!rows.size())
|
||||||
{
|
{
|
||||||
ret.first = true;
|
ret.first = true;
|
||||||
ret.second = vector<user>{};
|
ret.second = vector<user_dto>{};
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.first = rows.size() < limit + 1;
|
ret.first = rows.size() < limit + 1;
|
||||||
ret.second = vector<user>{};
|
ret.second = vector<user_dto>{};
|
||||||
|
|
||||||
ret.second.reserve(limit);
|
ret.second.reserve(limit);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
user user;
|
user_dto user;
|
||||||
|
|
||||||
const string user_uuid = row[0].get<string>();
|
const string user_uuid = row[0].get<string>();
|
||||||
const string user_login = row[1].get<string>();
|
const string user_login = row[1].get<string>();
|
||||||
@@ -96,7 +96,7 @@ pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MySQLUserDAO::Update(const user& u)
|
bool MySQLUserDAO::Update(const user_dto& u)
|
||||||
{
|
{
|
||||||
static const string sql_script = "UPDATE `up_and_down`.`users` SET `login` = ? WHERE `uuid` = ?;"s;
|
static const string sql_script = "UPDATE `up_and_down`.`users` SET `login` = ? WHERE `uuid` = ?;"s;
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ bool MySQLUserDAO::Delete(const string& uuid)
|
|||||||
return !!schema.getAffectedItemsCount();
|
return !!schema.getAffectedItemsCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
std::optional<user_dto> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result)
|
||||||
{
|
{
|
||||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& s
|
|||||||
const string user_login = row_data[1].get<string>();
|
const string user_login = row_data[1].get<string>();
|
||||||
const string user_hashed_password = row_data[2].get<string>();
|
const string user_hashed_password = row_data[2].get<string>();
|
||||||
|
|
||||||
return optional<user>({
|
return optional<user_dto>({
|
||||||
.uuid = user_uuid,
|
.uuid = user_uuid,
|
||||||
.login = user_login,
|
.login = user_login,
|
||||||
.hashed_password = user_hashed_password
|
.hashed_password = user_hashed_password
|
||||||
|
|||||||
@@ -11,19 +11,19 @@ class MySQLUserDAO : public IUserDAO
|
|||||||
public:
|
public:
|
||||||
explicit MySQLUserDAO(mysqlx::Session& session);
|
explicit MySQLUserDAO(mysqlx::Session& session);
|
||||||
|
|
||||||
std::string Create(const user& created_user) override;
|
std::string Create(const user_dto& created_user) override;
|
||||||
|
|
||||||
std::optional<user> GetByUUID(const std::string& uuid) override;
|
std::optional<user_dto> GetByUUID(const std::string& uuid) override;
|
||||||
|
|
||||||
std::optional<user> GetByLogin(const std::string& login) override;
|
std::optional<user_dto> 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_dto>> GetAll(size_t limit, size_t offset) override;
|
||||||
|
|
||||||
bool Update(const user& u) override;
|
bool Update(const user_dto& u) override;
|
||||||
|
|
||||||
bool Delete(const std::string& uuid) override;
|
bool Delete(const std::string& uuid) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<user> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
std::optional<user_dto> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
struct medication
|
struct medication_dto
|
||||||
{
|
{
|
||||||
std::string uuid;
|
std::string uuid;
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
namespace uad
|
namespace uad
|
||||||
{
|
{
|
||||||
struct user
|
struct user_dto
|
||||||
{
|
{
|
||||||
std::string uuid;
|
std::string uuid;
|
||||||
std::string login;
|
std::string login;
|
||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s);
|
throw session_exception(http::status::unprocessable_entity, "Login or password are empty"s);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::optional<user> maybe_user = user_dao_->GetByLogin(login);
|
const std::optional<user_dto> maybe_user = user_dao_->GetByLogin(login);
|
||||||
|
|
||||||
if (!maybe_user.has_value() || maybe_user.value().hashed_password != HashPassword(password))
|
if (!maybe_user.has_value() || maybe_user.value().hashed_password != HashPassword(password))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
throw session_exception(http::status::conflict, "User with login "s + login + " exists"s);
|
throw session_exception(http::status::conflict, "User with login "s + login + " exists"s);
|
||||||
}
|
}
|
||||||
|
|
||||||
user user;
|
user_dto user;
|
||||||
|
|
||||||
user.login = login;
|
user.login = login;
|
||||||
user.hashed_password = HashPassword(password);
|
user.hashed_password = HashPassword(password);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
http::response<ResponseType> res{http::status::ok, req.version()};
|
http::response<ResponseType> res{http::status::ok, req.version()};
|
||||||
const std::vector<medication> medications = medications_dao_->GetAll();
|
const std::vector<medication_dto> medications = medications_dao_->GetAll();
|
||||||
value response_body;
|
value response_body;
|
||||||
|
|
||||||
response_body.emplace_object();
|
response_body.emplace_object();
|
||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::json::object ToJSON(const medication& m)
|
boost::json::object ToJSON(const medication_dto& m)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{ "uuid", m.uuid },
|
{ "uuid", m.uuid },
|
||||||
@@ -84,7 +84,7 @@ private:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::json::array toJSONArray(const std::vector<medication>& medications)
|
boost::json::array toJSONArray(const std::vector<medication_dto>& medications)
|
||||||
{
|
{
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
using namespace boost::json;
|
using namespace boost::json;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
|
|
||||||
const auto body = req.body();
|
const auto body = req.body();
|
||||||
value req_json;
|
value req_json;
|
||||||
medication m;
|
medication_dto m;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -97,7 +97,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::json::object ToJSON(const medication& m)
|
boost::json::object ToJSON(const medication_dto& m)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
{ "uuid", m.uuid },
|
{ "uuid", m.uuid },
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
#include "./session/WebsocketSession.h"
|
#include "./session/WebsocketSession.h"
|
||||||
#include "./listener/Listener.h"
|
#include "./listener/Listener.h"
|
||||||
#include "./db/mysql_connector.h"
|
#include "./db/mysql_connector.h"
|
||||||
#include "entities/user.h"
|
#include "dtos/user_dto.h"
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
|
|
||||||
namespace beast = boost::beast;
|
namespace beast = boost::beast;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ BOOST_FIXTURE_TEST_CASE(AuthRegistrationExecutor_Unsuccesfull_User_Registration,
|
|||||||
RouteAuthRegistrationExecutor executor(GetMySqlSession(), user_dao);
|
RouteAuthRegistrationExecutor executor(GetMySqlSession(), user_dao);
|
||||||
|
|
||||||
user_dao->Create(
|
user_dao->Create(
|
||||||
user {
|
user_dto {
|
||||||
.login = "MyLogin123456780"s + uuid,
|
.login = "MyLogin123456780"s + uuid,
|
||||||
.hashed_password = HashPassword("Qwerty123456"s)}
|
.hashed_password = HashPassword("Qwerty123456"s)}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user