mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-11-01 02:58:00 +00:00
Finishing DB refactor.
This commit is contained in:
@@ -3,52 +3,24 @@
|
||||
//
|
||||
|
||||
#include "RESTAPI_contact_list_handler.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
#include "RESTObjects/RESTAPI_ProvObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "framework/RESTAPI_errors.h"
|
||||
#include "RESTAPI_db_helpers.h"
|
||||
|
||||
namespace OpenWifi{
|
||||
void RESTAPI_contact_list_handler::DoGet() {
|
||||
if(!QB_.Select.empty()) {
|
||||
auto DevUUIDS = Utils::Split(QB_.Select);
|
||||
Poco::JSON::Array ObjArr;
|
||||
for(const auto &i:DevUUIDS) {
|
||||
ProvObjects::Contact E;
|
||||
Poco::JSON::Object Obj;
|
||||
if(StorageService()->ContactDB().GetRecord("id",i,E)) {
|
||||
E.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddContactExtendedInfo(E, Obj);
|
||||
ObjArr.add(Obj);
|
||||
} else {
|
||||
return BadRequest(RESTAPI::Errors::ContactMustExist + " ("+i+")");
|
||||
}
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("contacts", ObjArr);
|
||||
return ReturnObject(Answer);
|
||||
return ReturnRecordList<decltype(StorageService()->ContactDB()),
|
||||
ProvObjects::Contact>("contacts",StorageService()->ContactDB(),*this );
|
||||
} else if(QB_.CountOnly) {
|
||||
Poco::JSON::Object Answer;
|
||||
auto C = StorageService()->ContactDB().Count();
|
||||
ReturnCountOnly(C);
|
||||
return;
|
||||
return ReturnCountOnly(C);
|
||||
} else {
|
||||
ProvObjects::ContactVec Contacts;
|
||||
StorageService()->ContactDB().GetRecords(QB_.Offset,QB_.Limit,Contacts);
|
||||
Poco::JSON::Array ObjArray;
|
||||
for(const auto &i:Contacts) {
|
||||
Poco::JSON::Object Obj;
|
||||
i.to_json(Obj);
|
||||
if(QB_.AdditionalInfo)
|
||||
AddContactExtendedInfo(i, Obj);
|
||||
ObjArray.add(Obj);
|
||||
}
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set("contacts",ObjArray);
|
||||
return ReturnObject(Answer);
|
||||
return MakeJSONObjectArray("contacts", Contacts, *this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user