def update_group(group_id, args): group = Group.get_group(group_id) if group is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found group') if 'group_id' not in args: args['group_id'] = group['group_id'] if 'group_name' not in args: args['group_name'] = group['group_name'] new_group_id = args['group_id'] group = Group.get_group(new_group_id) if new_group_id != group_id and group is not None: raise Error(StatusCode.BAD_REQUEST, 'Group ID is already existed') group = Group.update_group(group_id, new_group_id, args['group_name']) return jsonify({'status': True, 'group': group}), StatusCode.OK
def add_group(args): group_id = Group.form_group_id(args['group_link']) group = Group.get_group(group_id) if group is not None: raise Error(StatusCode.BAD_REQUEST, 'Group is already existed') group = Group.add_group(group_id, args['group_name']) return jsonify({'status': True, 'group': group}), StatusCode.OK
def delete_group(group_id): group = Group.get_group(group_id) if group is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found group') Group.delete_group(group_id) return jsonify({ 'status': True, 'message': 'Delete group successfully' }), StatusCode.OK
def add_user_work(user_id, args): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found user') if 'work_place_link' not in args: args['work_place_link'] = None work = User.add_user_work(user_id, args['work_place_name'], args['work_place_link']) return jsonify({'status': True, 'work': work}), StatusCode.OK
def decorated_function(*args, **kwargs): request_args = request.get_json() or {} if request.method == 'GET': request_args = request.args.to_dict() parsed_args, errors = schema.load(request_args) if errors: raise Error(StatusCode.BAD_REQUEST, 'Bad request', errors) kwargs['args'] = parsed_args return f(*args, **kwargs)
def leave_group(user_id, args): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found user') User.leave_group(user_id, args['group_link']) return jsonify({ 'status': True, 'message': 'Leave group successfully' }), StatusCode.OK
def delete_user_work(user_id, args): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found user') User.delete_user_work(user_id, args['work_place_link']) return jsonify({ 'status': True, 'message': 'Delete work successfully' }), StatusCode.OK
def update_user(user_id, args): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot find user') if 'user_id' not in args: args['user_id'] = user['user_id'] if 'username' not in args: args['username'] = user['username'] if 'user_basic_info' not in args: args['user_basic_info'] = user['user_basic_info'] if 'user_contact_info' not in args: args['user_contact_info'] = user['user_contact_info'] if 'user_relationship_info' not in args: args['user_relationship_info'] = user['user_relationship_info'] new_user_id = args['user_id'] user = User.get_user(new_user_id) if user_id != new_user_id and user is not None: raise Error(StatusCode.BAD_REQUEST, 'User ID is already existed') user = User.update_user(user_id, new_user_id, args['username'], args['user_basic_info'], args['user_contact_info'], args['user_relationship_info']) return jsonify({'status': True, 'user': user}), StatusCode.OK
def add_user(args): user = User.get_user(args['user_id']) if user is not None: raise Error(StatusCode.BAD_REQUEST, 'User is already existed') if 'user_basic_info' not in args: args['user_basic_info'] = None if 'user_contact_info' not in args: args['user_contact_info'] = None if 'user_relationship_info' not in args: args['user_relationship_info'] = None user = User.add_user(args['user_id'], args['username'], args['user_basic_info'], args['user_contact_info'], args['user_relationship_info']) return jsonify({'status': True, 'user': user}), StatusCode.OK
def get_group_members(group_id): group = Group.get_group(group_id) if group is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found group') members = Group.get_group_members(group_id) return jsonify({'status': True, 'members': members}), StatusCode.OK
def get_user_works(user_id): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot find user') works = User.get_user_works(user_id) return jsonify({'status': True, 'works': works}), StatusCode.OK
def delete_user(user_id): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot find user') User.delete_user(user_id) return jsonify({'status': True, 'message': 'Delete user successfully'})
def get_user_groups(user_id): user = User.get_user(user_id) if user is None: raise Error(StatusCode.NOT_FOUND, 'Cannot found user') groups = User.get_user_groups(user_id) return jsonify({'status': True, 'groups': groups}), StatusCode.OK