def updateCustomer(self, customer_id, json): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: customer_firstname = json["customer_firstname"] customer_lastname = json["customer_lastname"] customer_date_birth = json["customer_date_birth"] customer_email = json["customer_email"] customer_phone = json["customer_phone"] customer_phone_id = json["customer_phone_id"] if customer_firstname and customer_lastname and customer_date_birth and customer_email and customer_phone_id and customer_phone: user_id = customer_dao.update(customer_id) user_dao = UserDAO() user_dao.update(user_id, customer_firstname, customer_lastname, customer_date_birth, customer_email) dao_phone = UserPhoneDAO() dao_phone.update(user_id, customer_phone) result = self.build_customer_attributes( customer_id, user_id, customer_firstname, customer_lastname, customer_date_birth, customer_email, customer_phone_id, customer_phone) return jsonify(Customer=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def getCustomerById(self, customer_id): dao = CustomerDAO() row = dao.getCustomerById(customer_id) if not row: return jsonify(Error="Customer Not Found"), 404 else: customer = self.build_customer_dict(row) return jsonify(Customer=customer)
def getAllCustomers(self): dao = CustomerDAO() customers_list = dao.getAllCustomers() result_list = [] for row in customers_list: result = self.build_customer_dict(row) result_list.append(result) return jsonify(Customers=result_list)
def getReservationsByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: reservation_list = [] dao = ReservationDAO() reservation_list = dao.getReservationsByCustomerId(customer_id) result_list = self.fixDict(reservation_list) return jsonify(Reservations=result_list)
def getOrderByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer Not Found"), 404 else: orders_list = [] dao = OrderDAO() orders_list = dao.getOrderByCustomerId(customer_id) result_list = self.fixDict(orders_list) return jsonify(Orders=result_list)
def getRequestsByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: request_list = [] request_dao = RequestDAO() request_list = request_dao.getRequestsByCustomerId(customer_id) result_list = self.fixDict(request_list) return jsonify(Requests=result_list)
def deleteCustomer(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: user_id = customer_dao.delete(customer_id) dao_phone = UserPhoneDAO() dao_phone.delete(user_id) user_dao = UserDAO() user_dao.delete(user_id) return jsonify(DeleteStatus="OK"), 200
def getAthMovilByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error = "Customer not found."), 404 else: dao = AthMovilDAO() row = dao.getAthMovilByCustomerId(customer_id) if not row: return jsonify(Error = "Ath Movil Not Found"), 404 else: ath_movil = self.build_athMovil_dict(row) return jsonify(AthMovil = ath_movil)
def getCreditCardByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: dao = CreditCardDAO() row = dao.getCreditCardByCustomerId(customer_id) if not row: return jsonify(Error="Credit Card Not Found"), 404 else: creditcard = self.build_creditcard_dict(row) return jsonify(CreditCard=creditcard)
def getPaypalByCustomerId(self, customer_id): customer_dao = CustomerDAO() if not customer_dao.getCustomerById(customer_id): return jsonify(Error="Customer not found."), 404 else: dao = PaypalDAO() row = dao.getPaypalByCustomerId(customer_id) if not row: return jsonify(Error="Paypal Not Found"), 404 else: paypal = self.build_paypal_dict(row) return jsonify(AthMovil=paypal)
def searchCustomers(self, args): customer_firstname = args.get("customer_firstname") customer_lastname = args.get("customer_lastname") customer_email = args.get("customer_email") customer_phone = args.get("customer_phone") customer_date_birth = args.get("customer_date_birth") dao = CustomerDAO() customers_list = [] if (len(args) == 2) and customer_firstname and customer_lastname: customers_list = dao.getCustomersByFirstnameAndLastname( customer_firstname, customer_lastname) elif (len(args) == 1) and customer_firstname: customers_list = dao.getCustomersByFirstname(customer_firstname) elif (len(args) == 1) and customer_lastname: customers_list = dao.getCustomersByLastname(customer_lastname) elif (len(args) == 1) and customer_email: customers_list = dao.getCustomersByEmail(customer_email) elif (len(args) == 1) and customer_phone: customers_list = dao.getCustomersByPhone(customer_phone) elif (len(args) == 1) and customer_date_birth: customers_list = dao.getCustomersByDateOfBirth(customer_date_birth) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in customers_list: result = self.build_customer_dict(row) result_list.append(result) return jsonify(Customers=result_list)
def insertCustomer(self, json): customer_firstname = json['customer_firstname'] customer_lastname = json['customer_lastname'] customer_date_birth = json['customer_date_birth'] customer_email = json['customer_email'] customer_phone = json['customer_phone'] if customer_firstname and customer_lastname and customer_date_birth and customer_email and customer_phone: user_dao = UserDAO() user_id = user_dao.insert(customer_firstname, customer_lastname, customer_date_birth, customer_email) dao_phone = UserPhoneDAO() customer_phone_id = dao_phone.insert(user_id, customer_phone) customer_dao = CustomerDAO() customer_id = customer_dao.insert(user_id) result = self.build_customer_attributes( customer_id, user_id, customer_firstname, customer_lastname, customer_date_birth, customer_email, customer_phone_id, customer_phone) return jsonify(Customer=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400