Add API endpoint for PUT /measure/@slug/@id.
This commit is contained in:
parent
02e0d1cae1
commit
038fa2f8a5
@ -453,6 +453,26 @@ proc start*(ctx: PMApiContext): void =
|
||||
error "unable to retrieve measurement:\n\t" & getCurrentExceptionMsg()
|
||||
jsonResp(Http500)
|
||||
|
||||
put "/measure/@slug/@id":
|
||||
checkAuth()
|
||||
|
||||
try:
|
||||
let measure = ctx.getMeasureForSlug(session.user.id, @"slug")
|
||||
var measurement = ctx.getMeasurementForMeasure(measure.id, parseUUID(@"id"))
|
||||
let jsonBody = parseJson(request.body)
|
||||
if jsonBody.hasKey("value"): measurement.value = jsonBody["value"].getInt
|
||||
if jsonBody.hasKey("timestamp"): measurement.timestamp = jsonBody["timestamp"].getStr.parseIso8601
|
||||
if jsonBody.hasKey("extData"): measurement.extData = jsonBody["extData"]
|
||||
resp($(%ctx.db.updateMeasurement(measurement)), JSON)
|
||||
|
||||
except ValueError: jsonResp(Http400, getCurrentExceptionMsg())
|
||||
except JsonParsingError: jsonResp(Http400, getCurrentExceptionMsg())
|
||||
except BadRequestError: jsonResp(Http400, getCurrentExceptionMsg())
|
||||
except NotFoundError: jsonResp(Http404, getCurrentExceptionMsg())
|
||||
except:
|
||||
error "unable to retrieve measurement:\n\t" & getCurrentExceptionMsg()
|
||||
jsonResp(Http500)
|
||||
|
||||
delete "/measure/@slug/@id":
|
||||
checkAuth()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user