Initial commit

This commit is contained in:
stephb9959
2022-03-11 22:56:06 -08:00
parent 157f3ab206
commit 3cb57d85e9
19 changed files with 2197 additions and 13 deletions

View File

@@ -0,0 +1,98 @@
//
// Created by stephane bourque on 2022-03-11.
//
#include "RESTAPI_board_handler.h"
#include "VenueCoordinator.h"
namespace OpenWifi {
void RESTAPI_board_handler::DoGet() {
auto id = GetBinding("id","");
if(id.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID);
}
AnalyticsObjects::BoardInfo B;
if(!StorageService()->BoardsDB().GetRecord("id",id,B)) {
return NotFound();
}
Poco::JSON::Object Answer;
B.to_json(Answer);
return ReturnObject(Answer);
}
void RESTAPI_board_handler::DoDelete() {
auto id = GetBinding("id","");
if(id.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID);
}
AnalyticsObjects::BoardInfo B;
if(!StorageService()->BoardsDB().GetRecord("id",id,B)) {
return NotFound();
}
if(!StorageService()->BoardsDB().DeleteRecord("id",id)) {
return NotFound();
}
VenueCoordinator()->StopVenue(id);
return OK();
}
void RESTAPI_board_handler::DoPost() {
auto id= GetBinding("id","");
if(id.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID);
}
auto RawObject = ParseStream();
AnalyticsObjects::BoardInfo NewObject;
if(!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
ProvObjects::CreateObjectInfo(RawObject,UserInfo_.userinfo,NewObject.info);
if(StorageService()->BoardsDB().CreateRecord(NewObject)) {
VenueCoordinator()->AddVenue(NewObject.info.id);
AnalyticsObjects::BoardInfo NewBoard;
StorageService()->BoardsDB().GetRecord("id",NewObject.info.id,NewBoard);
Poco::JSON::Object Answer;
NewBoard.to_json(Answer);
return ReturnObject(Answer);
}
}
void RESTAPI_board_handler::DoPut() {
auto id= GetBinding("id","");
if(id.empty()) {
return BadRequest(RESTAPI::Errors::MissingUUID);
}
AnalyticsObjects::BoardInfo Existing;
if(!StorageService()->BoardsDB().GetRecord("id",id,Existing)) {
return NotFound();
}
auto RawObject = ParseStream();
AnalyticsObjects::BoardInfo NewObject;
if(!NewObject.from_json(RawObject)) {
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
}
ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info);
if(RawObject->has("venueList")) {
// reconsile new venuelist compared to old...
}
if(StorageService()->BoardsDB().CreateRecord(NewObject)) {
VenueCoordinator()->ModifyVenue(NewObject.info.id);
AnalyticsObjects::BoardInfo NewBoard;
StorageService()->BoardsDB().GetRecord("id",NewObject.info.id,NewBoard);
Poco::JSON::Object Answer;
NewBoard.to_json(Answer);
return ReturnObject(Answer);
}
}
}