def getAllSuppliers(self):

        dao = SupplierDAO()
        suppliers_list = dao.getAllSuppliers()
        result_list = []
        for row in suppliers_list:
            result = self.build_supplier_dict(row)
            result_list.append(result)
        return jsonify(Suppliers=result_list)
 def getResourcesBySupplierId(self, sid):
     dao = SupplierDAO()
     if not dao.getSupplierById(sid):
         return jsonify(Error="Supplier Not Found"), 404
     parts_list = dao.getResourcesBySupplierId(sid)
     result_list = []
     for row in parts_list:
         result = self.build_resource_dict(row)
         result_list.append(result)
     return jsonify(PartsSupply=result_list)
    def getSupplierById(self, uid):

        dao = SupplierDAO()

        row = dao.getSupplierById(uid)
        if not row:
            return jsonify(Error="Supplier Not Found"), 404
        else:
            part = self.build_supplier_dict(row)
        return jsonify(Supplier=part)
Example #4
0
    def searchAllSuppliersByParameter(self, args):
        dao = SupplierDAO()
        city = args.get('city')
        region = args.get('region')
        resource_name = args.get('resource_name')
        type_name = args.get('type_name')
        name = args.get('name')
        keyword = args.get('keyword')
        if len(args) == 1 and city:
            res = dao.searchSuppliersByCity(city)
        elif len(args) == 1 and region:
            res = dao.searchSuppliersByRegion(region)
        elif len(args) == 1 and resource_name:
            res = dao.searchSuppliersSupplyingResource(resource_name)
        elif len(args) == 1 and type_name:
            res = dao.searchSuppliersSupplyingResourceByCategory(type_name)
        elif len(args) == 1 and name:
            res = dao.searchSuppliersByName(name)
        elif len(args) == 1 and keyword:
            res = dao.searchSuppliersByResourceKeyword(keyword)
        elif len(args) == 2 and resource_name and city:
            res = dao.searchSuppliersSupplyingResourceInCity(resource_name, city)
        else:
            return jsonify(Error = "Malformed query string"), 400

        if len(res) == 0:
            return jsonify(Error = "No Suppliers found"), 404
        else:
            result_list = []
            for row in res:
                result = self.build_supplier(row)
                result_list.append(result)            
            return jsonify(Suppliers = result_list)
Example #5
0
 def getSupplierByID(self,id):
     dao = SupplierDAO()
     res = dao.searchSuppliersByID(id)
     if not res:
         return jsonify(Error = "Supplier Not Found"), 404
     else:
         result_list = []
         for row in res:
             result = self.build_supplier(row)
             result_list.append(result)          
     return jsonify(Supplier = result_list)
Example #6
0
 def getAllSuppliers(self):
     dao = SupplierDAO()
     res = dao.getAllSuppliers()
     result_list = []
     
     if len(res) == 0:
         return jsonify(Error = "No Suppliers found"), 404
     else:
         for row in res:
             result = self.build_supplier(row)
             result_list.append(result)            
         return jsonify(Suppliers = result_list)
 def searchAdmins(self, args):
     if len(args) > 1:
         return jsonify(Error="Malformed search string."), 400
     else:
         username = args.get("name")
         if username:
             dao = SupplierDAO()
             supplier_list = dao.getSupplierByUsername(username)
             result_list = []
             for row in supplier_list:
                 result = self.build_supplier_dict(row)
                 result_list.append(row)
             return jsonify(Admins=result_list)
         else:
             return jsonify(Error="Malformed search string."), 400
 def insertSupplier(self, form):
     if form and len(form) == 3:
         name = form['name']
         email = form['email']
         username = form['username']
         if name and email and username:
             dao = SupplierDAO()
             uid = dao.insert(name, email, username)
             result = {}
             result["uid"] = uid
             result["name"] = name
             result["email"] = email
             result["username"] = username
             return jsonify(Supplier=result), 201
         else:
             return jsonify(Error="Malformed post request")
     else:
         return jsonify(Error="Malformed post request")
