def updateBooking(self, id, fieldsToUpdate, params): # update the booking with the specified id, indicating which fields to update and what to update them to db.updateObject('bookings', id, fieldsToUpdate, params) # retrieve the newly updated booking and create an object from it's data bookingTuple = db.getObjectById('bookings', id)[0] booking = Booking(bookingTuple[0], bookingTuple[1], bookingTuple[2], self.__getUser(bookingTuple[3]), self.__getCar(bookingTuple[4]), bookingTuple[5]) # jsonify the booking to confirm the update return jsonify({'booking': booking.asDict()})
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