def __getCar(self, id): carTuple = db.getObjectById('cars', id)[0] if not carTuple: return None return Car(carTuple[0], carTuple[1], carTuple[2], carTuple[3], carTuple[4], carTuple[5], carTuple[6], carTuple[7], carTuple[8])
def getCar(self, id): # locate a car in the database carTuple = db.getObjectById('cars', id)[0] # use data to create a car object then jsonify it's dict return jsonify( Car(carTuple[0], carTuple[1], carTuple[2], carTuple[3], carTuple[4], carTuple[5], carTuple[6], carTuple[7], carTuple[8]).asDict())
def updateReport(self, id, fieldsToUpdate, params): # update the report with the specified id, indicating which fields to update and what to update them to db.updateObject('reports', id, fieldsToUpdate, params) # retrieve the newly updated report and create an object from it's data reportTuple = db.getObjectById('reports', id)[0] report = Report(reportTuple[0], self.__getCar(reportTuple[1]), reportTuple[2], reportTuple[3]) # jsonify the report to confirm the update return jsonify({'report': report.asDict()})
def getBooking(self, id): # locate a booking in the database bookingTuple = db.getObjectById('bookings', id)[0] # use data to create a booking object then jsonify it's dict return jsonify( Booking(bookingTuple[0], bookingTuple[1], bookingTuple[2], self.__getUser(bookingTuple[3]), self.__getCar(bookingTuple[4]), bookingTuple[5]).asDict())
def updateCar(self, id, fieldsToUpdate, params): # update the car with the specified id, indicating which fields to update and what to update them to db.updateObject('cars', id, fieldsToUpdate, params) # retrieve the newly updated car and create an object from it's data carTuple = db.getObjectById('cars', id)[0] car = Car(carTuple[0], carTuple[1], carTuple[2], carTuple[3], carTuple[4], carTuple[5], carTuple[6], carTuple[7], carTuple[8]) # jsonify the car to confirm the update return jsonify({'car': car.asDict()})
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 getUser(self, id): userTuple = db.getObjectById('users', id)[0] userType = userTuple[7] classType = self.__userTypes[userType] if userType not in self.__userTypes: return jsonify({'Error': 'Not found'}), 404 user = self.__createUserFromType(userTuple, userType) return jsonify(user.asDict())
def updateUser(self, id, fieldsToUpdate, params): # when updating there can be between 0 and 8 params if params and (len(params) > 8 or len(params) < 0): return jsonify({'Error': 'Bad Request'}), 400 # update the user with the specified id, indicating which fields to update and what to update them to db.updateObject('users', id, fieldsToUpdate, params) # retrieve the newly updated user and create an object from it's data userTuple = db.getObjectById('users', id)[0] userType = userTuple[7] classType = self.__userTypes[userType] user = classType(userTuple[0], userTuple[1], userTuple[2], userTuple[3], userTuple[4], userTuple[5], userTuple[6]) # jsonify the user to confirm the update return jsonify({'user': user.asDict()}), 201
def getReport(self, id): # locate a report in the database reportTuple = db.getObjectById('reports', id)[0] # use data to create a report object then jsonify it's dict return jsonify(Report(reportTuple[0], self.__getCar(reportTuple[1]), reportTuple[2], reportTuple[3]).asDict())
def __getUser(self, id): userTuple = db.getObjectById('users', id)[0] if not userTuple: return None return User(userTuple[0], userTuple[1], userTuple[2], userTuple[3], userTuple[4], userTuple[5], userTuple[6])