mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🎨 changed how API versions are handled
This commit is contained in:
parent
539df650ea
commit
d9986db962
4 changed files with 158 additions and 163 deletions
|
|
@ -4,7 +4,7 @@
|
|||
#include <shared_mutex>
|
||||
#include <atomic>
|
||||
#include <drogon/HttpTypes.h>
|
||||
#include "error_responses.hpp"
|
||||
#include "error_responses.hpp" //temporary
|
||||
#include "parallel-hashmap/parallel_hashmap/phmap.h"
|
||||
#include "user.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ using namespace drogon;
|
|||
|
||||
#define req_args const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback
|
||||
|
||||
namespace v1
|
||||
{
|
||||
#if V1_API
|
||||
class api : public HttpController<api, false>
|
||||
{
|
||||
Bank &bank;
|
||||
|
|
@ -36,13 +35,13 @@ namespace v1
|
|||
METHOD_LIST_BEGIN
|
||||
|
||||
//Usage
|
||||
METHOD_ADD(api::GetBal, "/user/bal?name={name}", Get, Options); //done
|
||||
METHOD_ADD(api::GetLog, "/user/log", Get, Options, "UserFilter"); //snapshot not implemented
|
||||
METHOD_ADD(api::SendFunds, "/user/transfer", Post, Options, "UserFilter"); //responses incomplete
|
||||
METHOD_ADD(api::VerifyPassword, "/user/verify_password", Get, Options, "UserFilter"); //done
|
||||
METHOD_ADD(api::GetBal, "/v1/user/bal?name={name}", Get, Options); //done
|
||||
METHOD_ADD(api::GetLog, "/v1/user/log", Get, Options, "UserFilter"); //snapshot not implemented
|
||||
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "UserFilter"); //responses incomplete
|
||||
METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Get, Options, "UserFilter"); //done
|
||||
|
||||
//Meta Usage
|
||||
METHOD_ADD(api::ChangePassword, "/user/change_password", Patch, Options, "UserFilter"); //done
|
||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "UserFilter"); //done
|
||||
METHOD_ADD(api::SetBal, "/admin/{name}/bal?amount={amount}", Patch, Options);
|
||||
|
||||
//System Usage
|
||||
|
|
@ -60,4 +59,4 @@ namespace v1
|
|||
|
||||
METHOD_LIST_END
|
||||
};
|
||||
};
|
||||
#endif
|
||||
8
main.cpp
8
main.cpp
|
|
@ -84,9 +84,7 @@ int main(int argc, char **argv)
|
|||
}).detach();
|
||||
}
|
||||
|
||||
#if V1_API
|
||||
auto APIv1 = std::make_shared<v1::api>(bank); //v1
|
||||
#endif
|
||||
auto API = std::make_shared<api>(bank);
|
||||
auto user_filter = std::make_shared<UserFilter>(bank);
|
||||
auto admin_filter = std::make_shared<AdminFilter>(bank);
|
||||
|
||||
|
|
@ -98,9 +96,7 @@ int main(int argc, char **argv)
|
|||
.loadConfigFile(config_location)
|
||||
.registerFilter(user_filter)
|
||||
.registerFilter(admin_filter)
|
||||
#if V1_API
|
||||
.registerController(APIv1)
|
||||
#endif
|
||||
.registerController(API)
|
||||
.setThreadNum(get_nprocs())
|
||||
.run();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@
|
|||
const auto body = temp_req ? *temp_req : Json::Value();
|
||||
|
||||
#define RESPONSE_PARSE(R) \
|
||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(std::move(R.second))); \
|
||||
resp->setStatusCode(R.first); \
|
||||
\
|
||||
auto r = R; \
|
||||
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(std::move(r.second))); \
|
||||
resp->setStatusCode(r.first); \
|
||||
callback(resp);
|
||||
|
||||
#define RESPOND_TRUE \
|
||||
|
|
@ -20,10 +22,6 @@
|
|||
|
||||
#define NAME_PARAM req->getBody()
|
||||
|
||||
//#define NAME_CHECK(suc) BankResponse b = (name == NAME_PARAM ? suc : BankResponse(k400BadRequest, "Requests name must match Auth's name"));
|
||||
|
||||
namespace v1
|
||||
{
|
||||
template <typename T>
|
||||
constexpr Json::Value JsonCast(T &&val)
|
||||
{
|
||||
|
|
@ -45,7 +43,10 @@ namespace v1
|
|||
}
|
||||
}
|
||||
|
||||
api::api(Bank &b) : bank(b) {}
|
||||
#if V1_API
|
||||
api::api(Bank &b) : bank(b)
|
||||
{
|
||||
}
|
||||
|
||||
void api::GetBal(req_args, const std::string &name) const
|
||||
{
|
||||
|
|
@ -140,5 +141,4 @@ namespace v1
|
|||
{
|
||||
JSON(bank.AdminVerifyPass(PASS_HEADER));
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in a new issue