Example #1
0
    def getReports(self, params=None):
        reports = []

        if not params:
            reportTuples = db.getAllObjects('reports')
        else:
            for param in params:
                if param not in Report.attributesAsList():
                    return jsonify({'reports': []})
            reportTuples = db.getObjectsByFilter('reports', list(params.keys()), list(params.values()))

        # contsruct the fetched reports as objects
        for i in range(len(reportTuples)):
            reports.append(Report(reportTuples[i][0], self.__getCar(reportTuples[i][1]), reportTuples[i][2], reportTuples[i][3]))

        # jsonify each report object's dict
        return jsonify(reports=[report.asDict() for report in reports])
Example #2
0
 def createReport(self, params):
     # construct a report object from the gathered data
     report = Report(params[0], self.__getCar(params[1]), params[2], params[3])
     # update the database with the new report and respond with a confirmation of insertion
     db.insertObject('reports', Report.attributesAsList(), report.asTuple())
     return jsonify({'report': report.asDict()}), 201
Example #3
0
        abort(400)
    return bookingsController.createBooking(params)


@app.route(generateURI('bookings', True), methods=['PUT'])
def updateBooking(id):
    fieldsToUpdate, params = parseOptionalParams(bookingParams[1:])
    return bookingsController.updateBooking(id, fieldsToUpdate, params)


@app.route(generateURI('bookings', True), methods=['DELETE'])
def deleteBooking(id):
    return bookingsController.deleteBooking(id)


reportParams = Report.attributesAsList()


@app.route(generateURI('reports', True), methods=['GET'])
def getReport(id):
    return reportsController.getReport(id)


@app.route(generateURI('reports'), methods=['GET'])
def getReports():
    if request.args:
        return reportsController.getReports(request.args)
    return reportsController.getReports()


@app.route(generateURI('reports'), methods=['POST'])