Esempio n. 1
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)}
Esempio n. 2
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)}
Esempio n. 3
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)}