예제 #1
0
    def put(self):
        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            _json = request.json
            _client_id = _json['client_id']
            _client_name = _json['client_name']
            _client_status = _json['client_status']
            _mobile_phone = _json['mobile_phone']
            _email_address = _json['email_address']
            _city = _json['city']

            cursor.execute("SELECT count(*) FROM client WHERE client_id=%s",
                           (_client_id, ))
            check_record_exist = cursor.fetchone().get('count(*)')
            if check_record_exist:
                if not isinstance(conn, str):
                    query = "UPDATE client set client_name=%s, client_status=%s, mobile_phone=%s, email_address=%s, city=%s where client_id = %s"
                    bindData = (_client_name, _client_status, _mobile_phone,
                                _email_address, _city, _client_id)
                    cursor = conn.cursor()
                    cursor.execute(query, bindData)
                    conn.commit()
                    close_connection(conn, cursor)

                    return api_success(None, "Client updated successfully")
                else:
                    return api_failure(str(conn))
            else:
                return {"message": "Record not found"}, 404
        except Exception as error:
            return api_failure(str(error))
예제 #2
0
    def get(self):
        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            client_id = int(request.headers.get('client_id'))
            cursor.execute("SELECT count(*) FROM client WHERE client_id=%s",
                           (client_id, ))
            check_record_exist = cursor.fetchone().get('count(*)')
            if check_record_exist:
                if not isinstance(conn, str):
                    query = "SELECT client_id, client_name, client_status, mobile_phone, email_address, city FROM client \
                             WHERE client_id = {client_id}".format(
                        client_id=client_id)
                    cursor.execute(query)
                    clientRow = cursor.fetchone()
                    close_connection(conn, cursor)

                    return api_success(clientRow,
                                       "Client details fetched successfully")
                else:
                    return api_failure(str(conn))
            else:
                return {"message": "Record not found"}, 404
        except Exception as error:
            return api_failure(str(error))
예제 #3
0
    def post(self):
        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            _json = request.json
            _client_name = _json['client_name']
            _client_status = _json['client_status']
            _mobile_phone = _json['mobile_phone']
            _email_address = _json['email_address']
            _city = _json['city']
            if not isinstance(conn, str):
                query = "INSERT INTO client(client_name, client_status, mobile_phone, email_address, city) VALUES(%s, %s, %s, %s, %s)"
                bindData = (_client_name, _client_status, _mobile_phone,
                            _email_address, _city)
                cursor = conn.cursor()
                cursor.execute(query, bindData)
                conn.commit()
                close_connection(conn, cursor)

                return api_success(None, "Client saved successfully")
            else:
                return api_failure(str(conn))
        except Exception as error:
            return api_failure(str(error))
예제 #4
0
    def put(self):
        try:
            conn = mysql.connector.connect(**config)
            cursor = conn.cursor(dictionary=True)
            _json = request.json
            _product_id = _json['product_id']
            _product_name = _json['product_name']
            _product_status = _json['product_status']
            cursor.execute("SELECT count(*) FROM product WHERE product_id=%s",
                           (_product_id, ))
            check_record_exist = cursor.fetchone().get('count(*)')
            if check_record_exist:
                if not isinstance(conn, str):
                    query = "UPDATE product set product_name=%s, product_status=%s where product_id = %s"
                    bindData = (_product_name, _product_status, _product_id)
                    cursor = conn.cursor()
                    cursor.execute(query, bindData)
                    conn.commit()
                    close_connection(conn, cursor)

                    return api_success(None, "Product updated successfully")
                else:
                    return api_failure(str(conn))
            else:
                return {"message": "Record not found"}, 404
        except Exception as error:
            return api_failure(str(error))
예제 #5
0
    def get(self):
        try:
            conn = mysql.connector.connect(**config)
            cursor = conn.cursor(dictionary=True)
            product_id = int(request.headers.get('product_id'))
            cursor.execute("SELECT count(*) FROM product WHERE product_id=%s",
                           (product_id, ))
            check_record_exist = cursor.fetchone().get('count(*)')
            if check_record_exist:
                if not isinstance(conn, str):
                    query = "SELECT product_id, product_name, product_status FROM product \
                             WHERE product_id = {product_id}".format(
                        product_id=product_id)
                    cursor.execute(query)
                    productRow = cursor.fetchone()
                    close_connection(conn, cursor)

                    return api_success(
                        productRow, "Products details fetched successfully")
                else:
                    return api_failure(str(conn))
            else:
                return {"message": "Record not found"}, 404
        except Exception as error:
            return api_failure(str(error))
예제 #6
0
    def get(self):
        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            if not isinstance(conn, str):
                cursor.execute("SELECT product_id, product_name, product_status FROM product")
                productRows = cursor.fetchall()
                close_connection(conn, cursor)
                return api_success(productRows, "Products lists fetched successfully")
            else:
                return api_failure(str(conn))
        except Exception as error:
            return api_failure(str(error))
예제 #7
0
    def get(self):
        try:
            conn = mysql.connect()
            cursor = conn.cursor()

            if not isinstance(conn, str):
                cursor.execute("SELECT client_id, client_name, mobile_phone, email_address, city FROM client")
                clientRows = cursor.fetchall()
                close_connection(conn, cursor)
                return api_success(clientRows, "Clients lists fetched successfully")
            else:
                return api_failure(str(conn))
        except Exception as error:
            return api_failure(str(error))
예제 #8
0
    def post(self):
        try:
            conn = mysql.connector.connect(**config)
            _json = request.json
            _product_name = _json['product_name']
            _product_status = _json['product_status']
            if not isinstance(conn, str):
                cursor = conn.cursor(dictionary=True)
                query = "INSERT INTO product(product_name, product_status) VALUES(%s, %s)"
                bindData = (_product_name, _product_status)
                cursor = conn.cursor()
                cursor.execute(query, bindData)
                conn.commit()
                close_connection(conn, cursor)

                return api_success(None, "Product saved successfully")
            else:
                return api_failure(str(conn))
        except Exception as error:
            return api_failure(str(error))
예제 #9
0
    def delete(self):
        try:
            conn = mysql.connector.connect(**config)
            cursor = conn.cursor(dictionary=True)
            _product_id = int(request.headers.get('product_id'))
            cursor.execute("SELECT count(*) FROM product WHERE product_id=%s",
                           (_product_id, ))
            check_record_exist = cursor.fetchone().get('count(*)')
            if check_record_exist:
                if not isinstance(conn, str):
                    query = "DELETE FROM product WHERE product_id =%s"
                    bindData = (_product_id, )
                    cursor.execute(query, bindData)
                    conn.commit()
                    close_connection(conn, cursor)

                    return api_success(None, "Products deleted successfully")
                else:
                    return api_failure(str(conn))
            else:
                return {"message": "Record not found"}, 404
        except Exception as error:
            return api_failure(str(error))