Skip to content

Commit

Permalink
Checking for required parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamTambellini committed Dec 7, 2015
1 parent 4ab7073 commit a5dae07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions rest/RESTCallBack.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <assert.h>
#include <iostream>
#include "RESTCallBack.h"

RESTCallBack::~RESTCallBack()
Expand Down Expand Up @@ -27,6 +28,16 @@ void RESTCallBack::getDescription(Dumais::JSON::JSON& json)
RESTEngine::ResponseCode RESTCallBack::call(Dumais::JSON::JSON& json, const std::string& paramString, const std::string& dataString, std::smatch& matches)
{
RESTParameters params(paramString, mParamList);
// Let's check mandatory/required params
for (ParamMap::const_iterator it = mParamList.begin(); it != mParamList.end(); ++it) {
if (it->second.mRequired) {
if (params.getParam(it->first).empty()) {
std::cerr << "Missing mandatory parameter " << it->first << std::endl;
// todo : replace empty parameter value by default parameter value
}
}
}

RESTEngine::ResponseCode responseCode = RESTEngine::ResponseCode::OK;
RESTContext context ={
json,
Expand Down
8 changes: 7 additions & 1 deletion rest/RESTEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ class RESTEngine{
enum ResponseCode
{
OK,
Created,
Accepted,
BadRequest,
Forbidden,
NotFound,
MethodNotAllowed
MethodNotAllowed,
NotImplemented,
ServiceUnavailable
};

RESTEngine();
Expand Down
1 change: 1 addition & 0 deletions rest/RESTParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RESTParameters::RESTParameters(const std::string &params, const ParamMap &regist
break;
}
}

}

RESTParameters::~RESTParameters(){
Expand Down

0 comments on commit a5dae07

Please sign in to comment.