def deleteCompany(self, compid): dao = CompanyDAO() if not dao.getCompanyById(compid): return jsonify(Error="Company not found."), 404 else: dao.delete(compid) return jsonify(DeleteStatus="OK"), 200
def getAllCompany(self): dao = CompanyDAO() company_list = dao.getAllCompany() result_list = [] for row in company_list: result = self.build_company_dict(row) result_list.append(result) return jsonify(Company=result_list)
def getCompanyById(self, company_id): dao = CompanyDAO() row = dao.getCompanyById(company_id) if not row: return jsonify(Error="Company Not Found"), 404 else: order = self.build_company_dict(row) return jsonify(Company=order)
def getCompanyByCompname(self, compname): dao = CompanyDAO() row = dao.getCompanyByCompname(compname) if not row: return jsonify(Error="Company Not Found"), 404 else: company = self.build_company_dict(row) return jsonify(Company=company)
def insertCompanyJson(self, json): compname = json['compname'] if compname: dao = CompanyDAO() compid = dao.insert(compname) result = self.build_company_attributes(compid, compname) return jsonify(Company=result), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
def getAllComapnies(self): dao = CompanyDAO() cms = [] items = dao.getAllCompanies() for i in items: result = self.build_company_dict(i) cms.append(result) return jsonify(Companies=cms)
def getCompanyByDes(self, name): dao = CompanyDAO() cms = [] items = dao.getCompanyByDes(name) for i in items: result = self.build_company_dict(i) cms.append(result) return jsonify(Companies=cms)
def getResourcesByCompanyId(self, compid): dao = CompanyDAO() if not dao.getCompanyById(compid): return jsonify(Error="Company Not Found"), 404 resources_list = dao.getResourcesByCompanyId(compid) result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Company=result_list)
def getConsumerByCompanyId(self, compid): dao = CompanyDAO() if not dao.getCompanyById(compid): return jsonify(Error="Company Not Found"), 404 consumers_list = dao.getConsumerByCompanyId(compid) result_list = [] for row in consumers_list: result = self.build_consumer_dict(row) result_list.append(result) return jsonify(Company=result_list)
def getSuppliersByCompanyId(self, company_id): company_dao = CompanyDAO() if not company_dao.getCompanyById(company_id): return jsonify(Error = "Company Not Found"), 404 else: supplier_dao = SupplierDAO() result_list = [] supplier_list = supplier_dao.getSuppliersByCompanyId(company_id) for row in supplier_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = 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)
def searchCompany(self, args): compname = args.get('compname') dao = CompanyDAO() company_list = [] if (len(args) == 1) and compname: company_list = dao.getCompanyByCompname(compname) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in company_list: result = self.build_company_dict(row) result_list.append(result) return jsonify(Company=result_list)
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 insertCompany(self, json): company_name = json['company_name'] company_address = json['company_address'] company_phone = json['company_phone'] if company_name and company_address and company_phone: dao = CompanyDAO() company_id = dao.insert(company_name, company_address, company_phone) json = self.build_company_attributes(company_id, company_name, company_address, company_phone) return jsonify(Company=json), 201 else: return jsonify(Error="Unexpected attributes in post request"), 400
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 updateCompany(self, compid, form): dao = CompanyDAO() if not dao.getCompanyById(compid): return jsonify(Error="Company not found."), 404 else: if len(form) != 1: return jsonify(Error="Malformed update request"), 400 else: compname = form['compname'] if compname: dao.update(compid, compname) result = self.build_company_attributes(compid, compname) return jsonify(Company=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def updateCompany(self, company_id, json): dao = CompanyDAO() if not dao.getCompanyById(company_id): return jsonify(Error="Company not found."), 404 else: company_id = json['company_id'] company_name = json['company_name'] company_address = json['company_address'] company_phone = json['company_phone'] if company_id and company_name and company_address and company_phone: dao.update(company_id, company_name, company_address, company_phone) result = self.build_company_attributes(company_id, company_name, company_address, company_phone) return jsonify(Company=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400