Support linking of resources and configs through POST request. (#5)

Signed-off-by: Adam Capparelli <adam.capparelli@kinarasystems.com>
Co-authored-by: Adam Capparelli <adam.capparelli@kinarasystems.com>
This commit is contained in:
Adam Capparelli
2024-02-26 15:02:27 -05:00
committed by Ivan Chvets
parent 4ded8997cd
commit 2575fa628a
2 changed files with 22 additions and 0 deletions

View File

@@ -138,7 +138,22 @@ namespace OpenWifi {
return BadRequest(RESTAPI::Errors::ConfigBlockInvalid);
}
Types::UUIDvec_t ToVariables;
if (RawObject->has("variables")) {
for (const auto &i : NewObject.variables) {
if (!i.empty() && !StorageService()->VariablesDB().Exists("id", i)) {
return BadRequest(RESTAPI::Errors::VariableMustExist);
}
}
for (const auto &i : NewObject.variables)
ToVariables.emplace_back(i);
ToVariables = NewObject.variables;
}
if (DB_.CreateRecord(NewObject)) {
AddMembership(StorageService()->VariablesDB(),
&ProvObjects::VariableBlock::configurations, ToVariables, NewObject.info.id);
MoveUsage(StorageService()->PolicyDB(), DB_, "", NewObject.managementPolicy,
NewObject.info.id);
AddMembership(StorageService()->VenueDB(), &ProvObjects::Venue::configurations,

View File

@@ -389,6 +389,13 @@ namespace OpenWifi {
DB.ManipulateVectorMember(T, "id", Obj, Id, true);
}
template <typename db_type, typename Member>
void AddMembership(db_type &DB, Member T, const Types::UUIDvec_t &Obj, const std::string &Id) {
for (const auto &i : Obj) {
AddMembership(DB, T, i, Id);
}
}
template <typename db_type, typename Member>
void ManageMembership(db_type &DB, Member T, const std::string &From, const std::string &To,
const std::string &Id) {