def insertSupplierJson(self, json): ufirstname = None ulastname = None compid = None susername = json['susername'] scompany = json['scompany'] if len(json) == 3: compid = json['compid'] elif len(json) == 4: ufirstname = json['ufirstname'] ulastname = json['ulastname'] elif len(json) == 5: ufirstname = json['ufirstname'] ulastname = json['ulastname'] compid = json['compid'] if susername and scompany and ufirstname and ulastname and compid: if not CompanyDAO().getCompanyById(compid): return jsonify(Error="Company Not Found"), 404 uid = UsersDAO().insert(ufirstname, ulastname) sid = SupplierDAO().insertSupplierAsNewUsers( uid, susername, scompany) CompanyDAO().supplierWorksForCompany(compid, sid) self.build_user_attributes(uid, ufirstname, ulastname) result = self.build_supplier_attributes(sid, uid, susername, scompany) return jsonify(Supplier=result), 201 elif susername and scompany and ufirstname and ulastname: uid = UsersDAO().insert(ufirstname, ulastname) sid = SupplierDAO().insertSupplierAsNewUsers( uid, susername, scompany) self.build_user_attributes(uid, ufirstname, ulastname) result = self.build_supplier_attributes(sid, uid, susername, scompany) return jsonify(Supplier=result), 201 elif susername and scompany and compid: if not CompanyDAO().getCompanyById(compid): return jsonify(Error="Company Not Found"), 404 uid = "" sid = SupplierDAO().insert(susername, scompany) CompanyDAO().supplierWorksForCompany(compid, sid) result = self.build_supplier_attributes(sid, uid, susername, scompany) return jsonify(Supplier=result), 201 elif susername and scompany: uid = "" sid = SupplierDAO().insert(susername, scompany) result = self.build_supplier_attributes(sid, uid, susername, scompany) return jsonify(Supplier=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
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 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 insertResourcesJson(self, json): rname = json['rname'] rtype = json['rtype'] rprice = json['rprice'] rlocation = json['rlocation'] rstock = json['rstock'] sid = json['sid'] if not SupplierDAO().getSupplierById(sid): return jsonify(Error="Supplier Not Found"), 404 if rlocation == 'Ponce': rlocation = '18.0107279,-66.6141375' elif rlocation == 'Mayaguez': rlocation = '18.201108,-67.1401665' elif rlocation == 'San Juan': rlocation = '18.46542,-66.1172515' if ',' in rlocation and len(rlocation) != 1: rlocation = "https://maps.google.com/?q=" + rlocation if rname and rtype and rprice and rlocation and rstock and sid: dao = ResourcesDAO() rid = dao.insert(rname, rtype, rprice, rlocation, rstock) dao.insertSupplierOfResource(sid, rid) result = self.build_resource_attributes(rid, rname, rtype, rprice, rlocation, rstock) return jsonify(Resoure=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def searchSuppliers(self, args): first_name = args.get("first_name") last_name = args.get("last_name") email = args.get("email") phone = args.get("phone") company_name = args.get("company_name") dao = SupplierDAO() supplier_list = [] if (len(args) == 1) and first_name: supplier_list = dao.getSupplierByFirstName(first_name) elif (len(args) == 1) and last_name: supplier_list = dao.getSupplierByLastName(last_name) elif (len(args) == 1) and email: supplier_list = dao.getSupplierByEmail(email) elif (len(args) == 1) and last_name: supplier_list = dao.getSupplierByPhone(phone) elif (len(args) == 1) and company_name: supplier_list = dao.getSupplierByLastName(company_name) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers=result_list)
def searchSuppliers(self, args): supplier_firstname = args.get('supplier_firstname') supplier_lastname = args.get("supplier_lastname") supplier_email = args.get('supplier_email') supplier_phone = args.get('supplier_phone') suppplier_date_birth = args.get('supplier_date_birth') dao = SupplierDAO() supplier_list = [] if (len(args) == 2) and supplier_firstname and supplier_lastname: supplier_list = dao.getSuppliersByFirstnameAndLastname(supplier_firstname , supplier_lastname) elif (len(args) == 1) and supplier_firstname: supplier_list = dao.getSuppliersByFirstname(supplier_firstname) elif (len(args) == 1) and supplier_lastname: supplier_list = dao.getSuppliersByLastname(supplier_lastname) elif(len(args) == 1) and supplier_email: supplier_list = dao.getSupplierByEmail(supplier_email) elif(len(args) == 1) and supplier_phone: supplier_list = dao.getSupplierByPhone(supplier_phone) elif(len(args) == 1) and suppplier_date_birth: supplier_list = dao.getSuppliersByDateOfBirth(suppplier_date_birth) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = result_list)
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 updateSupplier(self, sid, form): dao = SupplierDAO() if not dao.getSupplierById(sid): return jsonify(Error="Supplier not found."), 404 else: if len(form) == 3: uid = form['uid'] susername = form['susername'] scompany = form['scompany'] if susername and scompany and uid: dao.update(sid, uid, susername, scompany) result = self.build_supplier_attributes( sid, uid, susername, scompany) return jsonify(Supplier=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400 elif len(form) == 4: uid = form['uid'] susername = form['susername'] scompany = form['scompany'] compid = form['compid'] if susername and scompany and uid and compid: if not CompanyDAO().getCompanyById(compid): return jsonify(Error="Company Not Found"), 404 dao.updateSupplierWithCompany(sid, uid, susername, scompany, compid) result = self.build_supplier_attributes( sid, uid, susername, scompany) return jsonify(Supplier=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400 else: return jsonify(Error="Malformed update request"), 400
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 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 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 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 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 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 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 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 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 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 searchSupplierOfThisResourceOnThisRegion(self,rname, rsid, args): daoRes = ResourceDAO() daoRegion = RegionDAO() dao = SupplierDAO() if not daoRegion.getRegionByName(rname): return jsonify(Error = 'Region Not Found'), 404 if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') suppliers_list = [] if(len(args) == 4) and afirst and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmailPhone(rname, rsid, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmail(rname, rsid, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastPhone(rname, rsid, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhoneEmail(rname, rsid, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmailPhone(rname, rsid, alast, email, phone) elif(len(args) == 2) and afirst and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlast(rname, rsid, afirst, alast) elif(len(args) == 2) and afirst and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstEmail(rname, rsid, afirst, email) elif(len(args) == 2) and afirst and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhone(rname, rsid, afirst, phone) elif(len(args) == 2) and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmail(rname, rsid, alast, email) elif(len(args) == 2) and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastPhone(rname, rsid, alast, phone) elif(len(args) == 2) and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmailPhone(rname, rsid, email, phone) elif(len(args) == 1) and afirst: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirst(rname, rsid, afirst) elif(len(args) == 1) and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlast(rname, rsid, alast) elif(len(args) == 1) and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmail(rname, rsid, email) elif(len(args) == 1) and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByPhone(rname, rsid, phone) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = result_list)
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 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 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 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 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 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 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 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)