generated from Sithas/conan_template
Ручка PostUserTreatmentScheme.h
This commit is contained in:
@@ -10,6 +10,11 @@ class IUserTreatmentSchemeDAO {
|
||||
public:
|
||||
virtual std::vector<user_treatment_scheme_dto> FindByUserUUID(const std::string& login) = 0;
|
||||
|
||||
virtual void CreateUserTreatmentScheme(
|
||||
const std::string& user_login,
|
||||
const user_treatment_scheme_dto& dto
|
||||
) = 0;
|
||||
|
||||
virtual ~IUserTreatmentSchemeDAO() = default;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,4 +67,46 @@ std::vector<user_treatment_scheme_dto> MySQLUserTreatmentSchemesDAO::FindByUserU
|
||||
|
||||
return std::move(schemes);
|
||||
}
|
||||
|
||||
void MySQLUserTreatmentSchemesDAO::CreateUserTreatmentScheme(
|
||||
const std::string& user_uuid,
|
||||
const user_treatment_scheme_dto& dto)
|
||||
{
|
||||
session_.startTransaction();
|
||||
|
||||
try {
|
||||
session_.sql(R"(
|
||||
INSERT INTO up_and_down.user_treatment_schemes (
|
||||
uuid,
|
||||
user_uuid,
|
||||
treatment_name,
|
||||
instructions
|
||||
) VALUES (?, ?, ?, ?)
|
||||
)")
|
||||
.bind(
|
||||
dto.uuid,
|
||||
user_uuid,
|
||||
dto.treatment_name,
|
||||
dto.instructions
|
||||
)
|
||||
.execute();
|
||||
|
||||
for (const auto& medication_uuid : dto.medication_uuids) {
|
||||
session_.sql(R"(
|
||||
INSERT INTO up_and_down.treatment_schemes (
|
||||
user_treatment_schemes_uuid,
|
||||
medication_uuid
|
||||
) VALUES (?, ?)
|
||||
)")
|
||||
.bind(dto.uuid, medication_uuid)
|
||||
.execute();
|
||||
}
|
||||
|
||||
session_.commit();
|
||||
}
|
||||
catch (...) {
|
||||
session_.rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
} // uad
|
||||
|
||||
@@ -12,5 +12,10 @@ public:
|
||||
explicit MySQLUserTreatmentSchemesDAO(mysqlx::Session& session);
|
||||
|
||||
std::vector<user_treatment_scheme_dto> FindByUserUUID(const std::string& uuid) override;
|
||||
|
||||
void CreateUserTreatmentScheme(
|
||||
const std::string& user_login,
|
||||
const user_treatment_scheme_dto& dto
|
||||
) override;
|
||||
};
|
||||
} // uad
|
||||
|
||||
Reference in New Issue
Block a user