yats.git

commit 4c3ec1d898e31489b7659862c56a405d3b0de3dc

Author: Paolo Lulli <paolo@lulli.net>

Fix broken Openapi 3.x conversion

 openapi/swagger.json | 265 ++++++++++++++++++++++++++++++++++++++++++++-
 openapi/swagger.yaml | 205 +++++++++++++++++++++++++++++++---
  | 10 -
 server/main.go | 6 


diff --git a/openapi/swagger.json b/openapi/swagger.json
index 331442d30dacaa5a8cf7af158e08dbf3355d3447..9c226e3acae8029699206c2105ef67a805895990 100755
--- a/openapi/swagger.json
+++ b/openapi/swagger.json
@@ -23,6 +23,9 @@                     },
                     "id_client": {
                         "type": "string"
                     },
+                    "source": {
+                        "type": "string"
+                    },
                     "to": {
                         "type": "integer"
                     }
@@ -57,6 +60,48 @@                     },
                     "name": {
                         "type": "string"
                     },
+                    "source": {
+                        "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"
+            },
+            "model.PositionSearchRequest": {
+                "properties": {
+                    "from": {
+                        "type": "integer"
+                    },
+                    "id_client": {
+                        "type": "string"
+                    },
+                    "source": {
+                        "type": "string"
+                    },
                     "to": {
                         "type": "integer"
                     }
@@ -71,8 +116,9 @@         "url": "https://swagger.io/resources/open-api/"
     },
     "info": {
         "contact": {
+            "email": "info@kevwe.com",
             "name": "API Support",
-            "url": "https://"
+            "url": "https://kevwe.com/message"
         },
         "description": "Yet Another Time Serie",
         "license": {
@@ -88,6 +134,17 @@     "paths": {
         "/event": {
             "post": {
                 "description": "store events",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
                 "requestBody": {
                     "content": {
                         "application/json": {
@@ -118,9 +175,20 @@                     "Events"
                 ]
             }
         },
-        "/event/get": {
+        "/event/search": {
             "post": {
                 "description": "retrieve events in the specified time window",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
                 "requestBody": {
                     "content": {
                         "application/json": {
@@ -151,11 +219,20 @@                     "Events"
                 ]
             }
         },
-        "/event/get/{from}": {
+        "/event/{from}": {
             "get": {
                 "description": "retrieve events  from timestamp {from}",
                 "parameters": [
                     {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    },
+                    {
                         "description": "Starting from timestamp :from",
                         "in": "path",
                         "name": "from",
@@ -198,6 +275,17 @@         },
         "/metric": {
             "post": {
                 "description": "store metric",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
                 "requestBody": {
                     "content": {
                         "application/json": {
@@ -228,9 +316,20 @@                     "Metrics"
                 ]
             }
         },
-        "/metric/get": {
+        "/metric/search": {
             "post": {
-                "description": "retrieve metric in the specified time window",
+                "description": "search metrics in the specified timeframe",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
                 "requestBody": {
                     "content": {
                         "application/json": {
@@ -261,11 +360,20 @@                     "Metrics"
                 ]
             }
         },
-        "/metric/get/{name}/{from}": {
+        "/metric/{name}/{from}": {
             "get": {
-                "description": "retrieve metric in the specified time window",
+                "description": "search metrics after the specified timestamp",
                 "parameters": [
                     {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    },
+                    {
                         "description": "Metric Name :name",
                         "in": "path",
                         "name": "name",
@@ -296,9 +404,150 @@                         },
                         "description": "OK"
                     }
                 },
-                "summary": "Get the spcific metric {name} starting from the epoch {from}",
+                "summary": "Get the specific metric {name} starting from the epoch {from}",
                 "tags": [
                     "Metrics"
+                ]
+            }
+        },
+        "/position": {
+            "post": {
+                "description": "store position",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "requestBody": {
+                    "content": {
+                        "application/json": {
+                            "schema": {
+                                "$ref": "#/components/schemas/model.PositionModel"
+                            }
+                        }
+                    },
+                    "description": "Position body data",
+                    "required": true,
+                    "x-originalParamName": "position"
+                },
+                "responses": {
+                    "202": {
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "type": "string"
+                                }
+                            }
+                        },
+                        "description": "Accepted"
+                    }
+                },
+                "summary": "write position to db",
+                "tags": [
+                    "Positions"
+                ]
+            }
+        },
+        "/position/search": {
+            "post": {
+                "description": "retrieve positions in the specified time window",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "requestBody": {
+                    "content": {
+                        "application/json": {
+                            "schema": {
+                                "$ref": "#/components/schemas/model.PositionSearchRequest"
+                            }
+                        }
+                    },
+                    "description": "Position query filters",
+                    "required": true,
+                    "x-originalParamName": "position"
+                },
+                "responses": {
+                    "200": {
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "type": "string"
+                                }
+                            }
+                        },
+                        "description": "OK"
+                    }
+                },
+                "summary": "Get the positions From ... and To when present",
+                "tags": [
+                    "Positions"
+                ]
+            }
+        },
+        "/position/{from}": {
+            "get": {
+                "description": "retrieve positions  from timestamp {from}",
+                "parameters": [
+                    {
+                        "description": "clientCN",
+                        "in": "header",
+                        "name": "X-SSL-Client-CN",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    },
+                    {
+                        "description": "Starting from timestamp :from",
+                        "in": "path",
+                        "name": "from",
+                        "required": true,
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                ],
+                "requestBody": {
+                    "content": {
+                        "application/json": {
+                            "schema": {
+                                "$ref": "#/components/schemas/model.PositionSearchRequest"
+                            }
+                        }
+                    },
+                    "description": "Event query filters",
+                    "required": true,
+                    "x-originalParamName": "position"
+                },
+                "responses": {
+                    "200": {
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "type": "string"
+                                }
+                            }
+                        },
+                        "description": "OK"
+                    }
+                },
+                "summary": "Get the positions from timestamp {from}",
+                "tags": [
+                    "Positions"
                 ]
             }
         }




diff --git a/openapi/swagger.yaml b/openapi/swagger.yaml
index ae38a8296bd5c32c3683e20529ee6e1ded515f32..235e60f577c88fa21ff5eaa5d20dd7fb3c35eadc 100755
--- a/openapi/swagger.yaml
+++ b/openapi/swagger.yaml
@@ -15,6 +15,8 @@                 from:
                     type: integer
                 id_client:
                     type: string
+                source:
+                    type: string
                 to:
                     type: integer
             type: object
@@ -37,6 +39,34 @@                 id_client:
                     type: string
                 name:
                     type: string
+                source:
+                    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
+        model.PositionSearchRequest:
+            properties:
+                from:
+                    type: integer
+                id_client:
+                    type: string
+                source:
+                    type: string
                 to:
                     type: integer
             type: object
@@ -45,8 +75,9 @@     description: OpenAPI
     url: https://swagger.io/resources/open-api/
 info:
     contact:
+        email: info@kevwe.com
         name: API Support
-        url: https://
+        url: https://kevwe.com/message
     description: Yet Another Time Serie
     license:
         name: Affero GPL
@@ -59,6 +90,13 @@ paths:
     /event:
         post:
             description: store events
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
             requestBody:
                 content:
                     application/json:
@@ -77,9 +115,22 @@                     description: Accepted
             summary: write event to db
             tags:
                 - Events
-    /event/get:
-        post:
-            description: retrieve events in the specified time window
+    /event/{from}:
+        get:
+            description: retrieve events  from timestamp {from}
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
+                - description: Starting from timestamp :from
+                  in: path
+                  name: from
+                  required: true
+                  schema:
+                    type: string
             requestBody:
                 content:
                     application/json:
@@ -95,16 +146,16 @@                         application/json:
                             schema:
                                 type: string
                     description: OK
-            summary: Get the events From ... and To when present
+            summary: Get the events from timestamp {from}
             tags:
                 - Events
-    /event/get/{from}:
-        get:
-            description: retrieve events  from timestamp {from}
+    /event/search:
+        post:
+            description: retrieve events in the specified time window
             parameters:
-                - description: Starting from timestamp :from
-                  in: path
-                  name: from
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
                   required: true
                   schema:
                     type: string
@@ -123,12 +174,19 @@                         application/json:
                             schema:
                                 type: string
                     description: OK
-            summary: Get the events from timestamp {from}
+            summary: Get the events From ... and To when present
             tags:
                 - Events
     /metric:
         post:
             description: store metric
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
             requestBody:
                 content:
                     application/json:
@@ -147,9 +205,48 @@                     description: Accepted
             summary: write metric to db
             tags:
                 - Metrics
-    /metric/get:
+    /metric/{name}/{from}:
+        get:
+            description: search metrics after the specified timestamp
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
+                - description: Metric Name :name
+                  in: path
+                  name: name
+                  required: true
+                  schema:
+                    type: string
+                - description: Starting from epoch :from
+                  in: path
+                  name: from
+                  required: true
+                  schema:
+                    type: string
+            responses:
+                "200":
+                    content:
+                        application/json:
+                            schema:
+                                type: string
+                    description: OK
+            summary: Get the specific metric {name} starting from the epoch {from}
+            tags:
+                - Metrics
+    /metric/search:
         post:
-            description: retrieve metric in the specified time window
+            description: search metrics in the specified timeframe
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
             requestBody:
                 content:
                     application/json:
@@ -168,22 +265,58 @@                     description: OK
             summary: Get the metrics From ... and To when present
             tags:
                 - Metrics
-    /metric/get/{name}/{from}:
+    /position:
+        post:
+            description: store position
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
+            requestBody:
+                content:
+                    application/json:
+                        schema:
+                            $ref: '#/components/schemas/model.PositionModel'
+                description: Position body data
+                required: true
+                x-originalParamName: position
+            responses:
+                "202":
+                    content:
+                        application/json:
+                            schema:
+                                type: string
+                    description: Accepted
+            summary: write position to db
+            tags:
+                - Positions
+    /position/{from}:
         get:
-            description: retrieve metric in the specified time window
+            description: retrieve positions  from timestamp {from}
             parameters:
-                - description: Metric Name :name
-                  in: path
-                  name: name
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
                   required: true
                   schema:
                     type: string
-                - description: Starting from epoch :from
+                - description: Starting from timestamp :from
                   in: path
                   name: from
                   required: true
                   schema:
                     type: string
+            requestBody:
+                content:
+                    application/json:
+                        schema:
+                            $ref: '#/components/schemas/model.PositionSearchRequest'
+                description: Event query filters
+                required: true
+                x-originalParamName: position
             responses:
                 "200":
                     content:
@@ -191,6 +324,34 @@                         application/json:
                             schema:
                                 type: string
                     description: OK
-            summary: Get the spcific metric {name} starting from the epoch {from}
+            summary: Get the positions from timestamp {from}
+            tags:
+                - Positions
+    /position/search:
+        post:
+            description: retrieve positions in the specified time window
+            parameters:
+                - description: clientCN
+                  in: header
+                  name: X-SSL-Client-CN
+                  required: true
+                  schema:
+                    type: string
+            requestBody:
+                content:
+                    application/json:
+                        schema:
+                            $ref: '#/components/schemas/model.PositionSearchRequest'
+                description: Position query filters
+                required: true
+                x-originalParamName: position
+            responses:
+                "200":
+                    content:
+                        application/json:
+                            schema:
+                                type: string
+                    description: OK
+            summary: Get the positions From ... and To when present
             tags:
-                - Metrics
+                - Positions




diff --git a/server/grpc/metric-grpc-server.go b/server/grpc/metric-grpc-server.go
deleted file mode 100644
index caa0b441bfe8806d52182ab6c07340881db4da3c..0000000000000000000000000000000000000000
--- a/server/grpc/metric-grpc-server.go
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * Yats - yats
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Paolo Lulli <kevwe.com>
- * @copyright Paolo Lulli 2024
- */
-
-package grpc
-
-import (
-	"context"
-	"fmt"
-	"google.golang.org/grpc"
-	"log"
-	"net"
-	"yats-server/db"
-	"yats-server/proto"
-)
-
-type server struct {
-	proto.UnimplementedYatsGrpcServiceServer
-}
-
-func (s *server) CreateMetric(ctx context.Context, req *proto.CreateMetricRequest) (*proto.CreateMetricResponse, error) {
-	metric := req.GetMetric()
-	clientCN := metric.IdClient
-	fmt.Printf("%s / %s / %s", clientCN, metric.Name, metric.Value)
-	db.SaveMetric(clientCN, metric.Name, metric.Value)
-
-	return &proto.CreateMetricResponse{Metric: metric}, nil
-}
-
-func (s *server) CreateEvent(ctx context.Context, req *proto.CreateEventRequest) (*proto.CreateEventResponse, error) {
-	event := req.GetEvent()
-	clientCN := event.IdClient
-	fmt.Printf("%s / %s ", clientCN, event.Name)
-	db.SaveEvent(clientCN, event.Name)
-	return &proto.CreateEventResponse{Event: event}, nil
-}
-
-func (s *server) Createposition(ctx context.Context, req *proto.CreatePositionRequest) (*proto.CreatePositionResponse, error) {
-	position := req.GetPosition()
-	clientCN := position.IdClient
-	fmt.Printf("%s / %s ", clientCN, position.Name)
-	db.SavePosition(clientCN, position.Lat, position.Lon, position.Name)
-	return &proto.CreatePositionResponse{Position: position}, nil
-}
-
-func RunYatsGrpcServer(address string) {
-	lis, err := net.Listen("tcp", address)
-	if err != nil {
-		log.Fatalf("failed to listen: %v", err)
-	}
-	s := grpc.NewServer()
-	proto.RegisterYatsGrpcServiceServer(s, &server{})
-	log.Printf("Server is running on port %s\n", address)
-	if err := s.Serve(lis); err != nil {
-		log.Fatalf("failed to serve: %v", err)
-	}
-}




diff --git a/server/grpc/yats-grpc-server.go b/server/grpc/yats-grpc-server.go
new file mode 100644
index 0000000000000000000000000000000000000000..50bdc61e78435a334439c921afea1a79459cac9b
--- /dev/null
+++ b/server/grpc/yats-grpc-server.go
@@ -0,0 +1,55 @@
+/**
+ * Yats - yats
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Paolo Lulli <kevwe.com>
+ * @copyright Paolo Lulli 2024
+ */
+
+package grpc
+
+import (
+	"context"
+	"fmt"
+	"google.golang.org/grpc"
+	"log"
+	"net"
+	"yats-server/db"
+	"yats-server/proto"
+)
+
+type server struct {
+	proto.UnimplementedYatsGrpcServiceServer
+}
+
+func (s *server) CreateMetric(ctx context.Context, req *proto.CreateMetricRequest) (*proto.CreateMetricResponse, error) {
+	metric := req.GetMetric()
+	clientCN := metric.IdClient
+	fmt.Printf("%s / %s / %s", clientCN, metric.Name, metric.Value)
+	db.SaveMetric(clientCN, metric.Name, metric.Value)
+
+	return &proto.CreateMetricResponse{Metric: metric}, nil
+}
+
+func (s *server) CreatePosition(ctx context.Context, req *proto.CreatePositionRequest) (*proto.CreatePositionResponse, error) {
+	position := req.GetPosition()
+	clientCN := position.IdClient
+	fmt.Printf("%s / %s ", clientCN, position.Name)
+	db.SavePosition(clientCN, position.Lat, position.Lon, position.Name)
+	return &proto.CreatePositionResponse{Position: position}, nil
+}
+
+func RunYatsGrpcServer(address string) {
+	lis, err := net.Listen("tcp", address)
+	if err != nil {
+		log.Fatalf("failed to listen: %v", err)
+	}
+	s := grpc.NewServer()
+	proto.RegisterYatsGrpcServiceServer(s, &server{})
+	log.Printf("Server is running on port %s\n", address)
+	if err := s.Serve(lis); err != nil {
+		log.Fatalf("failed to serve: %v", err)
+	}
+}




diff --git a/server/main.go b/server/main.go
index 096fa6223c929d6024bffe188e2ddf0c11ce08ee..7e6686ff6aa947018b88decc6e22ee66ee1f4b35 100644
--- a/server/main.go
+++ b/server/main.go
@@ -25,11 +25,11 @@
 // @title           Yats Server
 // @version         1.0
 // @description     Yet Another Time Serie
-// @termsOfService  https://kevwe.com/ TODO
+// @termsOfService  https://kevwe.com/
 
 // @contact.name   API Support
-// @contact.url    https:// TODO
-// @contact.email           TODO
+// @contact.url    https://kevwe.com/message
+// @contact.email  info@kevwe.com
 
 // @license.name  Affero GPL
 // @license.url   https://www.gnu.org/licenses/agpl-3.0.en.html#license-text