From 92c3bfa1d51391edaf39fde426be1b9976892e44 Mon Sep 17 00:00:00 2001 From: Ilia Bakhterev Date: Mon, 22 Jan 2024 15:28:44 +0100 Subject: [PATCH] api update (/incidents) --- app/api/routes.py | 15 +++++++++++++++ doc/source/api.rst | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/api/routes.py b/app/api/routes.py index ef12acc..880c348 100644 --- a/app/api/routes.py +++ b/app/api/routes.py @@ -332,3 +332,18 @@ def post(self, data): "not modifying or opening new incident" ) return incident + + +@bp.route("/v1/incidents", methods=["GET"]) +class ApiIncidents(MethodView): + @bp.response(200, IncidentSchema(many=True)) + def get(self): + """Get all incidents + Retrieve a list of all incidents. + Example: + .. code-block:: console + curl http://localhost:5000/api/v1/incidents -X GET \\ + -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...' + """ + incidents = db.session.scalars(db.select(Incident)).all() + return incidents diff --git a/doc/source/api.rst b/doc/source/api.rst index e39af98..61c71b3 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -27,8 +27,23 @@ You should encode the "SECRET_KEY" to get the token >>> payload = {"status_dashboard": "dummy"} >>> encoded = jwt.encode(payload, secret_key, algorithm="HS256") >>> print(encoded) - eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjoiU09NRV9QQVlMT0FEIn0.oLj3UE3cQaviTpjOn0J6v0KE_wvPowyk2MAyN_s00_8 + eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjoiU09NRV9Powyk2MN_s00_8 +API usage examples +================== + +.. code-block:: console + + $ curl http://localhost:5000/api/v1/component_status -X POST \ + -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6pX...' \ + -H 'content-type:application/json' \ + -d '{"impact": "minor", "name": "Component 1", \ + "attributes":[{"name":"region","value":"Reg1"}]}' + +.. code-block:: console + + $ curl http://localhost:5000/api/v1/incidents -X GET \ + -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ikp...' API v1 ======