From fc4dc30f741c882368c616298b5b6ba06d5d6ce1 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 7 Nov 2022 21:35:49 +0100 Subject: [PATCH] fix(api): always return JSON response on success (fixes #276) --- src/console/targets/targets.v | 7 ++----- src/server/api_targets.v | 8 +++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/console/targets/targets.v b/src/console/targets/targets.v index 521ca23..4179363 100644 --- a/src/console/targets/targets.v +++ b/src/console/targets/targets.v @@ -227,8 +227,7 @@ fn remove(conf Config, id string) ! { if id_int != 0 { c := client.new(conf.address, conf.api_key) - res := c.remove_target(id_int)! - println(res.message) + c.remove_target(id_int)! } } @@ -245,9 +244,7 @@ fn patch(conf Config, id string, params map[string]string) ! { id_int := id.int() if id_int != 0 { c := client.new(conf.address, conf.api_key) - res := c.patch_target(id_int, params)! - - println(res.message) + c.patch_target(id_int, params)! } } diff --git a/src/server/api_targets.v b/src/server/api_targets.v index c4d32d2..16db7e9 100644 --- a/src/server/api_targets.v +++ b/src/server/api_targets.v @@ -47,7 +47,7 @@ fn (mut app App) v1_post_target() web.Result { id := app.db.add_target(new_repo) - return app.json(http.Status.ok, new_data_response(id)) + return app.json(.ok, new_data_response(id)) } // v1_delete_target removes a given target from the server's list. @@ -55,7 +55,7 @@ fn (mut app App) v1_post_target() web.Result { fn (mut app App) v1_delete_target(id int) web.Result { app.db.delete_target(id) - return app.status(.ok) + return app.json(.ok, new_response('')) } // v1_patch_target updates a target's data with the given query params. @@ -69,5 +69,7 @@ fn (mut app App) v1_patch_target(id int) web.Result { app.db.update_target_archs(id, arch_objs) } - return app.status(.ok) + repo := app.db.get_target(id) or { return app.status(.internal_server_error) } + + return app.json(.ok, new_data_response(repo)) }