Author: Paolo Lulli <paolo@lulli.net>
Test position Rest endpoint
server/db/position.go | 6 +- server/docs/docs.go | 65 +++++++++++++++++++++++++++++++++++++ server/docs/swagger.json | 65 +++++++++++++++++++++++++++++++++++++ server/docs/swagger.yaml | 44 +++++++++++++++++++++++++ server/rest/rest-position.go | 4 +-
diff --git a/server/db/position.go b/server/db/position.go index 2f1ca31efb2e7219870d1d81fd4a07e447e52d4d..128b7e40faf6316a3144d6f8c5a35c10cd49610f 100644 --- a/server/db/position.go +++ b/server/db/position.go @@ -16,14 +16,14 @@ "time" ) func SavePosition(idClient string, lat float64, lon float64, positionName string) { - q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s',toTimestamp(now()),'%f','%f','%s');", idClient, lat, lon, positionName) + q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s',toTimestamp(now()),%f,%f,'%s');", idClient, lat, lon, positionName) fmt.Printf("q=%s", q) Session.Query(q).Exec() } func SavePositionAt(idClient string, lat float64, lon float64, tstamp time.Time, positionName string) { timeAsBytes, _ := tstamp.UTC().MarshalText() - q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s','%s','%f','%f','%s');", idClient, string(timeAsBytes), lat, lon, positionName) - + q := fmt.Sprintf("insert into position ( id_client, ptime, lat, lon, name) values ('%s','%s',%f,%f,'%s');", idClient, string(timeAsBytes), lat, lon, positionName) + fmt.Printf("q=%s", q) Session.Query(q).Exec() } diff --git a/server/docs/docs.go b/server/docs/docs.go index 3819a6e5133c71765ee81b02829dffb837fc3d5a..92cd9d1b1212b0b1011b8366718c7646e5766d9d 100644 --- a/server/docs/docs.go +++ b/server/docs/docs.go @@ -245,7 +245,7 @@ ], "tags": [ "Metrics" ], - "summary": "Get the spcific metric {name} starting from the epoch {from}", + "summary": "Get the specific metric {name} starting from the epoch {from}", "parameters": [ { "type": "string", @@ -278,6 +278,47 @@ } } } } + }, + "/position": { + "post": { + "description": "store position", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Positions" + ], + "summary": "write position to db", + "parameters": [ + { + "type": "string", + "description": "clientCN", + "name": "X-SSL-Client-CN", + "in": "header", + "required": true + }, + { + "description": "Position body data", + "name": "position", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.PositionModel" + } + } + ], + "responses": { + "202": { + "description": "Accepted", + "schema": { + "type": "string" + } + } + } + } } }, "definitions": { @@ -339,6 +380,28 @@ "name": { "type": "string" }, "to": { + "type": "integer" + } + } + }, + "model.PositionModel": { + "type": "object", + "properties": { + "id_client": { + "type": "string" + }, + "lat": { + "description": "TODO Check parquet types", + "type": "number" + }, + "lon": { + "description": "TODO Check parquet types", + "type": "number" + }, + "name": { + "type": "string" + }, + "ptime": { "type": "integer" } } diff --git a/server/docs/swagger.json b/server/docs/swagger.json index 447aed70f93e5a6a7e056fd33113bca3648b1349..7879f76ac280dd8e848914e957e24f8e92b67642 100755 --- a/server/docs/swagger.json +++ b/server/docs/swagger.json @@ -238,7 +238,7 @@ ], "tags": [ "Metrics" ], - "summary": "Get the spcific metric {name} starting from the epoch {from}", + "summary": "Get the specific metric {name} starting from the epoch {from}", "parameters": [ { "type": "string", @@ -271,6 +271,47 @@ } } } } + }, + "/position": { + "post": { + "description": "store position", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Positions" + ], + "summary": "write position to db", + "parameters": [ + { + "type": "string", + "description": "clientCN", + "name": "X-SSL-Client-CN", + "in": "header", + "required": true + }, + { + "description": "Position body data", + "name": "position", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/model.PositionModel" + } + } + ], + "responses": { + "202": { + "description": "Accepted", + "schema": { + "type": "string" + } + } + } + } } }, "definitions": { @@ -332,6 +373,28 @@ "name": { "type": "string" }, "to": { + "type": "integer" + } + } + }, + "model.PositionModel": { + "type": "object", + "properties": { + "id_client": { + "type": "string" + }, + "lat": { + "description": "TODO Check parquet types", + "type": "number" + }, + "lon": { + "description": "TODO Check parquet types", + "type": "number" + }, + "name": { + "type": "string" + }, + "ptime": { "type": "integer" } } diff --git a/server/docs/swagger.yaml b/server/docs/swagger.yaml index d9a07e80f8f60d6aa06be2abce32540dfb0e7122..880f7eb10c381fa3b2da76bafe98c4d2f30cc568 100755 --- a/server/docs/swagger.yaml +++ b/server/docs/swagger.yaml @@ -40,6 +40,21 @@ type: string to: type: integer type: object + model.PositionModel: + properties: + id_client: + type: string + lat: + description: TODO Check parquet types + type: number + lon: + description: TODO Check parquet types + type: number + name: + type: string + ptime: + type: integer + type: object externalDocs: description: OpenAPI url: https://swagger.io/resources/open-api/ @@ -195,7 +210,7 @@ "200": description: OK schema: type: string - summary: Get the spcific metric {name} starting from the epoch {from} + summary: Get the specific metric {name} starting from the epoch {from} tags: - Metrics /metric/search: @@ -225,4 +240,31 @@ type: string summary: Get the metrics From ... and To when present tags: - Metrics + /position: + post: + consumes: + - application/json + description: store position + parameters: + - description: clientCN + in: header + name: X-SSL-Client-CN + required: true + type: string + - description: Position body data + in: body + name: position + required: true + schema: + $ref: '#/definitions/model.PositionModel' + produces: + - application/json + responses: + "202": + description: Accepted + schema: + type: string + summary: write position to db + tags: + - Positions swagger: "2.0" diff --git a/server/rest/rest-position.go b/server/rest/rest-position.go index 5300cf4f33637e7c03c2e38c1c93cfb8e7e84553..4177d4a544e12b67f269b6499ca9f4ce48b95938 100644 --- a/server/rest/rest-position.go +++ b/server/rest/rest-position.go @@ -15,7 +15,7 @@ // @Param X-SSL-Client-CN header string true "clientCN" // @Summary write position to db // @Schemes // @Description store position -// @Tags Events +// @Tags Positions // @Accept json // @Param position body model.PositionModel true "Position body data" // @Produce json @@ -31,7 +31,7 @@ return } clientCN := GetClientCN(c, cfg) - fmt.Printf("%s / %s ", clientCN, position.Name) + fmt.Printf("%s / %s / %f /%f", clientCN, position.Name, position.Lat, position.Lon) if position.Ptime == 0 { db.SavePosition(clientCN, position.Lat, position.Lon, position.Name)