Beispiel #1
0
    def get(self):
        request = reqparse.RequestParser() \
            .add_argument('id', type=int) \
            .add_argument('balances') \
            .parse_args()

        user_id = get_jwt_identity()

        id = request['id']
        if id is not None:
            if id < 0:
                return resp_util.invalid_request()

            t = Transaction.find_by_user_id(user_id, id)

            return ser_util.serialize_transaction(
                t, Balance.actual_balance(
                    t.balance_id)) if t else resp_util.not_found()

        try:
            balances_string = request['balances']
        except KeyError:
            balances_string = ''

        balances_stripped_string = balances_string.strip()
        transactions = Transaction.find_by_user_id(user_id) if not balances_stripped_string \
            else Transaction.find_by_balance_ids(balances_stripped_string.split(','))

        return ser_util.serialize_transactions(
            transactions, calculate_actual_balances(transactions))
Beispiel #2
0
    def put(self):
        parser = reqparse.RequestParser()
        parser.add_argument('name', required=True)
        parser.add_argument('id', required=True)

        data = parser.parse_args()
        if not data['name'].strip():
            return resp_util.invalid_request()

        balance = Balance.find_by_id(data['id'])
        if balance is None or balance.system is True:
            return resp_util.not_found()

        balance.name = data['name']
        try:
            balance.update()
        except:
            return {'message': 'Something went wrong'}, 500
Beispiel #3
0
    def get(self):
        request = reqparse.RequestParser() \
            .add_argument('id', type=int) \
            .add_argument('currency') \
            .parse_args()

        if request['id'] is None:
            balances = list(
                filter(lambda b: b.system is False,
                       User.find_by_id(get_jwt_identity()).balances))
            return ser_util.serialize_balances(balances) if not request['currency'] \
                else ser_util.serialize_balances(list(filter(lambda b: b.currency == request['currency'], balances)))

        if request['id'] <= 0:
            return resp_util.invalid_request('Given id isn\'t valid')

        balance = Balance.find_by_user_id(get_jwt_identity(), request['id'])
        if not balance or balance.system is True:
            return resp_util.not_found()
        return ser_util.serialize_balance(balance)
Beispiel #4
0
    def get(self):
        id = reqparse.RequestParser() \
            .add_argument('id', type=int) \
            .parse_args()['id']

        if id is None:
            response = []
            for goal in User.find_by_id(get_jwt_identity()).goals:
                response.append(
                    ser_util.serialize_goal(
                        goal, Balance.actual_balance(goal.balance_id)))
            return response

        if id <= 0:
            return resp_util.invalid_request('Given id isn\'t valid')

        goal = Goal.find_by_user_id(get_jwt_identity(), id)
        if not goal:
            return resp_util.not_found()
        return ser_util.serialize_goal(goal,
                                       Balance.actual_balance(goal.balance_id))
Beispiel #5
0
    def get(self):
        id = reqparse.RequestParser() \
            .add_argument('id', type=int) \
            .parse_args()['id']

        if id is None:
            response = []
            for budget in User.find_by_id(get_jwt_identity()).budgets:
                response.append(
                    ser_util.serialize_budget(
                        budget, calculate_budget_current_amount(budget)))
            return response

        if id <= 0:
            return resp_util.invalid_request('Given id isn\'t valid')

        budget = Budget.find_by_user_id(get_jwt_identity(), id)
        if not budget:
            return resp_util.not_found()
        return ser_util.serialize_budget(
            budget, calculate_budget_current_amount(budget))