diff --git a/docs/connected_services/how_to/endpoints.md b/docs/connected_services/how_to/endpoints.md index f5c7176..18416e8 100644 --- a/docs/connected_services/how_to/endpoints.md +++ b/docs/connected_services/how_to/endpoints.md @@ -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 | diff --git a/include/bank_api.h b/include/bank_api.h index 1e58fff..eaff8d8 100644 --- a/include/bank_api.h +++ b/include/bank_api.h @@ -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"); #endif - METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](32 bits) + METHOD_ADD(api::SendFunds, "/v1/user/transfer", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) METHOD_ADD(api::VerifyPassword, "/v1/user/verify_password", Post, Options, "UserFilter", "JsonFilter"); //Meta Usage METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["pass"](string) METHOD_ADD(api::AdminChangePassword, "/v1/admin/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["pass"](string) - METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](32 bits) - METHOD_ADD(api::ImpactBal, "/v1/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](32 bits) + METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) and ["amount"](uint32) + METHOD_ADD(api::ImpactBal, "/v1/admin/impact_balance", Post, Options, "JsonFilter", "UserFilter"); //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", "JsonFilter"); METHOD_ADD(api::Contains, "/v1/user/exists?name={name}", Get, Options, "JsonFilter"); METHOD_ADD(api::AdminVerifyAccount, "/v1/admin/verify_account", Post, Options, "UserFilter", "JsonFilter"); + METHOD_ADD(api::PruneUsers, "/v1/admin/prune_users", Post, "UserFilter", "JsonFilter"); //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", "UserFilter"); //expects ["name"](string) ["amount"](32 bits) ["pass"](string) + METHOD_ADD(api::AdminAddUser, "/v1/admin/user/register", Post, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) ["amount"](uint32) ["pass"](string) METHOD_ADD(api::DelSelf, "/v1/user/delete", Delete, Options, "UserFilter", "JsonFilter"); METHOD_ADD(api::AdminDelUser, "/v1/admin/user/delete", Delete, Options, "JsonFilter", "UserFilter"); //expects ["name"](string) #endif diff --git a/src/bank_api.cpp b/src/bank_api.cpp index aff7fbb..860b355 100644 --- a/src/bank_api.cpp +++ b/src/bank_api.cpp @@ -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;