예제 #1
0
 def update_cart_info(self, id=None):
     cur = self.db_conn.cursor()
     cur.execute(
         """UPDATE {} SET cart_id = {}, user_id={}, product_id={}, info= \"{}\", creation_date={} where cart_id={} """
         .format(self.table_name, self.id, self.user_id, self.product_id,
                 self.info, self.creation_date, id))
     data = cur.fetchall()
     if len(data) > 0:
         usr = user_data_to_dict(data[0])
     else:
         print("Invalid Cart")
     cur.close()
     self.db_conn.commit()
 def get(self, id=None):
     """
     GET  : It can be used.
         to get user object by id to get specific user.
         to get all users.
     """
     if (id == None):
         try:
             conn = mysql.connect()
             cursor = conn.cursor()
             cursor.callproc('GetAllUser')
             data = cursor.fetchall()
             users = []
             for user in data:
                 usr = user_data_to_dict(user)
                 users.append(usr)
             return {'Users': users}, 200
         except Exception as e:
             return {'error': str(e)}
     else:
         try:
             conn = mysql.connect()
             cursor = conn.cursor()
             cursor.callproc("GetUserById", [id])
             data = cursor.fetchall()
             cursor.close()
             if len(data) > 0:
                 user = user_data_to_dict(data[0])
                 return {'User': user}, 200
             else:
                 return {
                     'StatusCode': '200',
                     'message': 'User not found .. :< '
                 }
         except Exception as e:
             return {'error': str(e)}
 def post(self):
     """
     POST : To create user object.
     """
     try:
         args_data = request.get_json(force=True)
         conn = mysql.connect()
         cursor = conn.cursor()
         cursor.callproc('CreateUser', unicode_to_str(args_data))
         cursor.callproc("LastRowEntry")
         data = cursor.fetchall()[0]
         cursor.close()
         conn.commit()
         if len(data) > 0:
             usr = user_data_to_dict(data)
             return {'User': usr, 'message': 'User get created..'}, 201
         else:
             return {"message": str(data[0])}, 200
     except Exception as e:
         return {'error': str(e)}
예제 #4
0
 def get_discount(self, id=None):
     if id == None:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {}""".format(self.table_name))
         data = cur.fetchall()
         print(data)
         disc_list = []
         for discount in data:
             usr = Discount()
             usr = raw_data_to_discount_model(discount, usr)
             disc_list.append(usr)
         return disc_list
     else:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {} where discount_id= {}""".format(
             self.table_name, self.id))
         data = cur.fetchall()
         if len(data) > 0:
             usr = user_data_to_dict(data[0])
         else:
             print("Invalid discount")
     cur.close()
예제 #5
0
 def get_product(self, product_id=None):
     if product_id == None:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {}""".format(self.table_name))
         data = cur.fetchall()
         print(data)
         prod_list = []
         for user in data:
             usr = Products()
             usr = raw_data_to_product_model(user, usr)
             prod_list.append(usr)
         return prod_list
     else:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {} where product_id= {}""".format(
             self.table_name, self.id))
         data = cur.fetchall()
         if len(data) > 0:
             usr = user_data_to_dict(data[0])
         else:
             print("Invalid product")
     cur.close()
예제 #6
0
 def get_order(self, id=None):
     if id == None:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {}""".format(self.table_name))
         data = cur.fetchall()
         print(data)
         order_list = []
         for order in data:
             usr = Orders()
             usr = raw_data_to_order_model(order, usr)
             order_list.append(usr)
         return order_list
     else:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {} where order_id= {}""".format(
             self.table_name, self.id))
         data = cur.fetchall()
         if len(data) > 0:
             usr = user_data_to_dict(data[0])
         else:
             print("Invalid Order")
     cur.close()
예제 #7
0
 def get_cart(self, id=None):
     if id == None:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {}""".format(self.table_name))
         data = cur.fetchall()
         print(data)
         cart_list = []
         for cart in data:
             usr = User_cart()
             usr = raw_data_to_cart_model(cart, usr)
             cart_list.append(usr)
         return cart_list
     else:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {} where user_cart_id={}""".format(
             self.table_name, id))
         data = cur.fetchall()
         if len(data) > 0:
             usr = user_data_to_dict(data[0])
         else:
             print("Invalid Cart Details")
     cur.close()
예제 #8
0
 def get_category(self, id=None):
     if id == None:
         cur = self.db_conn.cursor()
         cur.execute("""SELECT * from {}""".format(self.table_name))
         data = cur.fetchall()
         print(data)
         cat_list = []
         for user in data:
             usr = Category()
             usr = raw_data_to_category_model(user, usr)
             cat_list.append(usr)
         return cat_list
     else:
         cur = self.db_conn.cursor()
         cur.execute(
             """SELECT * from {} where category_id= {}""".format(self.table_name, self.id))
         data = cur.fetchall()
         if len(data) > 0:
             usr = user_data_to_dict(data[0])
         else:
             print("Invalid category")
     cur.close()