mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
changed structure
This commit is contained in:
parent
893ca3884d
commit
faf63b0d4b
2 changed files with 26 additions and 24 deletions
|
|
@ -15,11 +15,11 @@ namespace v1
|
||||||
public:
|
public:
|
||||||
api(Bank &b);
|
api(Bank &b);
|
||||||
void GetBal(req_args, const std::string &name) const;
|
void GetBal(req_args, const std::string &name) const;
|
||||||
void GetLog(req_args, const std::string &name);
|
void GetLog(req_args);
|
||||||
void SendFunds(req_args, const std::string &name) const;
|
void SendFunds(req_args) const;
|
||||||
void VerifyPassword(req_args, const std::string &name) const;
|
void VerifyPassword(req_args) const;
|
||||||
|
|
||||||
void ChangePassword(req_args, const std::string &name) const;
|
void ChangePassword(req_args) const;
|
||||||
|
|
||||||
void Help(req_args) const;
|
void Help(req_args) const;
|
||||||
void Ping(req_args) const;
|
void Ping(req_args) const;
|
||||||
|
|
@ -35,13 +35,13 @@ namespace v1
|
||||||
METHOD_LIST_BEGIN
|
METHOD_LIST_BEGIN
|
||||||
|
|
||||||
//Usage
|
//Usage
|
||||||
METHOD_ADD(api::GetBal, "/users/{name}/bal", Get, Options); //done
|
METHOD_ADD(api::GetBal, "/user/bal?name={name}", Get, Options); //done
|
||||||
METHOD_ADD(api::GetLog, "/users/{name}/log", Get, Options, "UserFilter"); //snapshot not implemented
|
METHOD_ADD(api::GetLog, "/user/log", Get, Options, "UserFilter"); //snapshot not implemented
|
||||||
METHOD_ADD(api::SendFunds, "/users/{name}/transfer", Post, Options, "UserFilter"); //responses incomplete
|
METHOD_ADD(api::SendFunds, "/user/transfer", Post, Options, "UserFilter"); //responses incomplete
|
||||||
METHOD_ADD(api::VerifyPassword, "/users/{name}/verify_password", Get, Options); //done
|
METHOD_ADD(api::VerifyPassword, "/user/verify_password", Get, Options, "UserFilter"); //done
|
||||||
|
|
||||||
//Meta Usage
|
//Meta Usage
|
||||||
METHOD_ADD(api::ChangePassword, "/users/{name}/change_password", Patch, Options); //done
|
METHOD_ADD(api::ChangePassword, "/user/change_password", Patch, Options, "UserFilter"); //done
|
||||||
METHOD_ADD(api::SetBal, "/admin/{name}/bal?amount={amount}", Patch, Options);
|
METHOD_ADD(api::SetBal, "/admin/{name}/bal?amount={amount}", Patch, Options);
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,15 @@
|
||||||
resp->setStatusCode(R.first); \
|
resp->setStatusCode(R.first); \
|
||||||
callback(resp);
|
callback(resp);
|
||||||
|
|
||||||
|
#define RESPOND_TRUE \
|
||||||
|
auto resp = HttpResponse::newHttpJsonResponse(JsonCast(true)); \
|
||||||
|
resp->setStatusCode(k200OK); \
|
||||||
|
resp->setExpiredTime(0); \
|
||||||
|
callback(resp);
|
||||||
|
|
||||||
#define NAME_PARAM req->getBody()
|
#define NAME_PARAM req->getBody()
|
||||||
|
|
||||||
#define NAME_CHECK(suc) BankResponse b = (name == NAME_PARAM ? suc : BankResponse(k400BadRequest, "Requests name must match Auth's name"));
|
//#define NAME_CHECK(suc) BankResponse b = (name == NAME_PARAM ? suc : BankResponse(k400BadRequest, "Requests name must match Auth's name"));
|
||||||
|
|
||||||
namespace v1
|
namespace v1
|
||||||
{
|
{
|
||||||
|
|
@ -45,12 +51,11 @@ namespace v1
|
||||||
{
|
{
|
||||||
RESPONSE_PARSE(bank.GetBal(name));
|
RESPONSE_PARSE(bank.GetBal(name));
|
||||||
}
|
}
|
||||||
void api::GetLog(req_args, const std::string &name)
|
void api::GetLog(req_args)
|
||||||
{
|
{
|
||||||
if constexpr (max_log_size > 0)
|
if constexpr (max_log_size > 0)
|
||||||
{
|
{
|
||||||
NAME_CHECK(bank.GetLogs(name));
|
RESPONSE_PARSE(bank.GetLogs(NAME_PARAM.data()));
|
||||||
RESPONSE_PARSE(b);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -60,30 +65,27 @@ namespace v1
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void api::SendFunds(req_args, const std::string &name) const
|
void api::SendFunds(req_args) const
|
||||||
{
|
{
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
NAME_CHECK(bank.SendFunds(name, body["to"].asCString(), body["amount"].asUInt()));
|
RESPONSE_PARSE(bank.SendFunds(NAME_PARAM.data(), body["to"].asCString(), body["amount"].asUInt()));
|
||||||
RESPONSE_PARSE(b);
|
|
||||||
}
|
}
|
||||||
void api::VerifyPassword(req_args, const std::string &name) const
|
void api::VerifyPassword(req_args) const
|
||||||
{
|
{
|
||||||
NAME_CHECK(BankResponse(k200OK, true));
|
RESPOND_TRUE
|
||||||
RESPONSE_PARSE(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void api::ChangePassword(req_args, const std::string &name) const
|
void api::ChangePassword(req_args) const
|
||||||
{
|
{
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
bank.ChangePassword(name, std::move(body["new_pass"].asCString())); //may make asString()
|
bank.ChangePassword(NAME_PARAM.data(), std::move(body["new_pass"].asCString())); //may make asString()
|
||||||
NAME_CHECK(BankResponse(k200OK, true));
|
RESPOND_TRUE
|
||||||
RESPONSE_PARSE(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void api::Help(req_args) const
|
void api::Help(req_args) const
|
||||||
{
|
{
|
||||||
auto resp = HttpResponse::newHttpResponse();
|
auto resp = HttpResponse::newHttpResponse();
|
||||||
resp->setBody("");
|
resp->setBody(""); //will be filled in with docs
|
||||||
resp->setExpiredTime(0);
|
resp->setExpiredTime(0);
|
||||||
callback(resp);
|
callback(resp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue