feat(server): less verbose repo DELETE responses

database-fixes
Jef Roosens 2022-09-11 21:28:37 +02:00
parent b6cd2f0bc2
commit cf67b46df0
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 11 additions and 13 deletions

View File

@ -1,8 +1,6 @@
module server module server
import web import web
import net.http
import web.response { new_response }
// delete_package tries to remove the given package. // delete_package tries to remove the given package.
['/:repo/:arch/:pkg'; auth; delete] ['/:repo/:arch/:pkg'; auth; delete]
@ -10,17 +8,17 @@ fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or { res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
app.lerror('Error while deleting package: $err.msg()') app.lerror('Error while deleting package: $err.msg()')
return app.json(http.Status.internal_server_error, new_response('Failed to delete package.')) return app.status(.internal_server_error)
} }
if res { if res {
app.linfo("Removed package '$pkg' from '$repo/$arch'") app.linfo("Removed package '$pkg' from '$repo/$arch'")
return app.json(http.Status.ok, new_response('Package removed.')) return app.status(.ok)
} else { } else {
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.") app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
return app.json(http.Status.not_found, new_response('Package not found.')) return app.status(.not_found)
} }
} }
@ -30,17 +28,17 @@ fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
res := app.repo.remove_arch_repo(repo, arch) or { res := app.repo.remove_arch_repo(repo, arch) or {
app.lerror('Error while deleting arch-repo: $err.msg()') app.lerror('Error while deleting arch-repo: $err.msg()')
return app.json(http.Status.internal_server_error, new_response('Failed to delete arch-repo.')) return app.status(.internal_server_error)
} }
if res { if res {
app.linfo("Removed '$repo/$arch'") app.linfo("Removed arch-repo '$repo/$arch'")
return app.json(http.Status.ok, new_response('Arch-repo removed.')) return app.status(.ok)
} else { } else {
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.") app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
return app.json(http.Status.not_found, new_response('Arch-repo not found.')) return app.status(.not_found)
} }
} }
@ -50,16 +48,16 @@ fn (mut app App) delete_repo(repo string) web.Result {
res := app.repo.remove_repo(repo) or { res := app.repo.remove_repo(repo) or {
app.lerror('Error while deleting repo: $err.msg()') app.lerror('Error while deleting repo: $err.msg()')
return app.json(http.Status.internal_server_error, new_response('Failed to delete repo.')) return app.status(.internal_server_error)
} }
if res { if res {
app.linfo("Removed '$repo'") app.linfo("Removed repo '$repo'")
return app.json(http.Status.ok, new_response('Repo removed.')) return app.status(.ok)
} else { } else {
app.linfo("Tried removing '$repo', but it doesn't exist.") app.linfo("Tried removing '$repo', but it doesn't exist.")
return app.json(http.Status.not_found, new_response('Repo not found.')) return app.status(.not_found)
} }
} }