mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🎨🔥 reduced Sub/Add Bal() to ImpactBal()
This commit is contained in:
parent
e9ccf6b227
commit
297b184a11
4 changed files with 6 additions and 36 deletions
|
|
@ -55,8 +55,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;
|
BankResponse ImpactBal(const std::string &name, int64_t amount) noexcept;
|
||||||
BankResponse SubBal(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(const std::string &name) noexcept;
|
bool AdminVerifyAccount(const std::string &name) noexcept;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,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 ImpactBal(req_args) const;
|
||||||
void SubBal(req_args) const;
|
|
||||||
|
|
||||||
void Help(req_args) const;
|
void Help(req_args) const;
|
||||||
void Close(req_args) const;
|
void Close(req_args) const;
|
||||||
|
|
@ -57,8 +56,7 @@ public:
|
||||||
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["new_pass"](string)
|
METHOD_ADD(api::ChangePassword, "/v1/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<true, false>"); //expects ["new_pass"](string)
|
||||||
METHOD_ADD(api::AdminChangePassword, "/v1/admin/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["new_pass"](string)
|
METHOD_ADD(api::AdminChangePassword, "/v1/admin/user/change_password", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["new_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::SetBal, "/v1/admin/set_balance", Patch, Options, "JsonFilter<true>", "UserFilter<false, true>"); //expects ["name"](string) and ["amount"](32 bits)
|
||||||
METHOD_ADD(api::AddBal, "/v1/admin/add_balance", Post, 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::SubBal, "/v1/admin/sub_balance", Post, Options, "JsonFilter<true>", "UserFilter<false, true>"); //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);
|
||||||
|
|
|
||||||
24
src/bank.cpp
24
src/bank.cpp
|
|
@ -162,7 +162,7 @@ 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
|
BankResponse Bank::ImpactBal(const std::string &name, int64_t amount) noexcept
|
||||||
{
|
{
|
||||||
if (amount)
|
if (amount)
|
||||||
{
|
{
|
||||||
|
|
@ -184,28 +184,6 @@ BankResponse Bank::AddBal(const std::string &name, uint32_t amount) noexcept
|
||||||
return {k404NotFound, "User not found"};
|
return {k404NotFound, "User not found"};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BankResponse Bank::SubBal(const std::string &name, uint32_t amount) noexcept
|
|
||||||
{
|
|
||||||
if (amount)
|
|
||||||
{
|
|
||||||
return {k400BadRequest, "Amount cannot be 0"};
|
|
||||||
}
|
|
||||||
if (users.modify_if(name, [amount](User &u) { amount >= u.balance ? u.balance = 0 : u.balance -= amount; }))
|
|
||||||
{
|
|
||||||
#if CONSERVATIVE_DISK_SAVE
|
|
||||||
#if MULTI_THREADED
|
|
||||||
save_flag.SetChangesOn();
|
|
||||||
#else
|
|
||||||
save_flag = true;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
return {k200OK, "Balance subtracted!"};
|
|
||||||
}
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -86,15 +86,10 @@ 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
|
void api::ImpactBal(req_args) const
|
||||||
{
|
{
|
||||||
GEN_BODY
|
GEN_BODY
|
||||||
RESPONSE_PARSE(bank.AddBal(body["name"].asCString(), body["amount"].asUInt()));
|
RESPONSE_PARSE(bank.ImpactBal(body["name"].asCString(), body["amount"].asInt64()));
|
||||||
}
|
|
||||||
void api::SubBal(req_args) const
|
|
||||||
{
|
|
||||||
GEN_BODY
|
|
||||||
RESPONSE_PARSE(bank.AddBal(body["name"].asCString(), body["amount"].asUInt()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//System Usage
|
//System Usage
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue