#!/usr/bin/env python3
# -*- encoding: UTF-8 -*-

from flask import jsonify, request

def add_route(app):
    ''' Add routes to a flask app Class. See API swagger doc'''
    @app.route('/users/<id>', methods=['GET'])
    def get_user(id):
        try:
            id = int(id)
        except ValueError:
            return "Invalid id", 400
        print(id)
        # TO BE IMPLEMENTED
        # ASK RECOGNITION SERVICE FOR USER(id)
        raise NotImplementedError()
        if result:
            return jsonify(dict(result.items()))
        else:
            return "User not found", 404

    @app.route('/users', methods=["POST"])
    def new_user():
        body = request.get_json()
        try:
            username, intensity, volume = [body[k] for k in ("username", "intensity", "volume")]
        except KeyError:
            return "Incorrect body", 400
        # TO BE IMPLEMENTED
        # ASK RECOGNITION SERVICE TO CREATE USER
        raise NotImplementedError()

    @app.route('/users/<id>', methods=["PUT"])
    def modify_user(id):
        try:
            id = int(id)
        except ValueError:
            return "Invalid id", 400
        # TO BE IMPLEMENTED
        # ASK RECOGNITION SERVICE TO MODIY USER

        raise NotImplementedError()

    @app.route('/users/<id>', methods=["DELETE"])
    def delete_user(id):
        try:
            id = int(id)
        except ValueError:
            return "Invalid id", 400

        # TO BE IMPLEMENTED
        # ASK RECOGNITION SERVICE TO DELETE USER
        raise NotImplementedError()

    @app.route('/coffee', methods=["GET"])
    def make_coffee():
        print(request.values)
        # TO BE IMPLEMENTED
        # ASK COFFE MACHINE TO MAKE COFFE
        raise NotImplementedError()

@@ -77,16 +77,32 @@
  request
+%0Aimport requests
 %0A%0Adef ad
@@ -368,24 +368,25 @@
 int(id)%0A
+%0A
         
 # TO BE 
@@ -381,41 +381,41 @@
     
-# TO BE IMPLEMENTED%0A        # ASK
+try:%0A            # Do request on 
  REC
@@ -435,12 +435,8 @@
 ICE 
-FOR 
 USER
@@ -452,122 +452,161 @@
     
-raise NotImplementedError()%0A        if result:%0A            return jsonify(dict(result.items()))%0A        else:%0A    
+    user = requests.get('http://example.com').content%0A        except ConnectionError:%0A            return %22Could not connect to Recognition Service%22, 421%0A
     
@@ -620,29 +620,17 @@
 urn 
-%22User not found%22, 404
+user, 200
 %0A%0A  
@@ -896,24 +896,25 @@
  body%22, 400%0A
+%0A
         # TO
@@ -970,32 +970,32 @@
  TO CREATE USER%0A
-
         raise No
@@ -1007,32 +1007,370 @@
 ementedError()%0A%0A
+        try:%0A        # TO BE IMPLEMENTED%0A        # ASK RECOGNITION SERVICE TO CREATE USER%0A        # Do post on  RECOGNITION SERVICE USER(id)%0A            r= requests.post('http://example.com', data = body%7D).content%0A        except ConnectionError:%0A            return %22Could not connect to Recognition Service%22, 421%0A        return r, 200%0A%0A%0A%0A
     @app.route('

enhance gateway api