diff --git a/components/control_center/src/app/services/rest.service.ts b/components/control_center/src/app/services/rest.service.ts index 54033d2..af42907 100644 --- a/components/control_center/src/app/services/rest.service.ts +++ b/components/control_center/src/app/services/rest.service.ts @@ -18,7 +18,7 @@ export class RestService { } getCarEvents(vin) { - return this.http.get(this.currentLocation + 'car_events?vin=' + vin, {observe: 'response'}); + return this.http.get(this.currentLocation + 'car_events/?vin=' + vin, {observe: 'response'}); } getTrafficLights() { diff --git a/components/x_way/requirements.txt b/components/x_way/requirements.txt index 7df827e..ec961a5 100644 --- a/components/x_way/requirements.txt +++ b/components/x_way/requirements.txt @@ -2,4 +2,5 @@ flask Flask-Cors requests Flask-PyMongo -jsonify \ No newline at end of file +jsonify +flask_restx \ No newline at end of file diff --git a/components/x_way/x_way_server.py b/components/x_way/x_way_server.py index 8a9bee1..794754f 100644 --- a/components/x_way/x_way_server.py +++ b/components/x_way/x_way_server.py @@ -1,30 +1,43 @@ +import flask +import flask_restx import requests from bson import json_util -from flask import Flask +from flask import Flask, jsonify from flask_cors import CORS from flask import request import json; app = Flask(__name__) CORS(app) +api_bp = flask.Blueprint("api", __name__, url_prefix="/api/v1/resources") + +API = flask_restx.Api(api_bp) +app.register_blueprint(api_bp) + + +NAMESPACE = API.namespace("car_events") + ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' EVENT_STORE_URL = 'http://eventstore:5001/api/keys/' -@app.route('/api/v1/resources/car_events', methods=['GET']) -def get_cars_events(): - vin = request.args.get('vin') +@NAMESPACE.route('/') +class CarsEvents(flask_restx.Resource): + @NAMESPACE.doc(params={'vin': {'description': 'Vehicle Identifier Number of car', + 'type': 'String', 'default': '5GZCZ43D13S812715'}}) + def get(self): + vin = request.args.get('vin') - try: - response = requests.get(EVENT_STORE_URL + 'DAF:' + vin + '/0/') - cars = json.loads(response.text) + try: + response = requests.get(EVENT_STORE_URL + 'DAF:' + vin + '/0/') + cars = json.loads(response.text) - except requests.exceptions.ConnectionError as e: - print("Is the EVENT_STORE_URL running and reachable?") - raise e + except requests.exceptions.ConnectionError as e: + print("Is the EVENT_STORE_URL running and reachable?") + raise e - return json_util.dumps(cars) + return jsonify(cars) @app.route('/api/v1/resources/traffic_light_events', methods=['GET'])