Beispiel #1
0
    def post(self, brand_name):
        db.create_all()
        db.session.commit()
        if BrandsModel.find_by_name(brand_name):
            return {
                'message':
                "An Record with name '{}' already exists.".format(brand_name)
            }, 400

        data = self.parser.parse_args()

        brand = BrandsModel(
            brand_name,
            **data,
        )
        brand.created_by = 1
        brand.created_on = datetime.now()
        brand.modified_by = 0
        brand.deleted_by = 0
        try:
            brand.save_to_db()
        except Exception as e:
            return {
                "message":
                "An error occurred while inserting the Record.'{}'".format(e)
            }

        return brand.json(), 201
Beispiel #2
0
 def put(self, token):
     try:
         data = self.parser.parse_args()
         validateObj = BrandsModel.validateData(data, request)
         if type(validateObj) is dict:
             return {"success": False, "errors": validateObj}, 400
         
         brand_id = decodeID(token)
         brand = BrandsModel.find_by_id(brand_id)
         if not brand or brand.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         
             
         brand.brand_name = data['brand_name']
         brand.modified_on = datetime.now()
         brand.modified_by = 1
         brand.user_id = data['user_id']
         brand.industry_id = data['industry_id']
         brand.brand_category_id =data['brand_category_id']
         name=data['brand_name']
         if name.strip():
             brand.save_to_db()
         else :
             return {"success": False, "message":"Brand Name Should not be empty"}
         
         return {"success": True, "message": "Record updated successfully."}, 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #3
0
 def get(self, brand_name):
     brand = BrandsModel.find_by_name(brand_name)
     try:
         if brand:
             return brand.json()
     except Exception as e:
         return {"message": "Record not found'{}'".format(e)}, 404
Beispiel #4
0
 def get(cls, token):
     try:
         brand_id = decodeID(token)
         brand = BrandsModel.find_by_id(brand_id)
         if not brand or brand.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         return brand.json(), 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #5
0
    def delete(cls, brand_name):
        brand = BrandsModel.find_by_name(brand_name)
        if brand:
            brand.deleted_by = 1
            brand.deleted_on = datetime.now()
            brand.save_to_db()
            #brand.delete_from_db()
            return {'message': 'Record deleted'}

        else:
            return {"Message": "Record Not FOUND"}
Beispiel #6
0
    def put(self, brand_name):
        data = self.parser.parse_args()
        brand = BrandsModel.find_by_name(brand_name)
        if brand:
            brand.modified_on = datetime.now()
            brand.modified_by = 1
            brand.user_id = data['user_id']
            brand.industry_id = data['industry_id']
            brand.brand_category_id = data['brand_category_id']
            brand.save_to_db()

        else:
            return {"Message": "Record Not FOUND"}
        return brand.json()
Beispiel #7
0
 def delete(cls, token):
     try:
         brand_id = decodeID(token)
         brand = BrandsModel.find_by_id(brand_id)
         if not brand or brand.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         
         brand.deleted_by =1
         brand.deleted_on = datetime.now()
         brand.save_to_db()
         #brand.delete_from_db()
         return {"success": True, 'message': 'Record deleted.'}, 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #8
0
    def post(self):
        data = self.parser.parse_args()
        brand = BrandsModel(**data)
        brand.created_by = 1
        brand.created_on = datetime.now()
        brand.modified_by = 0
        brand.deleted_by = 0
        brand.modified_on = None
        brand.deleted_on =  None
        
        try:
            validateObj = BrandsModel.validateData(data, request)

            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            if BrandsModel.find_by_name(data['brand_name']):
                return {"success": False, "message": "A brand with that Record Name already exists"}, 400
            name=data['brand_name']
            if name.strip():
                brand.save_to_db()
                brand.token = encodeID(brand.brand_id)
                brand.save_to_db()
            else:
                return {"success": False, "message":"Brand Name Should not be empty"}
        except Exception as e:
            return {"message": "An error occurred creating the Record.'{}'".format(e)}, 500
        return brand.json(), 201