コード例 #1
0
def delete_brand_function():
    if request.method == 'POST':
        try:
            input_data = json.loads(request.get_data())
            response = brandHandle.delete_brand(input_data)
            return json.dumps(response)
        except Exception as e:
            return json.dumps(AppConstants.result_error_template(str(e)))
    else:
        return json.dumps(AppConstants.result_error_template(AppConstants.method_not_supported))
コード例 #2
0
ファイル: supplierServices.py プロジェクト: ramHruday/bApp-be
def create_supplier():
    if request.method == 'POST':
        try:
            input_data = json.loads(request.get_data())
            response = supplierHandle.create_supplier(input_data)
            print(response)
            return json.dumps(response)
        except Exception as e:
            return json.dumps(AppConstants.result_error_template(str(e)))
    else:
        return json.dumps(
            AppConstants.result_error_template(
                AppConstants.method_not_supported))
コード例 #3
0
 def create_location(self, input_json):
     try:
         print(input_json)
         if AppConstants.LOCATION.location not in input_json \
                 or (input_json[AppConstants.LOCATION.location] is None
                     or input_json[AppConstants.LOCATION.location] == ""):
             print('location name not present')
             raise BPLocationException(
                 AppConstants.LOCATION.location +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         if AppConstants.LOCATION.address not in input_json \
                 or (input_json[AppConstants.LOCATION.address] is None
                     or input_json[AppConstants.LOCATION.address] == ""):
             print(AppConstants.LOCATION.address +
                   AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
             raise BPLocationException(
                 AppConstants.LOCATION.address +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         input_json[AppConstants.LOCATION.
                    LOCATION_ID] = self.mongo_db_object.UUID_generator(
                        AppConstants.LOCATION.LOCATION_ID)
         self.mongo_db_object.insert_one(
             input_json, AppConfigurations.MONGO_DATABASE,
             AppConstants.LOCATION.MONGO_LOCATION_COLLECTION_NAME)
         return AppConstants.result_success_template(
             "Successfully Created a Location")
     except Exception as e:
         print(e)
コード例 #4
0
 def create_brand(self, input_json):
     try:
         print(input_json)
         if AppConstants.BRANDS.brand_series not in input_json \
                 or (input_json[AppConstants.BRANDS.brand_series] is None
                     or input_json[AppConstants.BRANDS.brand_series] == ""):
             print('brand name not present')
             raise BPBrandException(
                 AppConstants.BRANDS.brand_series +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         if AppConstants.BRANDS.brand_name not in input_json \
                 or (input_json[AppConstants.BRANDS.brand_name] is None
                     or input_json[AppConstants.BRANDS.brand_name] == ""):
             print(AppConstants.BRANDS.brand_name +
                   AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
             raise BPBrandException(
                 AppConstants.BRANDS.brand_name +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         input_json[AppConstants.BRANDS.
                    BRAND_ID] = self.mongo_db_object.UUID_generator(
                        AppConstants.BRANDS.BRAND_ID)
         self.mongo_db_object.insert_one(
             input_json, AppConfigurations.MONGO_DATABASE,
             AppConstants.BRANDS.MONGO_BRAND_COLLECTION_NAME)
         return AppConstants.result_success_template(
             "Successfully Created a Brand")
     except Exception as e:
         print(e)
コード例 #5
0
ファイル: product_handler.py プロジェクト: ramHruday/bApp-be
 def create_product(self, input_json):
     try:
         print(input_json)
         if AppConstants.PRODUCT.name not in input_json \
                 or (input_json[AppConstants.PRODUCT.name] is None
                     or input_json[AppConstants.PRODUCT.name] == ""):
             print('name not present')
             raise BPProductException(
                 AppConstants.PRODUCT.name +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         if AppConstants.PRODUCT.sub_type not in input_json \
                 or (input_json[AppConstants.PRODUCT.sub_type] is None
                     or input_json[AppConstants.PRODUCT.sub_type] == ""):
             print(AppConstants.PRODUCT.sub_type +
                   AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
             raise BPProductException(
                 AppConstants.PRODUCT.sub_type +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         input_json[AppConstants.PRODUCT.
                    PRODUCT_ID] = self.mongo_db_object.UUID_generator(
                        AppConstants.PRODUCT.PRODUCT_ID)
         self.mongo_db_object.insert_one(
             input_json, AppConfigurations.MONGO_DATABASE,
             AppConstants.PRODUCT.MONGO_PRODUCT_COLLECTION_NAME)
         return AppConstants.result_success_template(
             "Successfully Created a Product")
     except Exception as e:
         print(e)
コード例 #6
0
ファイル: supplier_handler.py プロジェクト: ramHruday/bApp-be
 def create_supplier(self, input_json):
     try:
         print(input_json)
         if AppConstants.SUPPLIER.supplier not in input_json \
                 or (input_json[AppConstants.SUPPLIER.supplier] is None
                     or input_json[AppConstants.SUPPLIER.supplier] == ""):
             print('name not present')
             raise BPSupplierException(
                 AppConstants.SUPPLIER.supplier +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         if AppConstants.SUPPLIER.contact not in input_json \
                 or (input_json[AppConstants.SUPPLIER.contact] is None
                     or input_json[AppConstants.SUPPLIER.contact] == ""):
             print(AppConstants.SUPPLIER.contact +
                   AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
             raise BPSupplierException(
                 AppConstants.SUPPLIER.contact +
                 AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
         input_json[AppConstants.SUPPLIER.
                    SUPPLIER_ID] = self.mongo_db_object.UUID_generator(
                        AppConstants.SUPPLIER.SUPPLIER_ID)
         self.mongo_db_object.insert_one(
             input_json, AppConfigurations.MONGO_DATABASE,
             AppConstants.SUPPLIER.MONGO_SUPPLIER_COLLECTION_NAME)
         return AppConstants.result_success_template(
             "Successfully Created a Supplier")
     except Exception as e:
         print(e)
コード例 #7
0
def fetch_all_brands():
    if request.method == 'GET':
        try:
            brand_data = brandHandle.get_brands()
            response = brand_data
            return json.dumps(response, default=str)
        except Exception as e:
            print(e, ': error while fetching from brand service')
            return str(e)
    else:
        return json.dumps(AppConstants.result_error_template(AppConstants.method_not_supported))
コード例 #8
0
    def get_locations(self):
        """
        This Method is used to Get the Locations in Database
        :param input_json:
        :return:
        """
        try:
            output_json = {}
            total_locations = list(
                self.mongo_db_object.find_all(
                    AppConfigurations.MONGO_DATABASE,
                    AppConstants.LOCATION.MONGO_LOCATION_COLLECTION_NAME))
            output_json = total_locations
            return AppConstants.result_success_template(output_json)

        except Exception as e:
            print("Error while fetching the Location Data.", str(e))
コード例 #9
0
    def update_location(self, input_json):
        """
        This method is used to update the location data
        :param input_json: location obj,
        :return:
        """
        try:
            if AppConstants.LOCATION.LOCATION_ID not in input_json \
                    or (input_json[AppConstants.LOCATION.LOCATION_ID] is None
                        or input_json[AppConstants.LOCATION.LOCATION_ID] == ""):
                print(AppConstants.LOCATION.LOCATION_ID +
                      AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
                raise BPLocationException(
                    AppConstants.LOCATION.LOCATION_ID +
                    AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)

            location_data = list(
                self.mongo_db_object.find_json(
                    {
                        AppConstants.LOCATION.LOCATION_ID:
                        input_json[AppConstants.LOCATION.LOCATION_ID]
                    }, AppConfigurations.MONGO_DATABASE,
                    AppConstants.LOCATION.MONGO_LOCATION_COLLECTION_NAME))

            if location_data:
                try:
                    response = self.mongo_db_object.update_one(
                        {
                            AppConstants.LOCATION.LOCATION_ID:
                            input_json[AppConstants.LOCATION.LOCATION_ID]
                        }, input_json, AppConfigurations.MONGO_DATABASE,
                        AppConstants.LOCATION.MONGO_LOCATION_COLLECTION_NAME)
                    print("Successfully updated location")
                except Exception as e:
                    print(e, 'exception in updating location')
                return AppConstants.result_success_template(
                    "successfully updated the location data")
            else:
                print("No Location found with the specified ID")
                raise BPLocationException(
                    "No Location found with the specified ID")
        except Exception as e:
            raise BPLocationException(e)
コード例 #10
0
ファイル: product_handler.py プロジェクト: ramHruday/bApp-be
    def update_product(self, input_json):
        """
        This method is used to update the product data
        :param input_json: product obj,
        :return:
        """
        try:
            if AppConstants.PRODUCT.PRODUCT_ID not in input_json \
                    or (input_json[AppConstants.PRODUCT.PRODUCT_ID] is None
                        or input_json[AppConstants.PRODUCT.PRODUCT_ID] == ""):
                print(AppConstants.PRODUCT.PRODUCT_ID +
                      AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
                raise BPProductException(
                    AppConstants.PRODUCT.PRODUCT_ID +
                    AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)

            product_data = list(
                self.mongo_db_object.find_json(
                    {
                        AppConstants.PRODUCT.PRODUCT_ID:
                        input_json[AppConstants.PRODUCT.PRODUCT_ID]
                    }, AppConfigurations.MONGO_DATABASE,
                    AppConstants.PRODUCT.MONGO_PRODUCT_COLLECTION_NAME))

            if product_data:
                try:
                    response = self.mongo_db_object.update_one(
                        {
                            AppConstants.PRODUCT.PRODUCT_ID:
                            input_json[AppConstants.PRODUCT.PRODUCT_ID]
                        }, input_json, AppConfigurations.MONGO_DATABASE,
                        AppConstants.PRODUCT.MONGO_PRODUCT_COLLECTION_NAME)
                    print("Successfully updated product")
                except Exception as e:
                    print(e, 'exception in updating product')
                return AppConstants.result_success_template(
                    "successfully updated the product data")
            else:
                print("No PRODUCT found with the specified ID")
                raise BPProductException(
                    "No PRODUCT found with the specified ID")
        except Exception as e:
            raise BPProductException(e)
コード例 #11
0
ファイル: supplier_handler.py プロジェクト: ramHruday/bApp-be
    def update_supplier(self, input_json):
        """
        This method is used to update the supplier data
        :param input_json: supplier obj,
        :return:
        """
        try:
            if AppConstants.SUPPLIER.SUPPLIER_ID not in input_json \
                    or (input_json[AppConstants.SUPPLIER.SUPPLIER_ID] is None
                        or input_json[AppConstants.SUPPLIER.SUPPLIER_ID] == ""):
                print(AppConstants.SUPPLIER.SUPPLIER_ID +
                      AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
                raise BPSupplierException(
                    AppConstants.SUPPLIER.SUPPLIER_ID +
                    AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)

            supplier_data = list(
                self.mongo_db_object.find_json(
                    {
                        AppConstants.SUPPLIER.SUPPLIER_ID:
                        input_json[AppConstants.SUPPLIER.SUPPLIER_ID]
                    }, AppConfigurations.MONGO_DATABASE,
                    AppConstants.SUPPLIER.MONGO_SUPPLIER_COLLECTION_NAME))

            if supplier_data:
                try:
                    response = self.mongo_db_object.update_one(
                        {
                            AppConstants.SUPPLIER.SUPPLIER_ID:
                            input_json[AppConstants.SUPPLIER.SUPPLIER_ID]
                        }, input_json, AppConfigurations.MONGO_DATABASE,
                        AppConstants.SUPPLIER.MONGO_SUPPLIER_COLLECTION_NAME)
                    print("Successfully updated supplier")
                except Exception as e:
                    print(e, 'exception in updating supplier')
                return AppConstants.result_success_template(
                    "successfully updated the supplier data")
            else:
                print("No Supplier found with the specified ID")
                raise BPSupplierException(
                    "No Supplier found with the specified ID")
        except Exception as e:
            raise BPSupplierException(e)
コード例 #12
0
    def update_brand(self, input_json):
        """
        This method is used to update the brand data
        :param input_json: brand obj,
        :return:
        """
        try:
            if AppConstants.BRANDS.BRAND_ID not in input_json \
                    or (input_json[AppConstants.BRANDS.BRAND_ID] is None
                        or input_json[AppConstants.BRANDS.BRAND_ID] == ""):
                print(AppConstants.BRANDS.BRAND_ID +
                      AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)
                raise BPBrandException(
                    AppConstants.BRANDS.BRAND_ID +
                    AppConstants.PROJECT.NOT_PRESENT_ERROR_MSG)

            brand_data = list(
                self.mongo_db_object.find_json(
                    {
                        AppConstants.BRANDS.BRAND_ID:
                        input_json[AppConstants.BRANDS.BRAND_ID]
                    }, AppConfigurations.MONGO_DATABASE,
                    AppConstants.BRANDS.MONGO_BRAND_COLLECTION_NAME))

            if brand_data:
                try:
                    response = self.mongo_db_object.update_one(
                        {
                            AppConstants.BRANDS.BRAND_ID:
                            input_json[AppConstants.BRANDS.BRAND_ID]
                        }, input_json, AppConfigurations.MONGO_DATABASE,
                        AppConstants.BRANDS.MONGO_BRAND_COLLECTION_NAME)
                    print("Successfully updated brand")
                except Exception as e:
                    print(e, 'exception in updating brand')
                return AppConstants.result_success_template(
                    "successfully updated the brand data")
            else:
                print("No Brand found with the specified ID")
                raise BPBrandException("No Brand found with the specified ID")
        except Exception as e:
            raise BPBrandException(e)