Пример #1
0
 def insertSeller(self, form):
     if len(form) != 9:
         return jsonify(Error="Malformed post Seller"), 400
     else:
         u_name = form['u_name']
         u_lastname = form['u_lastname']
         u_email = form['u_email']
         u_password = form['u_password']
         u_address = form['u_address']
         u_city = form['u_city']
         u_region = form['u_region']
         u_phone = form['u_phone']
         u_age = form['u_age']
         if u_name and u_lastname and u_email and u_password and u_address and u_city and u_region and u_phone and u_age:
             dao = SellerDAO()
             s_id = dao.insert(u_name, u_lastname, u_email, u_password,
                               u_address, u_city, u_region, u_phone, u_age)
             result = self.build_seller_attributes(s_id, u_name, u_lastname,
                                                   u_email, u_password,
                                                   u_address, u_city,
                                                   u_region, u_phone, u_age)
             return jsonify(Seller=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post Seller"), 400
Пример #2
0
 def deleteSeller(self, s_id):
     dao = SellerDAO()
     if not dao.getSellerById(s_id):
         return jsonify(Error="Seller not found."), 404
     else:
         dao.delete(s_id)
         return jsonify(DeleteStatus="OK"), 200
Пример #3
0
 def getSellerById(self, s_id):
     dao = SellerDAO()
     seller_list = dao.getSellerById(s_id)
     if not seller_list:
         return jsonify(Error="Seller Not Found"), 404
     else:
         result = self.build_seller_dict(seller_list)
     return jsonify(Seller=result)
Пример #4
0
 def searchSeller(self, args):
     name = args.get("name")
     lastname = args.get("lastname")
     region = args.get("region")
     dao = SellerDAO()
     seller_list = []
     if (len(args) == 3) and name and lastname and region:
         seller_list = dao.getSellerByRegionNameAndLastName(
             region, name, lastname)
     elif (len(args) == 2) and name and lastname:
         seller_list = dao.getSellerByNameandLastName(name, lastname)
     elif (len(args) == 2) and name and region:
         seller_list = dao.getSellerByNameandRegion(name, region)
     elif (len(args) == 2) and lastname and region:
         seller_list = dao.getSellerByLastNameandRegion(lastname, region)
     elif (len(args) == 1) and name:
         seller_list = dao.getSellerByName(name)
     elif (len(args) == 1) and lastname:
         seller_list = dao.getSellerByLastName(lastname)
     elif (len(args) == 1) and region:
         seller_list = dao.getSellerByRegion(region)
     else:
         return jsonify(Error="Malformed query string"), 400
     if not seller_list:
         return jsonify(Error="Seller Not Found"), 404
     else:
         result_list = []
         for row in seller_list:
             result = self.build_seller_dict(row)
             result_list.append(result)
         return jsonify(Sellers=result_list)
Пример #5
0
 def getTransactionsBySellerId(self, s_id):
     dao = SellerDAO()
     transaction_list = dao.getTransactionsBySellerId(s_id)
     if not transaction_list:
         return jsonify(Error="Transaction Not Found"), 404
     else:
         result_list = []
         for row in transaction_list:
             result = self.build_transaction_dict(row)
             result_list.append(result)
         return jsonify(Transactions=result_list)
Пример #6
0
 def getResourcesBySellerId(self, s_id):
     dao = SellerDAO()
     seller_list = dao.getResourcesBySellerId(s_id)
     if not seller_list:
         return jsonify(Error="Seller Not Found"), 404
     else:
         result_list = []
         for row in seller_list:
             result = self.build_resource_dict(row)
             result_list.append(result)
         return jsonify(Resources=result_list)
Пример #7
0
 def getAllSellers(self):
     dao = SellerDAO()
     seller_list = dao.getAllSellers()
     if not seller_list:
         return jsonify(Error="Seller Not Found"), 404
     else:
         result_list = []
         for row in seller_list:
             result = self.build_seller_dict(row)
             result_list.append(result)
         return jsonify(Sellers=result_list)
Пример #8
0
 def updateSeller(self, s_id, form):
     dao = SellerDAO()
     if not dao.getSellerById(s_id):
         return jsonify(Error="Seller not found."), 404
     else:
         if len(form) != 9:
             return jsonify(Error="Malformed update Seller"), 400
         else:
             u_name = form['u_name']
             u_lastname = form['u_lastname']
             u_email = form['u_email']
             u_password = form['u_password']
             u_address = form['u_address']
             u_city = form['u_city']
             u_region = form['u_region']
             u_phone = form['u_phone']
             u_age = form['u_age']
             if u_name and u_lastname and u_email and u_password and u_address and u_city and u_region and u_phone and u_age:
                 dao = SellerDAO()
                 dao.update(s_id, u_name, u_lastname, u_email, u_password,
                            u_address, u_city, u_region, u_phone, u_age)
                 result = self.build_seller_attributes(
                     s_id, u_name, u_lastname, u_email, u_password,
                     u_address, u_city, u_region, u_phone, u_age)
                 return jsonify(Seller=result), 201
             else:
                 return jsonify(
                     Error="Unexpected attributes in update Seller"), 400