Add sticker sub-commands inc and dec

Let sqlite do the work for incrementing or decrementing a sticker value.
This sub-commands are usefull to track playcounts with sticker values and
saves us one roundtrip.
This commit is contained in:
jcorporation
2024-12-11 21:41:20 +01:00
parent 78e643150f
commit 1078c1c1bf
7 changed files with 159 additions and 0 deletions

View File

@@ -58,6 +58,24 @@ public:
return CommandResult::OK;
}
virtual CommandResult Inc(const char *uri, const char *name, const char *value) {
sticker_database.IncValue(sticker_type,
ValidateUri(uri).c_str(),
name,
value);
return CommandResult::OK;
}
virtual CommandResult Dec(const char *uri, const char *name, const char *value) {
sticker_database.DecValue(sticker_type,
ValidateUri(uri).c_str(),
name,
value);
return CommandResult::OK;
}
virtual CommandResult Delete(const char *uri, const char *name) {
std::string validated_uri = ValidateUri(uri);
uri = validated_uri.c_str();
@@ -442,6 +460,14 @@ handle_sticker(Client &client, Request args, Response &r)
/* set */
if (args.size() == 5 && StringIsEqual(cmd, "set"))
return handler->Set(uri, sticker_name, args[4]);
/* inc */
if (args.size() == 5 && StringIsEqual(cmd, "inc"))
return handler->Inc(uri, sticker_name, args[4]);
/* dec */
if (args.size() == 5 && StringIsEqual(cmd, "dec"))
return handler->Dec(uri, sticker_name, args[4]);
/* delete */
if ((args.size() == 3 || args.size() == 4) && StringIsEqual(cmd, "delete"))