diff --git a/server/webserver.py b/server/webserver.py index ef91567..bd4d9d7 100644 --- a/server/webserver.py +++ b/server/webserver.py @@ -30,6 +30,7 @@ class WebServer: bottle.get("/api/spots")(lambda: self.serve_api(self.get_spot_list_with_filters())) bottle.get("/api/options")(lambda: self.serve_api(self.get_options())) bottle.get("/api/status")(lambda: self.serve_api(self.status_data)) + bottle.post("/api/spot")(lambda: self.accept_spot()) # Routes for templated pages bottle.get("/")(lambda: self.serve_template('webpage_home')) bottle.get("/about")(lambda: self.serve_template('webpage_about')) @@ -55,6 +56,17 @@ class WebServer: response.set_header('Cache-Control', 'no-store') return json.dumps(data, default=serialize_everything) + # Accept a spot + def accept_spot(self): + self.last_api_access_time = datetime.now(pytz.UTC) + self.status = "OK" + + print(bottle.request.forms.spot) + + response.content_type = 'application/json' + response.set_header('Cache-Control', 'no-store') + return json.dumps("OK", default=serialize_everything) + # Serve a templated page def serve_template(self, template_name): self.last_page_access_time = datetime.now(pytz.UTC) diff --git a/webassets/apidocs/openapi.yml b/webassets/apidocs/openapi.yml index 5cee53b..c5f96fb 100644 --- a/webassets/apidocs/openapi.yml +++ b/webassets/apidocs/openapi.yml @@ -18,7 +18,7 @@ paths: get: tags: - spots - summary: Retrieve a set of spots. + summary: Get spots description: The main API call that retrieves spots from the system. Supply this with no query parameters to retrieve all spots known to the system. Supply query parameters to filter what is retrieved. operationId: spots parameters: @@ -170,7 +170,7 @@ paths: - AN responses: '200': - description: Successfully retrieved spots. + description: Success content: application/json: schema: @@ -183,12 +183,12 @@ paths: get: tags: - status - summary: Retrieve the server status. - description: Query information about the server for use in a diagnostics display + summary: Get server status + description: Query information about the server for use in a diagnostics display. operationId: status responses: '200': - description: Successfully retrieved status. + description: Success content: application/json: schema: @@ -251,12 +251,12 @@ paths: get: tags: - spots - summary: Retieve a list of options for various enumerations. + summary: Get enumeration options description: Retrieves the list of options for various enumerated types, which can be found in the spots and also provided back to the API as query parameters. While these enumerated options are defined in this spec anyway, providing them in an API call allows us to define extra parameters, like the colours associated with bands, and also allows clients to set up their filters and features without having to have internal knowledge about, for example, what bands the server knows about. operationId: options responses: '200': - description: Successfully retrieved options. + description: Success content: application/json: schema: @@ -302,6 +302,38 @@ paths: description: The maximum age, in seconds, of any spot before it will be deleted by the system. When querying the /api/spots endpoint and providing a "max_age" or "since" parameter, there is no point providing a number larger than this, because the system drops all spots older than this. example: 3600 + + /spot: + post: + tags: + - spots + summary: Add a spot + description: Supply a new spot object, which will be added to the system. Currently, this will not be reported up the chain to a cluster, POTA, SOTA etc. This will be introduced in a future version. + operationId: spot + parameters: + - name: spot + description: The spot data to post + required: true + schema: + type: + $ref: '#/components/schemas/Spot' + responses: + '200': + description: Success + content: + application/json: + schema: + type: string + example: "OK" + '422': + description: Validation error + content: + application/json: + schema: + type: string + example: "Failed" + + components: schemas: Spot: