def post(self, service_name): db.create_all() db.session.commit() if ServiceModel.find_by_name(service_name): return { 'message': "An Record with name '{}' already exists.".format(service_name) }, 400 data = self.parser.parse_args() service = ServiceModel( service_name, **data, ) service.created_by = 1 service.created_on = datetime.now() service.modified_by = 0 service.deleted_by = 0 try: service.save_to_db() except Exception as e: return { "message": "An error occurred while inserting the Record.'{}'".format(e) } return service.json(), 201
def post(self): data = self.parser.parse_args() service = ServiceModel(**data) service.created_by = 1 service.created_on = datetime.now() service.modified_by = 0 service.deleted_by = 0 service.modified_on = None service.deleted_on = None try: validateObj = ServiceModel.validateData(data, request) if type(validateObj) is dict: return {"success": False, "errors": validateObj}, 400 if ServiceModel.find_by_name(data['service_name']): return { "success": False, "message": "A service with that Record Name already exists" }, 400 name = data['service_name'] if name.strip(): service.save_to_db() service.token = encodeID(service.service_id) service.save_to_db() else: return { "success": False, "message": "String Should not be empty" } except Exception as e: return { "message": "An error occurred creating the Record.'{}'".format(e) }, 500 return service.json(), 201