Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions budgeting/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,45 @@ def find_user_by_id(user_id):
return None

def get_budgets_for_user(user_id):
# TODO: read budgets.csv and return all rows where user_id matches
pass
# DONE? read budgets.csv and return all rows where user_id matches
rows = []
for row in _read_csv("budgets.csv"):
if row["user_id"] == str(user_id):
rows.append(row)
if (rows.count == 0):
return None
else:
return rows

def get_budget_by_id(budget_id):
# TODO: read budgets.csv and return the row where id matches, or None
pass
# DONE? read budgets.csv and return the row where id matches, or None
for row in _read_csv("budgets.csv"):
if row["id"] == str(budget_id):
return row
return None

def get_categories_for_budget(budget_id):
# TODO: read categories.csv and return all rows where budget_id matches
pass

# DONE? read categories.csv and return all rows where budget_id matches
rows = []
for row in _read_csv("categories.csv"):
if row["budget_id"] == str(budget_id):
rows.append(row)
if (rows.count == 0):
return None
else:
return rows

def get_latest_budget(user_id):
# TODO: get all budgets for this user and return the most recently created, or None
pass
latest_budget = []
for row in _read_csv("budgets.csv"):
if (row["user_id"] == str(user_id)):
if (latest_budget == [] or latest_budget["date_created"] < row["date_created"]):
latest_budget = row
if (latest_budget == []):
return None
else:
return latest_budget

def save_budget(user_id, monthly_income, carryover, categories):
# TODO: append a new row to budgets.csv and save categories, return the new id
Expand Down