コード例 #1
0
ファイル: bookings.py プロジェクト: Complexia/CarShare
    def getBookings(self, params=None):
        bookings = []
        # with no optional params all bookings can be fetched
        if not params:
            bookingTuples = db.getAllObjects('bookings')
        # otherwise only bookings matching the params may be fetched
        else:
            for param in params:
                if param not in Booking.attributesAsList():
                    return jsonify({'bookings': []})
            # obtain booking history for user_id param
                bookingTuples = db.getObjectsByFilter('bookings',
                                                      list(params.keys()),
                                                      list(params.values()))

        # construct the fetched bookings as objects
        for i in range(len(bookingTuples)):
            bookings.append(
                Booking(bookingTuples[i][0],
                        bookingTuples[i][1], bookingTuples[i][2],
                        self.__getUser(bookingTuples[i][3]),
                        self.__getCar(bookingTuples[i][4]),
                        bookingTuples[i][5]))

        # jsonify each booking object's dict
        return jsonify(bookings=[booking.asDict() for booking in bookings])
コード例 #2
0
ファイル: bookings.py プロジェクト: Complexia/CarShare
 def createBooking(self, params):
     # fetch the user and car corresponding to the user_id and car_id in the request body
     user = self.__getUser(params[3])
     car = self.__getCar(params[4])
     # construct a booking object from the gathered data
     booking = Booking(params[0], params[1], params[2], user, car,
                       params[5])
     # update the database with the new booking and respond with a confirmation of insertion
     db.insertObject('bookings', Booking.attributesAsList(),
                     booking.asTuple())
     return jsonify({'booking': booking.asDict()}), 201
コード例 #3
0
ファイル: routes.py プロジェクト: Complexia/CarShare
    return usersController.createUser(params)


@app.route(generateURI('users', True), methods=['PUT'])
def updateUser(id):
    fieldsToUpdate, params = parseOptionalParams(userParams[1:])
    return usersController.updateUser(id, fieldsToUpdate, params)


@app.route(generateURI('users', True), methods=['DELETE'])
def deleteUser(id):
    return usersController.deleteUser(id)


# api calls regarding the booking object
bookingParams = Booking.attributesAsList()


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


@app.route(generateURI('bookings'), methods=['GET'])
def getBookings():
    # if the request is filtering by user_id call a modified version of the get all function
    if request.args:
        return bookingsController.getBookings(request.args)
    return bookingsController.getBookings()