Skip to content

Commit

Permalink
Merge pull request #96 from kinarasystems/wifi_13523_fix_resource_req…
Browse files Browse the repository at this point in the history
…uest_link_in_post

WIFI-13523: Fix: Support linking of resources and configs through POST request. (#5)
  • Loading branch information
stephb9959 authored Mar 20, 2024
2 parents 8fc7ce7 + 2575fa6 commit 10a39f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/RESTAPI/RESTAPI_configurations_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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,
Expand Down
7 changes: 7 additions & 0 deletions src/RESTAPI/RESTAPI_db_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 10a39f2

Please sign in to comment.