mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
✨ PruneUsers() endpoint
This commit is contained in:
parent
c99e542111
commit
72864e6c18
3 changed files with 37 additions and 10 deletions
|
|
@ -65,12 +65,13 @@
|
|||
| ImpactBal | :heavy_check_mark: |
|
||||
|
||||
### Sytem Usage endpoints
|
||||
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
|
||||
| :----------------- | ---------------------------------- | ---------- | ------------------------------ | :---------: | :------------: | :---------: | :----------: | :----------------------: | :----------------------: | :----------------------: | :----------------------: |
|
||||
| Help | redirects to GitHub projects Docs | `N/A` | api/v1/help | `GET` | 301 | `N/A` | `N/A` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| Close | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| Contains | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| AdminVerifyAccount | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| name | purpose | json input | path | HTTP Method | correct status | return type | return value | Jresp | Jreq | A | U |
|
||||
| :----------------- | ------------------------------------------------------------------------------ | ------------------------------ | ------------------------------ | :---------: | :------------: | :---------: | :---------------------: | :----------------------: | :----------------------: | :----------------------: | :----------------------: |
|
||||
| Help | redirects to GitHub projects Docs | `N/A` | api/v1/help | `GET` | 301 | `N/A` | `N/A` | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| Close | saves & closes the CCash webserver | `N/A` | api/v1/admin/shutdown | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| Contains | checks wether a user exists | `N/A` | api/v1/user/exists?name={name} | `GET` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_multiplication_x: | :heavy_multiplication_x: |
|
||||
| AdminVerifyAccount | checks wether a user is the admin | `N/A` | api/v1/admin/verify_account | `POST` | 204 | `N/A` | `N/A` | :heavy_check_mark: | :heavy_multiplication_x: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
| PruneUsers | deletes users that are older then `{time}` and have less money then `{amount}` | {"time":int64,"amount":uint32} | api/v1/admin/prune_users | `POST` | 200 | uint64 | number of users deleted | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_multiplication_x: |
|
||||
|
||||
### System Usage endpoin errors
|
||||
| name | 401 | 404 | 406 |
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public:
|
|||
void Close(req_args) const;
|
||||
void Contains(req_args, const std::string &name) const;
|
||||
void AdminVerifyAccount(req_args) const;
|
||||
void PruneUsers(req_args) const;
|
||||
void ApiProperties(req_args) const;
|
||||
|
||||
void AddUser(req_args) const;
|
||||
|
|
@ -51,24 +52,25 @@ public:
|
|||
#else
|
||||
METHOD_ADD(api::GetLogs, "/v1/user/log", Get, Options, "JsonFilter<false>");
|
||||
#endif
|
||||
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["name"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["name"](string) and ["amount"](uint32)
|
||||
METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter<false, false>", "JsonFilter<false>");
|
||||
|
||||
//Meta Usage
|
||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["pass"](string)
|
||||
METHOD_ADD(api::AdminChangePassword, "/v1/admin/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["pass"](string)
|
||||
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::ImpactBal, "/v1/admin/impact_balance", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](32 bits)
|
||||
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](uint32)
|
||||
METHOD_ADD(api::ImpactBal, "/v1/admin/impact_balance", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](uint32)
|
||||
|
||||
//System Usage
|
||||
METHOD_ADD(api::Help, "/v1/help", Get, Options);
|
||||
METHOD_ADD(api::Close, "/v1/admin/shutdown", Post, Options, "UserFilter<false, true>", "JsonFilter<false>");
|
||||
METHOD_ADD(api::Contains, "/v1/user/exists?name={name}", Get, Options, "JsonFilter<false>");
|
||||
METHOD_ADD(api::AdminVerifyAccount, "/v1/admin/verify_account", Post, Options, "UserFilter<false, true>", "JsonFilter<false>");
|
||||
METHOD_ADD(api::PruneUsers, "/v1/admin/prune_users", Post, "UserFilter<false, true>", "JsonFilter<true>"); //expects ["time"](int64) and ["amount"](uint32)
|
||||
|
||||
//User Managment
|
||||
METHOD_ADD(api::AddUser, "/v1/user/register", Post, Options); //expects ["name"](string) ["pass"](string)
|
||||
METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) ["amount"](32 bits) ["pass"](string)
|
||||
METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) ["amount"](uint32) ["pass"](string)
|
||||
METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter<true, false>", "JsonFilter<false>");
|
||||
METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string)
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -228,6 +228,30 @@ void api::ApiProperties(req_args) const
|
|||
CACHE_FOREVER;
|
||||
callback(resp);
|
||||
}
|
||||
void api::PruneUsers(req_args) const
|
||||
{
|
||||
SIMD_JSON_GEN;
|
||||
BankResponse res;
|
||||
if (doc.error())
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Invalid JSON\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
auto time = doc.find_field("time").get_int64();
|
||||
auto amount = doc.find_field("amount").get_uint64();
|
||||
if (time.error() || amount.error())
|
||||
{
|
||||
res = BankResponse{k400BadRequest, "\"Missing JSON arg(s)\""};
|
||||
}
|
||||
else
|
||||
{
|
||||
res = bank.PruneUsers(time.value(), amount.value());
|
||||
}
|
||||
}
|
||||
RESPONSE_PARSE(std::move(res));
|
||||
}
|
||||
|
||||
void api::AddUser(req_args) const
|
||||
{
|
||||
SIMD_JSON_GEN;
|
||||
|
|
|
|||
Loading…
Reference in a new issue