Ручка PostUserTreatmentScheme.h

This commit is contained in:
2026-01-18 11:47:37 +03:00
parent c5c6058fb2
commit 05a135afc6
8 changed files with 209 additions and 18 deletions
+5
View File
@@ -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;
};
}
+42
View File
@@ -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
+5
View File
@@ -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