Пример #1
0
 def insertSuppliers(self, form):
     if len(form) != 9:
         return jsonify(Error="Malform post request"), 400
     else:
         first_name = form['first_name']
         last_name = form['last_name']
         street = form['street']
         urb_conde = form['urb_conde']
         num = form['num']
         city = form['city']
         state = form['state']
         zip = form['zip']
         gps_local = form['gps_local']
         if first_name and last_name and street and urb_conde and num and city and state and zip and gps_local:
             dao = suppliersDAO()
             supp_ID = dao.insert(first_name, last_name)
             dao.insertAddress(supp_ID, street, urb_conde, num, city, state,
                               zip, gps_local)
             result = self.build_suppliers_attributes(
                 supp_ID, first_name, last_name, street, urb_conde, num,
                 city, state, zip, gps_local)
             return jsonify(Supplier=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Пример #2
0
 def getSuppliersById(self, supp_ID):
     dao = suppliersDAO()
     row = dao.getSuppliersById(supp_ID)
     if not row:
         return jsonify(Error="Part Not Found"), 404
     else:
         supplier = self.build_suppliers_dict(row)
         return jsonify(Supplier=supplier)
Пример #3
0
 def getAllSuppliersInfo(self):
     dao = suppliersDAO()
     suppliers = dao.getAllSuppliersInfo()
     result_list = []
     for row in suppliers:
         result = self.build_info_dict(row)
         result_list.append(result)
     return jsonify(Suppliers=result_list)
Пример #4
0
 def getSuppliersByResourceCategory(self, category):
     dao = suppliersDAO()
     suppliers = dao.getSuppliersByResourceCategory(category)
     if not suppliers:
         return jsonify(Error="Suppliers Not Found"), 404
     suppliers_list = suppliers
     result_list = []
     for row in suppliers_list:
         result = self.build_suppliers_dict(row)
         result_list.append(result)
     return jsonify(Suppliers=result_list)
Пример #5
0
 def getAccountsBySupp_ID(self, supp_ID):
     dao = suppliersDAO()
     accounts = dao.getAccountsBySuppliersID(supp_ID)
     if not accounts:
         return jsonify(Error="Accounts Not Found"), 404
     accounts_list = accounts
     result_list = []
     for row in accounts_list:
         result = self.build_accounts_dict(row)
         result_list.append(result)
     return jsonify(Accounts=result_list)
Пример #6
0
 def getResourcesBySupplierId(self, supp_ID):
     dao = suppliersDAO()
     resources = dao.getResourcesBySuppliersID(supp_ID)
     if not resources:
         return jsonify(Error="Part Not Found"), 404
     resources_list = resources
     result_list = []
     for row in resources_list:
         result = self.build_resources_dict(row)
         result_list.append(result)
     return jsonify(Resources=result_list)
Пример #7
0
 def insertAccount(self, supp_ID, form):
     if len(form) != 2:
         return jsonify(Error="Malform post request"), 400
     else:
         acct_num = form['acct_num']
         balance = form['balance']
         if acct_num and balance:
             dao = suppliersDAO()
             dao.insertAccount(acct_num, supp_ID, balance)
             result = self.build_accounts_attributes(
                 acct_num, supp_ID, balance)
             return jsonify(Account=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
Пример #8
0
 def updateAccount(self, acct_num, form):
     dao = suppliersDAO()
     if not dao.getAccountByAcctNum(acct_num):
         return jsonify(Error="Account not found"), 404
     else:
         if len(form) != 2:
             return jsonify(Error="Malform update request"), 400
         else:
             balance = form['balance']
             supp_ID = form['supp_ID']
             if balance and supp_ID:
                 dao.updateAccount(acct_num, balance)
                 result = self.build_accounts_attributes(
                     acct_num, supp_ID, balance)
                 return jsonify(Accounts=result), 200
             else:
                 return jsonify(
                     Error="Unexpected attributes in updates request"), 400
Пример #9
0
 def searchSuppliers(self, args):
     name = args.get("first_name")
     lastname = args.get("last_name")
     location = args.get("location")
     region = args.get("address")
     dao = suppliersDAO()
     suppliers_list = []
     if (len(args) == 2) and name and location:
         suppliers_list = dao.getSuppliersByNameAndLocation(name, location)
     elif (len(args) == 2) and name and region:
         suppliers_list = dao.getSuppliersByNameAndRegion(name, region)
     elif (len(args) == 1) and location:
         suppliers_list = dao.getSuppliersByLocation(location)
     elif (len(args) == 1) and region:
         suppliers_list = dao.getSuppliersByRegion(region)
     elif (len(args) == 2) and name and lastname:
         suppliers_list = dao.getSuppliersByNameAndLastname(name, lastname)
     else:
         return jsonify(Error="Malformed query string"), 400
     result_list = []
     for row in suppliers_list:
         result = self.build_suppliers_dict(row)
         result_list.append(result)
     return jsonify(Suppliers=result_list)