def insertSupplier(self, form): if form and len(form) == 8: sfirstname = form['first_name'] smiddleinitial = form['middle_initial'] slastname = form['last_name'] companyname = form['company_name'] warehouseaddress = form['warehouse_address'] slocation = form['supplier_location'] sphone = form['phone'] loginID = form['login_id'] if sfirstname and slastname and smiddleinitial and companyname and warehouseaddress and slocation and sphone and loginID: dao = SupplierDAO() sid = dao.insert(sfirstname, smiddleinitial, slastname, slocation, companyname, warehouseaddress, sphone, loginID) result = {} result['s_id'] = sid result['first_name'] = sfirstname result['middle_initial'] = smiddleinitial result['last_name'] = slastname result['company_name'] = companyname result['warehouse_address'] = warehouseaddress result['supplier_location'] = slocation result['phone'] = sphone result['login_id'] = loginID return jsonify(Supplier=result), 201 else: return jsonify(Error="Unexpected attributes in post request.") else: return jsonify(Error="Malformed post request."), 400
def putSupplierByID(self, form, s_id): if form and len(form) == 7: u_email = form['u_email'] u_password = form['u_password'] u_name = form['u_name'] u_last_name = form['u_last_name'] u_region = form['u_region'] u_age = form['u_age'] s_bank_account = form['s_bank_account'] if u_email and u_password and u_name and u_last_name and u_region and u_age and s_bank_account and s_id: dao = SupplierDAO() s_id = dao.put(u_email, u_password, u_name, u_last_name, u_region, u_age, s_bank_account, s_id) result = {} result["s_id"] = s_id result["u_email"] = u_email result["u_password"] = u_password result["u_name"] = u_name result["u_last_name"] = u_last_name result["u_region"] = u_region result["u_age"] = u_age result["s_bank_account"] = s_bank_account return jsonify(Supplier=result), 201 else: return jsonify(Error="Malformed post request") else: return jsonify(Error="Malformed post request")
def getAllOrders(self, sid): dao = SupplierDAO() supplier = dao.getSupplierByID(sid) if not supplier: return jsonify("Supplier Not Found"), 404 transactions = TransactionHandler().getTransactionsBySID(sid) return transactions
def deleteSupplierByID(self, s_id): dao = SupplierDAO() if not dao.getSupplierById(s_id): return jsonify(Error="Supplier not found."), 404 else: dao.delete(s_id) return jsonify(DeleteStatus="OK"), 200
def updateSupplier(self, sid, form): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier not found."), 404 else: if len(form) != 8: return jsonify(Error="Malformed update request"), 400 else: sfirstname = form['first_name'] smiddleinitial = form['middle_initial'] slastname = form['last_name'] companyname = form['company_name'] warehouseaddress = form['warehouse_address'] slocation = form['supplier_location'] sphone = form['phone'] loginID = form['login_id'] if sfirstname and smiddleinitial and slastname and slocation and companyname and warehouseaddress and sphone and loginID: dao.update(sid, sfirstname, smiddleinitial, slastname, slocation, companyname, warehouseaddress, sphone, loginID) result = {} result['s_id'] = sid result['first_name'] = sfirstname result['middle_initial'] = smiddleinitial result['last_name'] = slastname result['company_name'] = companyname result['warehouse_address'] = warehouseaddress result['supplier_location'] = slocation result['phone'] = sphone result['login_id'] = loginID return jsonify(Supplier=result), 200 else: return jsonify(Error="Unexpected attributes in update request"), 400
def getSupplierByID(self, sid): dao = SupplierDAO() row = dao.getSupplierByID(sid) if not row: return jsonify(Error="Supplier Not Found"), 404 else: supplier = self.build_supplier_dict(row) return jsonify(Supplier=supplier)
def deleteSupplier(self, sid): dao = SupplierDAO() result = dao.deleteSupplier(sid) if result: return jsonify(Supplier=result), 201 else: return jsonify(Error="Supplier not found"), 404
def getSupplierById(self, sid): dao = SupplierDAO() sup1 = dao.getSupplierById(sid) if not sup1: return jsonify(Error="Supplier Not Found"), 404 else: supplier = self.build_supplier_dict(sup1) return jsonify(Supplier = supplier)
def getSuppliersOfResourceId(self, resource_id): dao = SupplierDAO() supplier_list = dao.getSuppliersOfResourceId(resource_id) result_list = [] for row in supplier_list: result = self.build_supplier_by_product_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)
def getAllSupplier(self): dao = SupplierDAO() supplier_list = dao.getAllSupplier() result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def getAllSuppliers(self): dao = SupplierDAO() suppliers_list = dao.getAllSuppliers() result_list = [] for supplier in suppliers_list: result = self.build_supplier_dict(supplier) result_list.append(result) return jsonify(Suppliers=result_list)
def getAllSupplierResources(self, supplier_id): dao = SupplierDAO() result = dao.getAllSupplierResources(supplier_id) result_list = [] for row in result: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources = result_list)
def getResourceBySupplierId(self, rid): dao = SupplierDAO() supplier_list = dao.getResourceBySupplierId(rid) result_list = [] if not supplier_list: return jsonify(Error="Resource Not Found"), 404 for row in supplier_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resource=result_list)
def getReservationBySupplierId(self, sid): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 reservation_list = dao.getReservationBySupplierId(sid) result_list = [] for row in reservation_list: result = self.build_reservation_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def getPartsBySupplierId(self, sid): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 parts_list = dao.getPartsBySupplierId(sid) result_list = [] for row in parts_list: result = self.build_part_dict(row) result_list.append(result) return jsonify(PartsSupply=result_list)
def getAnnouncementsBySupplierID(self, s_id): dao = SupplierDAO() if not dao.getSupplierById(s_id): return jsonify(Error="Supplier Not Found"), 404 announcements_list = dao.getAnnouncementsBySupplierId(s_id) result_list = [] for row in announcements_list: result = self.build_announcement_dict(row) result_list.append(result) return jsonify(Announcements=result_list)
def getSupplierById(self, supplier_id): dao = SupplierDAO() row = dao.getSupplierById(supplier_id) if not row: return jsonify(Error="Supplier not Found"), 404 else: supplier = self.build_supplier_dict(row) return jsonify(Supplier=supplier) return self.getAllSuppliers()
def getCompanyBySupplierId(self, sid): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 company_list = dao.getCompanyBySupplierId(sid) result_list = [] for row in company_list: result = self.build_company_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def getOrdersBySupplierId(self, sid): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 orders_list = dao.getOrdersBySupplierId(sid) result_list = [] for row in orders_list: result = self.build_order_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def getTransactionsBySupplierID(self, s_id): dao = SupplierDAO() if not dao.getSupplierById(s_id): return jsonify(Error="Supplier Not Found"), 404 transactions_list = dao.getTransactionsBySupplierId(s_id) result_list = [] for row in transactions_list: result = self.build_transaction_dict(row) result_list.append(result) return jsonify(Transactions=result_list)
def getResourcesBySupplierID(self, s_id): dao = SupplierDAO() if not dao.getSupplierById(s_id): return jsonify(Error="Supplier Not Found"), 404 resources_list = dao.getResourcesBySupplierId(s_id) result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def searchSuppliers(self, args): region = args.get('region') name = args.get('name') lastname = args.get('lastname') dao = SupplierDAO() if (len(args) == 3) and region and name and lastname: supplier_list = dao.getSuppliersByRegionAndNameAndLastname( region, name, lastname) elif (len(args) == 2) and region and name: supplier_list = dao.getSuppliersByRegionAndName(region, name) elif (len(args) == 2) and region and lastname: supplier_list = dao.getSuppliersByRegionAndLastname( region, lastname) elif (len(args) == 2) and name and lastname: supplier_list = dao.getSuppliersByNameAndLastname(name, lastname) elif (len(args) == 1) and region: supplier_list = dao.getSuppliersByRegion(region) elif (len(args) == 1) and name: supplier_list = dao.getSuppliersByName(name) elif (len(args) == 1) and lastname: supplier_list = dao.getSuppliersByLastname(lastname) else: return jsonify(Error="Malformed query string"), 400 if not supplier_list: return jsonify(Error="Supplier Not Found"), 404 else: result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def searchSupplier(self, args): dao = SupplierDAO() city = args.get('SCity') company = args.get('SCompany') name = args.get('SName') if (len(args) == 1) and city: supplier_list = dao.getSupplierByCity(city) elif (len(args) == 1) and company: supplier_list = dao.getSupplierByCompany(company) elif (len(args) == 1) and name: supplier_list = dao.getSupplierByName(name) elif (len(args) == 2) and city and company: supplier_list = dao.getSupplierByCityAndCompany(city, company) elif (len(args) == 2) and city and name: supplier_list = dao.getSupplierByCityAndName(city, name) elif (len(args) == 2) and name and company: supplier_list = dao.getSupplierByCompanyAndName(company, name) elif (len(args) == 3) and city and company and name: supplier_list = dao.getSupplierByCityAndCompanyAndName( city, company, name) else: return jsonify(Error="Malformed query string"), 400 if not supplier_list: return jsonify(Error="Supplier Not Found"), 404 result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier=result_list)
def getRequestCompleteBySupplierId(self, supplier_id): dao = SupplierDAO() if not dao.getSupplierById(supplier_id): return jsonify(Error="Supplier Not Found"), 404 request_completed_list = dao.getRequestedCompletedBySupplierId( supplier_id) result_list = [] for row in request_completed_list: result = self.build_request_complete_dict(row) result_list.append(result) return jsonify(Request_Completed=result_list)
def getAllSuppliers(self): dao = SupplierDAO() supplier_list = dao.getAllSuppliers() if not supplier_list: return jsonify(Error="Supplier Not Found"), 404 else: result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)
def getResourcesByRegion(self, region): dao = SupplierDAO() if not dao.getResourcesByRegion(region): return jsonify(Error='Resource Not Found.'), 404 else: resource_list = dao.getResourcesByRegion(region) result_list = [] for row in resource_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def getSupplierByLocation(self, location): dao = SupplierDAO() supplier_list = dao.getSupplierByLocation(location) if not supplier_list: return jsonify(Error="Supplier Not Found"), 404 else: result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(SupplierList=result_list)
def getIceBySupplierId(self, supplier_id): supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error = "Supplier Not Found"), 404 else: ice_dao = IceDAO() result_list = [] ice_list = ice_dao.getIceBySupplierId(supplier_id) for row in ice_list: result = self.build_ice_dict(row) result_list.append(result) return jsonify(Ice = result_list)
def getBatteriesBySupplierId(self, supplier_id): supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error = "Supplier Not Found"), 404 else: battery_dao = BatteryDAO() result_list = [] battery_list = battery_dao.getBatteriesBySupplierId(supplier_id) for row in battery_list: result = self.build_battery_dict(row) result_list.append(result) return jsonify(Batteries = result_list)
def getCompanyBySupplierId(self, supplier_id): supplier_dao = SupplierDAO() if not supplier_dao.getSupplierById(supplier_id): return jsonify(Error="Supplier Not Found"), 404 else: company_dao = CompanyDAO() result_list = [] company_list = company_dao.getCompanyBySupplierId(supplier_id) for row in company_list: result = self.build_company_dict(row) result_list.append(result) return jsonify(Company=result_list)