Exemplo n.º 1
0
async def current_month_spending(bank_account_id: int,
                                 day_of_month: Optional[int] = None,
                                 categories: List[str] = Query(None)):

    transactions = load_user_data(bank_account_id)

    if len(transactions) == 0:
        raise HTTPException(
            status_code=404,
            detail=f"Bank Account ID, {bank_account_id}, doesn't exist")

    if not categories:
        raise HTTPException(
            status_code=404,
            detail=
            f"Please provide the categories that were in the user's budget")

    user = User(transactions)

    if day_of_month:
        return user.current_month_spending(fixed_categories=categories,
                                           date_cutoff=day_of_month)
    else:
        return user.current_month_spending(fixed_categories=categories)