[MOD] Use switch instead of if/else if

This commit is contained in:
lda 2023-11-01 18:04:23 +01:00
parent 688c1d3b9e
commit 7ec10703cd
Signed by: lda
GPG key ID: 6898757653ABE3E6

View file

@ -43,7 +43,14 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
HttpRequestMethod method = HttpRequestMethodGet(args->context);
if ((method != HTTP_GET))
Array *tokensarray;
Array *tokens;
RegTokenInfo *info;
size_t i;
if (method != HTTP_GET)
{
char *msg = "Route only supports GET for now.";
HttpResponseStatus(args->context, HTTP_BAD_REQUEST);
@ -73,43 +80,43 @@ ROUTE_IMPL(RouteAdminTokens, path, argp)
goto finish;
}
if (method == HTTP_GET && ArraySize(path) == 0)
switch (method)
{
Array *tokensarray = ArrayCreate();
/* Get all registration tokens */
Array *tokens = DbList(db, 2, "tokens", "registration");
size_t i;
case HTTP_GET:
if (ArraySize(path) == 0)
{
tokensarray = ArrayCreate();
/* Get all registration tokens */
tokens = DbList(db, 2, "tokens", "registration");
response = HashMapCreate();
response = HashMapCreate();
for (i = 0; i < ArraySize(tokens); i++)
{
/* TODO: Move this inside it's own `RegTokenJSON`
* function */
char *tokenname = ArrayGet(tokens, i);
for (i = 0; i < ArraySize(tokens); i++)
{
char *tokenname = ArrayGet(tokens, i);
RegTokenInfo *info = RegTokenGetInfo(db, tokenname);
HashMap *jsoninfo = RegTokenJSON(info);
info = RegTokenGetInfo(db, tokenname);
HashMap *jsoninfo = RegTokenJSON(info);
RegTokenClose(info);
RegTokenFree(info);
ArrayAdd(tokensarray, JsonValueObject(jsoninfo));
}
JsonSet(response, JsonValueArray(tokensarray), 1, "tokens");
DbListFree(tokens);
break;
}
info = RegTokenGetInfo(db, ArrayGet(path, 0));
response = RegTokenJSON(info);
RegTokenClose(info);
RegTokenFree(info);
ArrayAdd(tokensarray, JsonValueObject(jsoninfo));
}
JsonSet(response, JsonValueArray(tokensarray), 1, "tokens");
DbListFree(tokens);
}
else if (method == HTTP_GET && ArraySize(path) == 1)
{
RegTokenInfo *info = RegTokenGetInfo(db, ArrayGet(path, 0));
response = RegTokenJSON(info);
RegTokenClose(info);
RegTokenFree(info);
break;
}
finish:
UserUnlock(user);