generated from Sithas/conan_template
База для ручки PostUserMedicationsExecutor.h
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "../entities/user.h"
|
||||
#include "../dtos/user_dto.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
|
||||
@@ -3,16 +3,16 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "../entities/medication.h"
|
||||
#include "../dtos/medication_dto.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IMedicationsDAO
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
+6
-6
@@ -4,22 +4,22 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
#include "../entities/user.h"
|
||||
#include "../dtos/user_dto.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
class IUserDAO
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
@@ -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;";
|
||||
|
||||
mysqlx::SqlResult sql_result = session_.sql(sql_script).execute();
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
|
||||
vector<medication> ret;
|
||||
vector<medication_dto> ret;
|
||||
|
||||
if (rows.empty()) return ret;
|
||||
|
||||
for (const auto& row : rows)
|
||||
{
|
||||
medication m;
|
||||
medication_dto m;
|
||||
|
||||
m.uuid = row[0].get<string>();
|
||||
m.name = row[1].get<string>();
|
||||
@@ -37,7 +37,7 @@ std::vector<medication> MySQLMedicationsDAO::GetAll() const
|
||||
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::uuid uuid = generator();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "IMedicationsDAO.h"
|
||||
#include "../entities/medication.h"
|
||||
#include "../dtos/medication_dto.h"
|
||||
|
||||
namespace uad
|
||||
{
|
||||
@@ -14,8 +14,8 @@ class MySQLMedicationsDAO : public IMedicationsDAO
|
||||
public:
|
||||
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::uuid uuid = generator();
|
||||
@@ -31,7 +31,7 @@ string MySQLUserDAO::Create(const user& created_user)
|
||||
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;
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
@@ -42,7 +42,7 @@ optional<user> MySQLUserDAO::GetByUUID(const string& uuid)
|
||||
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;
|
||||
mysqlx::SqlResult sql_result = session_.
|
||||
@@ -53,7 +53,7 @@ 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_dto>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
{
|
||||
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)
|
||||
.execute();
|
||||
list<mysqlx::Row> rows = sql_result.fetchAll();
|
||||
pair<bool, vector<user>> ret;
|
||||
pair<bool, vector<user_dto>> ret;
|
||||
|
||||
if (!rows.size())
|
||||
{
|
||||
ret.first = true;
|
||||
ret.second = vector<user>{};
|
||||
ret.second = vector<user_dto>{};
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.first = rows.size() < limit + 1;
|
||||
ret.second = vector<user>{};
|
||||
ret.second = vector<user_dto>{};
|
||||
|
||||
ret.second.reserve(limit);
|
||||
|
||||
@@ -84,7 +84,7 @@ pair<bool, vector<user>> MySQLUserDAO::GetAll(size_t limit, size_t offset)
|
||||
break;
|
||||
}
|
||||
|
||||
user user;
|
||||
user_dto user;
|
||||
|
||||
const string user_uuid = row[0].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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -118,7 +118,7 @@ bool MySQLUserDAO::Delete(const string& uuid)
|
||||
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();
|
||||
|
||||
@@ -133,7 +133,7 @@ std::optional<user> MySQLUserDAO::GetSingleUserBySQLResult(mysqlx::SqlResult&& s
|
||||
const string user_login = row_data[1].get<string>();
|
||||
const string user_hashed_password = row_data[2].get<string>();
|
||||
|
||||
return optional<user>({
|
||||
return optional<user_dto>({
|
||||
.uuid = user_uuid,
|
||||
.login = user_login,
|
||||
.hashed_password = user_hashed_password
|
||||
|
||||
@@ -11,19 +11,19 @@ class MySQLUserDAO : public IUserDAO
|
||||
public:
|
||||
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;
|
||||
|
||||
private:
|
||||
std::optional<user> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
std::optional<user_dto> GetSingleUserBySQLResult(mysqlx::SqlResult&& sql_result);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user