예제 #1
0
 def insert_sup(self, form):
     dao = peopledao()
     if len(form) != 10:
         return jsonify(Error="Malformed post request"), 400
     else:
         s_fname = form['s_fname']
         s_lname = form['s_lname']
         a_username = form['a_username']
         a_password = form['a_password']
         s_phone = form['s_phone']
         addressline1 = form['addressline1']
         city = form['city']
         zipcode = form['zipcode']
         country = form['country']
         district = form['district']
         if s_fname and s_lname and s_phone and addressline1 and city and zipcode and country \
                 and district and a_username and a_password:
             saddress_id = dao.insert_new_address(addressline1, city,
                                                  zipcode, country,
                                                  district)
             sa_id = dao.insert_new_user(a_username, a_password)
             s_id = dao.insert_new_sup(s_fname, s_lname, sa_id, saddress_id,
                                       s_phone)
             result = self.build_supplierINS_dict(s_id, s_fname, s_lname,
                                                  sa_id, saddress_id,
                                                  s_phone, addressline1,
                                                  city, zipcode, country,
                                                  district)
             return jsonify(NewSupplier=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
예제 #2
0
 def getProductsBySupplier(self, args):
     s_id = args.get("s_id")
     s_fname = args.get("s_fname")
     s_lname = args.get("s_lname")
     p_name = args.get("p_name")
     ct_type = args.get("ct_type")
     dao = peopledao()
     product_list = []
     if (len(args) == 2) and s_fname and s_lname:
         product_list = dao.getProductsBySupplierFullName(s_fname, s_lname)
     elif (len(args) == 1) and s_fname:
         product_list = dao.getProductsBySupplierName(s_fname)
     elif (len(args) == 1) and s_id:
         product_list = dao.getProductsBySupplierId(s_id)
     elif (len(args) == 1) and p_name:
         product_list = dao.getSupplierByProductName(p_name)
     elif (len(args) == 1) and ct_type:
         product_list = dao.getSupplierByProductCategory(ct_type)
     else:
         return jsonify(error="malformed query string"), 400
     result_list = []
     for row in product_list:
         result = self.build_new_product(row)
         result_list.append(result)
     return jsonify(ProductsBySupplier=result_list)
예제 #3
0
 def insert_pin(self, form):
     dao = peopledao()
     if len(form) != 10:
         return jsonify(Error="Malformed post request"), 400
     else:
         pin_fname = form['pin_fname']
         pin_lname = form['pin_lname']
         a_username = form['a_username']
         a_password = form['a_password']
         pin_phone = form['pin_phone']
         addressline1 = form['addressline1']
         city = form['city']
         zipcode = form['zipcode']
         country = form['country']
         district = form['district']
         if pin_fname and pin_lname and pin_phone and addressline1 and city and zipcode and country \
                 and district and a_username and a_password:
             pinaddress_id = dao.insert_new_address(addressline1, city,
                                                    zipcode, country,
                                                    district)
             pina_id = dao.insert_new_user(a_username, a_password)
             pin_id = dao.insert_new_pin(pin_fname, pin_lname, pina_id,
                                         pinaddress_id, pin_phone)
             result = self.build_adminINS_dict(pin_id, pin_fname, pin_lname,
                                               pina_id, pinaddress_id,
                                               pin_phone, addressline1,
                                               city, zipcode, country,
                                               district)
             return jsonify(NewPersonInNeed=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
예제 #4
0
    def searchSUPByRequests(self, args):
        s_id = args.get("s_id")
        s_fname = args.get("s_fname")
        s_lname = args.get("s_lname")
        s_phone = args.get("s_phone")
        city = args.get("city")
        country = args.get("country")
        district = args.get("district")
        dao = peopledao()
        request_list = []

        if (len(args) == 1) and s_id:
            request_list = dao.GetSUPByID(s_id)
        elif (len(args) == 1) and s_fname:
            request_list = dao.GetSUPByFNAME(s_fname)
        elif (len(args) == 1) and s_phone:
            request_list = dao.GetSUPByPHONE(s_phone)
        elif (len(args) == 1) and city:
            request_list = dao.GetSUPByCITY(city)
        elif (len(args) == 1) and country:
            request_list = dao.GetSUPByCOUNTRY(country)
        elif (len(args) == 1) and district:
            request_list = dao.GetSUPByDISTRICT(district)
        elif (len(args) == 2) and s_fname and s_lname:
            request_list = dao.GetSUPByFULLNAME(s_fname, s_lname)
        else:
            return jsonify(error="malformed query string"), 400
        result_list = []
        for row in request_list:
            result = self.build_supplier_dict(row)
            result_list.append(result)
            print(row)

        return jsonify(Request=result_list)
예제 #5
0
 def get_all_products_by_supplier(self):
     dao = peopledao()
     product_list = dao.get_all_products_by_supplier()
     result_list = []
     for row in product_list:
         result = self.build_new_product(row)
         result_list.append(result)
     return jsonify(Product=result_list)
예제 #6
0
 def set_user(self, us):
     dao = peopledao()
     userlist = dao.getUserKeys(us)
     if userlist:
         self.__set_user(userlist)
         return True
     else:
         return False
예제 #7
0
 def get_user(self, us):  #using pId
     dao = peopledao()
     userlist = dao.getUserKeys(us)
     if userlist:
         usr = User()
         usr.__set_user(userlist)
         return usr
     return None
예제 #8
0
 def search_account_by_a_id(self, a_id):
     dao = peopledao()
     row = dao.search_account_by_a_id(a_id)
     if not row:
         return jsonify(Error="Account Not Found"), 404
     else:
         result = self.build_account_dict(row)
         return jsonify(Account_By_a_id=result)
예제 #9
0
 def get_all_bank_info(self):
     dao = peopledao()
     ba_list = dao.get_all_bank_info()
     result_list = []
     for row in ba_list:
         result = self.build_bankinfo_dict(row)
         result_list.append(result)
     return jsonify(Accounts=result_list)
예제 #10
0
 def getAllpin(self):
     dao = peopledao()
     pin_list = dao.getAllpin()
     result_list = []
     for row in pin_list:
         result = self.build_pin_dict(row)
         result_list.append(result)
     return jsonify(PIN=result_list)
예제 #11
0
 def getAllsup(self):
     dao = peopledao()
     sup_list = dao.getAllSUP()
     result_list = []
     for row in sup_list:
         result = self.build_supplier_dict(row)
         result_list.append(result)
     return jsonify(PIN=result_list)
예제 #12
0
 def get_all_accounts(self):
     dao = peopledao()
     accounts_list = dao.get_all_accounts()
     result_list = []
     for row in accounts_list:
         result = self.build_user_dict(row)
         result_list.append(result)
     return jsonify(Accounts=result_list)
예제 #13
0
 def getAllUsers(self):
     dao = peopledao()
     user_list = dao.getAllUsers()
     result_list = []
     for row in user_list:
         result = self.build_user_dict(row)
         result_list.append(result)
     return jsonify(Users=result_list)
예제 #14
0
 def get_bankinfo_by_SID(self, s_id):
     dao = peopledao()
     ba_list = dao.get_bankaccount_by_s_id(s_id)
     result_list = []
     for row in ba_list:
         result = self.build_bankinfo_dict(row)
         result_list.append(result)
     return jsonify(BANKINFO=result_list)
예제 #15
0
 def getAllAdmin(self):
     dao = peopledao()
     admin_list = dao.getAllAdmin()
     result_list = []
     for row in admin_list:
         result = self.build_admin_dict(row)
         result_list.append(result)
     return jsonify(Admins=result_list)
예제 #16
0
 def getAddressByID(self, address_id):
     dao = peopledao()
     address_list = dao.getAddressByID(address_id)
     result_list = []
     for row in address_list:
         result = self.build_address_dict(row)
         result_list.append(result)
     return jsonify(AdressByID=address_list)
예제 #17
0
 def get_all_orders(self):
     dao = peopledao()
     orders_list = dao.getAllOrders()
     result_list = []
     for row in orders_list:
         result = self.build_order_dict(row)
         result_list.append(result)
     return jsonify(Orders=result_list)
예제 #18
0
 def view_creditcard_by_PIN(self, pin_id):
     dao = peopledao()
     row = dao.view_creditcard_by_PIN(pin_id)
     if not row:
         return jsonify(Error="Credit Card Not Found"), 404
     else:
         result = self.build_creditcard_dict(row)
         return jsonify(Bank_info_by_SID=result)
예제 #19
0
 def get_all_products_by_district(self, args):
     dao = peopledao()
     district = args.get('district')
     if not district:
         product_list = dao.get_all_products_by_district()
     else:
         product_list = dao.get_all_products_by_district_declared(district)
     result_list = []
     for row in product_list:
         result = self.build_new_product_declared(row, 'district')
         result_list.append(result)
     return jsonify(ProductByDistrict=result_list)
예제 #20
0
 def get_all_products_by_country(self, args):
     dao = peopledao()
     country = args.get('country')
     if not country:
         product_list = dao.get_all_products_by_country()
     else:
         product_list = dao.get_all_products_by_country_declared(country)
     result_list = []
     for row in product_list:
         result = self.build_new_product_declared(row, 'country')
         result_list.append(result)
     return jsonify(ProductByCountry=result_list)
예제 #21
0
 def get_all_products_by_zipcode(self, args):
     dao = peopledao()
     zipcode = args.get('zipcode')
     if not zipcode:
         product_list = dao.get_all_products_by_zipcode()
     else:
         product_list = dao.get_all_products_by_zipcode_declared(zipcode)
     result_list = []
     for row in product_list:
         result = self.build_new_product_declared(row, 'zipcode')
         result_list.append(result)
     return jsonify(ProductByZipcode=result_list)
예제 #22
0
 def getSupplierByProduct(self, args):
     p_id = args
     dao = peopledao()
     product_list = []
     if p_id:
         product_list = dao.getSupplierByProductId(args)
     else:
         return jsonify(error="malformed query string"), 400
     result_list = []
     for row in product_list:
         result = self.build_supplier_dict(row)
         result_list.append(result)
     return jsonify(SupplierByProduct=result_list)
예제 #23
0
 def buy_product(self, form):
     if len(form) != 5:
         return jsonify(Error="Malformed post request"), 400
     else:
         o_id = int(form['o_id'])
         pin_id = int(form['pin_id'])
         qty = int(form['od_qty'])
         p_id = int(form['p_id'])
         s_id = int(form['s_id'])
         if o_id and pin_id and qty and p_id and s_id:
             if qty <= 0 or o_id <= 0 or pin_id <= 0 or p_id <= 0 or s_id <= 0:
                 return jsonify(Error="Invalid inputs o_id and/or pin_id and/or s_id and/or p_id and/or od_qty")
             else:
                 dao = ProductDAO()
                 pdao = peopledao()
                 date = time.strftime("%d%m%Y")
                 verify_o_id = pdao.check_o_id(o_id)  # returns true if o_id is less or equal max o_id, else false
                 verify_pin_id = pdao.check_pin(pin_id)  # return c_id if pin_id is valid, false otherwise
                 verify_sup = pdao.check_sup(s_id)  # returns ba_id if valid s_id, false otherwise
                 verify_product = dao.check_product(p_id, qty)  # return true if valid p_id & qty is less than db qty
                 if not (verify_o_id and verify_pin_id and verify_product and verify_sup):
                     return jsonify(
                         Error="Invalid inputs o_id and/or pin_id and/or s_id and/or p_id and/or od_qty")
                 else:
                     c_id = verify_pin_id[2]
                     ba_id = verify_sup[2]
                     p_priceperunit = verify_product[2]
                     pname = verify_product[3]
                     product_supplier = verify_product[4]
                     pin_fname = verify_pin_id[0]
                     pin_lname = verify_pin_id[1]
                     sup_fname = verify_sup[0]
                     sup_lname = verify_sup[1]
                     if product_supplier != s_id:
                         return jsonify(Error="supplier does not supply that item")
                     real_o_id = pdao.check_or_create_o_id(o_id, c_id, date)
                     order = dao.insert_product_to_OrderDetails(qty, p_priceperunit, real_o_id, pin_id, s_id,
                                                                ba_id, p_id)
                     if not order:
                         return jsonify(Error="Purchase did not go through")
                     else:
                         order_details = self.build_order_attributes(real_o_id, order, qty, p_priceperunit, s_id,
                                                                     ba_id, p_id, pin_id, c_id, date, sup_fname,
                                                                     sup_lname, pin_fname, pin_lname, pname)
                         new_qty = verify_product[1] - qty
                         dao.update_product_qty(p_id, new_qty)
                         return jsonify(OrderDetails=order_details)
         else:
             return jsonify(Error="Invalid Inputs")
예제 #24
0
 def getSupplierByProduct(self, args):
     p_id = args.get("p_id")
     p_name = args.get("p_name")
     dao = peopledao()
     product_list = []
     if (len(args) == 1) and p_id:
         product_list = dao.getSupplierByProductId(p_id)
     elif (len(args) == 1) and p_name:
         product_list = dao.getSupplierByProductName(p_name)
     else:
         return jsonify(error="malformed query string"), 400
     result_list = []
     for row in product_list:
         result = self.build_supplier_dict(row)
         result_list.append(result)
     return jsonify(SupplierByProduct=result_list)
예제 #25
0
 def insert_bankinfo(self, form):
     dao = peopledao()
     if len(form) != 3:
         return jsonify(Error="Malformed post request"), 400
     else:
         s_id = form['s_id']
         ba_accnumber = form['ba_accnumber']
         ba_routingnumber = form['ba_routingnumber']
         if s_id and ba_accnumber and ba_accnumber:
             ba_id = dao.insert_bankinfo(s_id, ba_accnumber,
                                         ba_routingnumber)
             result = self.build_bankinfo_attributes(
                 ba_id, s_id, ba_accnumber, ba_routingnumber)
             return jsonify(New_Bank_info=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
예제 #26
0
 def insert_creditcard(self, pin_id, form):
     if len(form) != 3:
         return jsonify(Error="Malformed post request"), 400
     else:
         c_cardtype = form['c_cardtype']
         c_cardnumber = form['c_cardnumber']
         c_cardname = form['c_cardname']
         if c_cardtype and c_cardnumber and c_cardname:
             dao = peopledao()
             addressid = dao.get_address_by_pin(pin_id)
             c_id = dao.insert_creditcard(c_cardtype, c_cardnumber,
                                          c_cardname, pin_id, addressid)
             result = self.build_creditcard_attributes(
                 c_id, c_cardtype, c_cardnumber, c_cardname, pin_id,
                 addressid)
             return jsonify(New_CreditCard=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post request"), 400
예제 #27
0
 def getOrdersBySupplier(self, args):
     s_id = args.get("s_id")
     s_fname = args.get("s_fname")
     s_lname = args.get("s_lname")
     dao = peopledao()
     order_list = []
     if (len(args) == 1) and s_id:
         order_list = dao.getOrdersBySupplierById(s_id)
     elif (len(args) == 1) and s_fname:
         order_list = dao.getOrdersBySuppplierByFirstName(s_fname)
     elif (len(args) == 2) and s_fname and s_lname:
         order_list = dao.getOrdersBySupplierByFullName(s_fname, s_lname)
     else:
         return jsonify(error="malformed query string"), 400
     result_list = []
     for row in order_list:
         print(row)
         result = self.build_orderinfo_dict(row)
         result_list.append(result)
     return jsonify(OrdersBySupplier=result_list)
예제 #28
0
 def update_supplier(self, s_id, form):
     dao = peopledao()
     if not dao.get_sup(s_id):
         return jsonify(Error="Supplier not found"), 404
     else:
         if len(form) != 3:
             return jsonify(Error="Malformed update request"), 400
         else:
             s_fname = form['s_fname']
             s_lname = form['s_lname']
             s_phone = form['s_phone']
             if s_fname and s_lname and s_phone:
                 check = dao.update_supplier(s_id, s_fname, s_lname,
                                             s_phone)
                 profile = dao.get_sup(s_id)
                 result = self.build_supplier_dict(profile)
                 return jsonify(Updated_Supplier=result), 201
             else:
                 return jsonify(
                     Error="Unexpected attributes in post request"), 400
예제 #29
0
 def update_pin(self, pin_id, form):
     dao = peopledao()
     if not dao.get_pin(pin_id):
         return jsonify(Error="Person in Need not found."), 404
     else:
         if len(form) != 3:
             return jsonify(Error="Malformed update request"), 400
         else:
             fname = form['pin_fname']
             lname = form['pin_lname']
             phone = form['pin_phone']
         if fname and lname and phone:
             check = dao.update_pin(pin_id, fname, lname, phone)
             profile = dao.get_pin(pin_id)
             print(profile)
             result = self.build_pin_dict(profile)
             return jsonify(PersonInNeed_updated=result), 200
         else:
             return jsonify(
                 Error="Unexpected attributes in update request"), 400
예제 #30
0
 def update_bankinfo(self, s_id, form):
     dao = peopledao()
     ba_id = dao.check_bankinfo(s_id)
     if not ba_id:
         return jsonify(Error="CBank Info not found."), 404
     else:
         if len(form) != 2:
             return jsonify(Error="Malformed update request"), 400
         else:
             ba_accnumber = form['ba_accnumber']
             ba_routingnumber = form['ba_routingnumber']
             if s_id and ba_accnumber and ba_accnumber:
                 dao.update_bankinfo(ba_id, s_id, ba_accnumber,
                                     ba_routingnumber)
                 result = self.build_bankinfo_attributes(
                     ba_id, s_id, ba_accnumber, ba_routingnumber)
                 return jsonify(New_CreditCard=result), 201
             else:
                 return jsonify(
                     Error="Unexpected attributes in post request"), 400