Also return a list of items that have been successfully added

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-10-08 09:00:49 +02:00
parent 97cc85553f
commit 425f791a19
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
2 changed files with 18 additions and 19 deletions

View File

@ -303,13 +303,16 @@ components:
This object is only present if the list has been processed (preceding PUT or POST request).
properties:
success:
description: How many domains were successfully added to the database
type: integer
example: 1
failed:
description: How many domains could not be added to the database
type: integer
example: 0
description: |
Array of items that were successfully added to the database.
type: array
items:
type: object
properties:
item:
description: Item that was added to the database
type: string
example: "example.com"
errors:
description: |
Array of errors that occurred during processing.
@ -320,7 +323,7 @@ components:
item:
description: Item that could not be added to the database
type: string
example: "example.com"
example: "example2.com"
error:
description: Error message
type: string

View File

@ -415,11 +415,9 @@ static int api_list_write(struct ftl_conn *api,
cJSON *elem = NULL;
cJSON *processed = JSON_NEW_OBJECT();
cJSON *errors = JSON_NEW_ARRAY();
cJSON *failed = cJSON_AddNumberToObject(processed, "failed", 0);
cJSON *success = cJSON_AddNumberToObject(processed, "success", 0);
cJSON_AddItemToObject(processed, "failed", failed);
cJSON_AddItemToObject(processed, "success", success);
cJSON *success = JSON_NEW_ARRAY();
cJSON_AddItemToObject(processed, "errors", errors);
cJSON_AddItemToObject(processed, "success", success);
cJSON_ArrayForEach(elem, row.items)
{
row.item = elem->valuestring;
@ -441,14 +439,12 @@ static int api_list_write(struct ftl_conn *api,
okay = true;
}
}
JSON_INCREMENT_NUMBER((okay ? success : failed), 1);
cJSON *details = JSON_NEW_OBJECT();
JSON_COPY_STR_TO_OBJECT(details, "item", row.item);
if(!okay)
{
cJSON *error = JSON_NEW_OBJECT();
JSON_COPY_STR_TO_OBJECT(error, "item", row.item);
JSON_COPY_STR_TO_OBJECT(error, "error", sql_msg);
cJSON_AddItemToArray(errors, error);
}
JSON_COPY_STR_TO_OBJECT(details, "error", sql_msg);
cJSON_AddItemToArray(okay ? success : errors, details);
}
// Inform the resolver that it needs to reload the domainlists