fix(api): always return JSON response on success (fixes #276)

Jef Roosens 2022-11-07 21:35:49 +01:00
parent 5542be0418
commit fc4dc30f74
2 changed files with 7 additions and 8 deletions

View File

@ -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)!
}
}

View File

@ -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))
}