def post(self): args = parser.parse_args() user = Users(username=args.username, email=args.email) db.session.add(user) db.session.commit() db.session.remove() return handle_success(message='add success', code='10201')
def delete(self, user_id): user = Users.query.filter_by(id=user_id).first() if user is None: return handle_error( message="User {} doesn't exist".format(user_id), code='10404') db.session.delete(user) db.session.commit() db.session.remove() return handle_success(message='delete success', code='10204')
def put(self, user_id): args = parser.parse_args() user = Users.query.filter_by(id=user_id).first() user.username = args.username user.email = args.email data = user.to_json() db.session.commit() db.session.remove() return handle_success(message='update success', code='10204', data=data)
def make_10_mock_data(): from models.user import User dev_sqlite_file = os.path.join(os.path.dirname(__file__), 'data-dev.sqlite') if os.path.exists(dev_sqlite_file): fake = Faker() for _ in range(10): o = User(fake.name(), fake.email()) db.session.add(o) db.session.commit() return handle.handle_success() else: db.create_all() return handle.handle_error(data='setup env, please try again')
def root_path(): return handle_success()
def endpoint(): data = 'endpoint is %s' % '/xls/' return handle.handle_success(data=data)
def get(self): query = Users.query.all() list = [o.to_json() for o in query] return handle_success(message='query success', data=list)
def get(self, user_id): user = Users.query.filter_by(id=user_id).first() if user is None: return handle_error( message="User {} doesn't exist".format(user_id), code='10404') return handle_success(message='query success', data=user.to_json())
def health_check(): cmd = 'ls /opt' data = Command().get_status_output(cmd) return handle.handle_success(str(data))