mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
✨ AddBal
This commit is contained in:
parent
77c6923765
commit
d6a55652ca
4 changed files with 26 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ public:
|
||||||
|
|
||||||
void ChangePassword(const std::string &name, std::string &&new_pass) noexcept;
|
void ChangePassword(const std::string &name, std::string &&new_pass) noexcept;
|
||||||
BankResponse SetBal(const std::string &name, uint32_t amount) noexcept;
|
BankResponse SetBal(const std::string &name, uint32_t amount) noexcept;
|
||||||
|
BankResponse AddBal(const std::string &name, uint32_t amount) noexcept;
|
||||||
bool Contains(const std::string &name) const noexcept;
|
bool Contains(const std::string &name) const noexcept;
|
||||||
bool AdminVerifyAccount(std::string_view name) noexcept;
|
bool AdminVerifyAccount(std::string_view name) noexcept;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ public:
|
||||||
void ChangePassword(req_args) const;
|
void ChangePassword(req_args) const;
|
||||||
void AdminChangePassword(req_args) const;
|
void AdminChangePassword(req_args) const;
|
||||||
void SetBal(req_args) const;
|
void SetBal(req_args) const;
|
||||||
|
void AddBal(req_args) const;
|
||||||
|
|
||||||
void Help(req_args) const;
|
void Help(req_args) const;
|
||||||
void Ping(req_args) const;
|
void Ping(req_args) const;
|
||||||
|
|
@ -54,6 +55,7 @@ public:
|
||||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["new_pass"](string)
|
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter", "UserFilter"); //expects ["new_pass"](string)
|
||||||
METHOD_ADD(api::AdminChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter", "AdminFilter"); //expects ["name"](string) and ["new_pass"](string)
|
METHOD_ADD(api::AdminChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter", "AdminFilter"); //expects ["name"](string) and ["new_pass"](string)
|
||||||
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter", "AdminFilter"); //expects ["name"](string) and ["amount"](32 bits)
|
METHOD_ADD(api::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter", "AdminFilter"); //expects ["name"](string) and ["amount"](32 bits)
|
||||||
|
METHOD_ADD(api::AddBal, "/v1/admin/give_balance", Post, Options, "JsonFilter", "AdminFilter"); //expects ["name"](string) and ["amount"](32 bits)
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
METHOD_ADD(api::Help, "/v1/help", Get, Options);
|
METHOD_ADD(api::Help, "/v1/help", Get, Options);
|
||||||
|
|
|
||||||
18
src/bank.cpp
18
src/bank.cpp
|
|
@ -149,6 +149,24 @@ BankResponse Bank::SetBal(const std::string &name, uint32_t amount) noexcept
|
||||||
return {k404NotFound, "User not found"};
|
return {k404NotFound, "User not found"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BankResponse Bank::AddBal(const std::string &name, uint32_t amount) noexcept
|
||||||
|
{
|
||||||
|
if (users.modify_if(name, [amount](User &u) { u.balance += amount; }))
|
||||||
|
{
|
||||||
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
|
#if MULTI_THREADED
|
||||||
|
save_flag.SetChangesOn();
|
||||||
|
#else
|
||||||
|
save_flag = true;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
return {k200OK, "Balance set!"};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return {k404NotFound, "User not found"};
|
||||||
|
}
|
||||||
|
}
|
||||||
bool Bank::Contains(const std::string &name) const noexcept
|
bool Bank::Contains(const std::string &name) const noexcept
|
||||||
{
|
{
|
||||||
return users.contains(name);
|
return users.contains(name);
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ void api::SetBal(req_args) const
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
RESPONSE_PARSE(bank.SetBal(body["name"].asCString(), body["amount"].asUInt()));
|
RESPONSE_PARSE(bank.SetBal(body["name"].asCString(), body["amount"].asUInt()));
|
||||||
}
|
}
|
||||||
|
void api::AddBal(req_args) const
|
||||||
|
{
|
||||||
|
GEN_BODY
|
||||||
|
RESPONSE_PARSE(bank.AddBal(body["name"].asCString(), body["amount"].asUInt()));
|
||||||
|
}
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
void api::Help(req_args) const
|
void api::Help(req_args) const
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue