def GetOrders():
    db = flights_db.sqlite_db()
    CustomerName = request.args.get('CustomerName')
    OrderNumber = request.args.get('OrderNumber')
    orders = db.get_orders(OrderNumber, CustomerName)
    json_string = json.dumps([ob.__dict__ for ob in orders])
    return json_string
Exemple #2
0
 def setUpClass(cls):
     cls.created_order = 0
     cls.cities = ('San Francisco', 'Seattle', 'Denver', 'Frankfurt',
                   'London', 'Los Angeles', 'Paris', 'Portland', 'Sydney',
                   'Zurich')
     cls.sl = flights_db.sqlite_db()
     logging.config.fileConfig('../logging.conf')
def DeleteOrder(OrderNumber):
    db = flights_db.sqlite_db()
    rows = db.delete_flight_order(OrderNumber)
    if (rows==1):
        json_string = jsonify({"true": "Oder deleted {0} ".format(OrderNumber)}), 200
    else:
        json_string = jsonify({"false": "Oder not found  {0} ".format(OrderNumber)}), 200
    return json_string
def GetFlightByNumber(flight_number):
    db = flights_db.sqlite_db()
    flight = db.get_flight(flight_number)
    if (flight == -1):
        json_string = jsonify({"error": "Unkown Flight  : {0} ".format(flight_number)}), 404
    else:
        json_string = json.dumps(flight[0].__dict__)
    return json_string
def GetFlights():
    db = flights_db.sqlite_db()
    DepartureCity = request.args.get('DepartureCity')
    ArrivalCity = request.args.get('ArrivalCity')
    FlightDate = request.args.get('Date')
    flights = db.get_flights(DepartureCity, ArrivalCity, FlightDate)
    if (flights == -1):
        json_string = jsonify({"error": "Invalid DepartureCity : {0} ".format(DepartureCity)}), 500
    else:
        json_string = json.dumps([ob.__dict__ for ob in flights])
    return json_string
def UpdateOrder(OrderNumber):
    db = flights_db.sqlite_db()
    if (request.is_json):
        data = request.get_json()
        DepartureDate = data['DepartureDate']
        if (not db.date_in_the_past(DepartureDate)):
            return (jsonify({"error": "Flight date cannot be in the past : {0} ".format(DepartureDate)}), 500)
        CustomerName = data['CustomerName']
        FlightNumber = data['FlightNumber']
        NumberOfTickets = data['NumberOfTickets']
        FlightClass = data['Class']
        upd_order = db.update_flight_order(OrderNumber, CustomerName, DepartureDate, FlightNumber, NumberOfTickets, FlightClass)
        if (upd_order==-1):
            return (jsonify({"error": "Ordered tickets too high : {0} ".format(FlightNumber)}), 500)
        elif (upd_order==-2):
            return (jsonify({"error": "Unkown Flight  : {0} ".format(FlightNumber)}), 500)
        elif (upd_order==-3):
            return (jsonify({"error": "No more seats available in flight  : {0} ".format(FlightNumber)}), 500)
        else:
            return Response(json.dumps(upd_order.__dict__), mimetype='application/json')
    else:
        return (jsonify({"error": "Invalid json format  "}), 500)
def DeleteAllOrders():
    db = flights_db.sqlite_db()
    db.delete_all_orders();
    return ('{"result":"ok"}')
def GetOrder(OrderNumber):
    db = flights_db.sqlite_db()
    orders = db.get_orders(OrderNumber, '')
    json_string = json.dumps([ob.__dict__ for ob in orders])
    return json_string