Example #9
0
    def insertSupplier(self, form, parsed_json):
        first_name = form.get('first_name')  
        last_name = form.get('last_name')
        email = form.get('email')
        phone = form.get('phone')
        address = form.get('address')
        city_id = form.get('city_id')
        latitude = form.get('latitude')
        longitud = form.get('longitud')   
        password = form.get('password')
        dt = datetime.now()  
        photo_url = 'https://robohash.org/quiautdolores.png?size=50x50&set=set1'

        if len(form)==0:
            # parsed_json = json.loads(test)
            first_name = parsed_json['first_name']  
            last_name = parsed_json['last_name']
            email = parsed_json['email']
            phone = parsed_json['phone']
            address = parsed_json['address']
            city_id = parsed_json['city_id']
            latitude = parsed_json['latitude']
            longitud = parsed_json['longitud']   
            password = parsed_json['password']
            #Hash password
            password = self.hash_password(password)
            dao = SupplierDAO()
            id = dao.addSupplier(first_name , last_name , email , phone , address , city_id , latitude , longitud , photo_url , 'Supplier' , password,dt)
            result = self.getSupplierByID(id)
            return (result), 201     
                
        if first_name and last_name and email and phone and address and city_id and latitude and longitud and password :
            dao = SupplierDAO()
            password = self.hash_password(password)
            id = dao.addSupplier(first_name , last_name , email , phone , address , city_id , latitude , longitud , 'https://robohash.org/quiautdolores.png?size=50x50&set=set1' , 'Supplier' , password,dt)
            result = self.getSupplierByID(id)
            return (result), 201
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400
Example #10
0
    def PutSupplier(self, form, parsed_json):
        first_name = form.get('first_name')  
        last_name = form.get('last_name')
        email = form.get('email')
        phone = form.get('phone')
        address = form.get('address')
        city_id = form.get('city_id')
        latitude = form.get('latitude')
        longitud = form.get('longitud')   
        photo = 'https://robohash.org/quiautdolores.png?size=50x50&set=set1'    
        id = form.get('id')

        if len(form)==0:
            id = parsed_json['id']
            first_name = parsed_json['first_name']  
            last_name = parsed_json['last_name']
            email = parsed_json['email']
            phone = parsed_json['phone']
            address = parsed_json['address']
            city_id = parsed_json['city_id']
            latitude = parsed_json['latitude']
            longitud = parsed_json['longitud']
            id = dao.UpdateSupplier(id,first_name , last_name , email , phone , address , city_id , latitude , longitud , photo)
            result = self.getSupplierByID(id)
            return (result), 201   
        
        elif first_name and last_name and email and phone and address and city_id and latitude and longitud and photo and id:
            dao = SupplierDAO()
            id = dao.UpdateSupplier(id,first_name , last_name , email , phone , address , city_id , latitude , longitud , photo)
            result = self.getSupplierByID(id)
            return (result), 201
        
        elif email and id and (len(form)==2):
            dao = SupplierDAO()
            tid = dao.updateSupplierEmail(id,email)
            result = self.getSupplierByID(id)
            return (result), 201

        elif phone and id and (len(form)==2):
            dao = SupplierDAO()
            tid = dao.updateSupplierPhone(id,phone)
            result = self.getSupplierByID(id)
            return (result), 201

        elif first_name and id and (len(form)==2):
            dao = SupplierDAO()
            tid = dao.updateSupplierFirst_name(id,first_name)
            result = self.getSupplierByID(id)
            return (result), 201

        elif last_name and id and (len(form)==2):
            dao = SupplierDAO()
            tid = dao.updateSupplierLast_name(id,last_name)
            result = self.getSupplierByID(id)
            return (result), 201    
        
        else:
            return jsonify(Error="Unexpected attributes in post request"), 400