Add some additional GET endpoints in the API.
This commit is contained in:
parent
038fa2f8a5
commit
066e70b4bf
@ -249,6 +249,11 @@ proc start*(ctx: PMApiContext): void =
|
||||
|
||||
resp(Http200, $(%session.user), JSON)
|
||||
|
||||
get "/users":
|
||||
checkAuth(true)
|
||||
|
||||
resp(Http200, $(%ctx.db.getAllUsers()))
|
||||
|
||||
post "/users":
|
||||
checkAuth(true)
|
||||
|
||||
@ -272,6 +277,11 @@ proc start*(ctx: PMApiContext): void =
|
||||
error "Could not create new user:\n\t" & getCurrentExceptionMsg()
|
||||
jsonResp(Http500)
|
||||
|
||||
get "/users/@userId":
|
||||
checkAuth(true)
|
||||
|
||||
resp(Http200, $(%ctx.db.getUser(parseUUID(@"userId"))))
|
||||
|
||||
delete "/users/@userId":
|
||||
checkAuth(true)
|
||||
|
||||
@ -283,6 +293,8 @@ proc start*(ctx: PMApiContext): void =
|
||||
|
||||
try:
|
||||
if not ctx.db.deleteUser(user): raiseEx "unable to delete user"
|
||||
makeJsonResp(Http200, "user " & user.email & " deleted")
|
||||
|
||||
except: jsonResp(Http500, getCurrentExceptionMsg())
|
||||
|
||||
get "/api-tokens":
|
||||
@ -318,15 +330,23 @@ proc start*(ctx: PMApiContext): void =
|
||||
debug getCurrentExceptionMsg()
|
||||
jsonResp(Http500)
|
||||
|
||||
get "/api-tokens/@tokenId":
|
||||
checkAuth()
|
||||
|
||||
try:
|
||||
resp(Http200, $(%ctx.db.getApiToken(parseUUID(@"tokenId"))))
|
||||
except NotFoundError: jsonResp(Http404, getCurrentExceptionMsg())
|
||||
except: jsonResp(Http500)
|
||||
|
||||
delete "/api-tokens/@tokenId":
|
||||
info "Request to delete API Token"
|
||||
checkAuth()
|
||||
|
||||
try:
|
||||
let token = ctx.db.getApiToken(parseUUID(@"tokenId"))
|
||||
if ctx.db.deleteApiToken(token): jsonResp(Http200)
|
||||
else: jsonResp(Http500)
|
||||
except: jsonResp(Http404)
|
||||
except NotFoundError: jsonResp(Http404, getCurrentExceptionMsg())
|
||||
except: jsonResp(Http500)
|
||||
|
||||
get "/measures":
|
||||
checkAuth()
|
||||
|
Loading…
x
Reference in New Issue
Block a user