drogon/drogon_ctl/templates/restful_controller_h.csp

80 lines
2.5 KiB
Plaintext
Raw Normal View History

<%inc#include "create_model.h"
using namespace drogon_ctl;
%>
/**
*
* [[fileName]].h
* This file is generated by drogon_ctl
*
*/
#pragma once
#include <drogon/HttpController.h>
<%c++
$$<<"using namespace drogon;\n";
auto namespaceVector=@@.get<std::vector<std::string>>("namespaceVector");
for(auto &name:namespaceVector)
{
%>
namespace {%name%}
{
<%c++
}
%>
/**
* @brief this class is created by the drogon_ctl command ([[ctlCommand]]).
* this class is a restful API controller.
*/
class [[className]]: public drogon::HttpController<[[className]]>
{
public:
METHOD_LIST_BEGIN
// use METHOD_ADD to add your custom processing function here;
<%c++
auto resource=@@.get<std::string>("resource");
if(resource.empty())
{
%>
METHOD_ADD([[className]]::getOne,"/{1}",Get,Options[[filters]]);
METHOD_ADD([[className]]::get,"",Get,Options[[filters]]);
METHOD_ADD([[className]]::create,"",Post,Options[[filters]]);
METHOD_ADD([[className]]::updateOne,"/{1}",Put,Options[[filters]]);
//METHOD_ADD([[className]]::update,"",Put,Options[[filters]]);
METHOD_ADD([[className]]::deleteOne,"/{1}",Delete,Options[[filters]]);
<%c++
}else
{
%>
ADD_METHOD_TO([[className]]::getOne,"{%resource%}/{1}",Get,Options[[filters]]);
ADD_METHOD_TO([[className]]::updateOne,"{%resource%}/{1}",Put,Options[[filters]]);
ADD_METHOD_TO([[className]]::deleteOne,"{%resource%}/{1}",Delete,Options[[filters]]);
ADD_METHOD_TO([[className]]::get,"{%resource%}",Get,Options[[filters]]);
ADD_METHOD_TO([[className]]::create,"{%resource%}",Post,Options[[filters]]);
//ADD_METHOD_TO([[className]]::update,"{%resource%}",Put,Options[[filters]]);
<%c++}%>
METHOD_LIST_END
void getOne(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback,
std::string &&id);
void updateOne(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback,
std::string &&id);
void deleteOne(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback,
std::string &&id);
void get(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback);
void create(const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback);
// void update(const HttpRequestPtr &req,
// std::function<void(const HttpResponsePtr &)> &&callback);
};
<%c++ for(size_t i=0;i<namespaceVector.size();++i)
{
$$<<"}\n";
}
%>