|
| 1 | +defmodule BudgetTracker.BudgetCategories do |
| 2 | + @moduledoc """ |
| 3 | + The BudgetCategories context. |
| 4 | + """ |
| 5 | + |
| 6 | + import Ecto.Query, warn: false |
| 7 | + alias BudgetTracker.Repo |
| 8 | + |
| 9 | + alias BudgetTracker.BudgetCategories.BudgetCategory |
| 10 | + |
| 11 | + @doc """ |
| 12 | + Returns the list of budget_categories. |
| 13 | +
|
| 14 | + ## Examples |
| 15 | +
|
| 16 | + iex> list_budget_categories() |
| 17 | + [%BudgetCategory{}, ...] |
| 18 | +
|
| 19 | + """ |
| 20 | + def list_budget_categories do |
| 21 | + Repo.all(BudgetCategory) |
| 22 | + end |
| 23 | + |
| 24 | + @doc """ |
| 25 | + Gets a single budget_category. |
| 26 | +
|
| 27 | + Raises `Ecto.NoResultsError` if the Budget category does not exist. |
| 28 | +
|
| 29 | + ## Examples |
| 30 | +
|
| 31 | + iex> get_budget_category!(123) |
| 32 | + %BudgetCategory{} |
| 33 | +
|
| 34 | + iex> get_budget_category!(456) |
| 35 | + ** (Ecto.NoResultsError) |
| 36 | +
|
| 37 | + """ |
| 38 | + def get_budget_category!(id), do: Repo.get!(BudgetCategory, id) |
| 39 | + |
| 40 | + @doc """ |
| 41 | + Creates a budget_category. |
| 42 | +
|
| 43 | + ## Examples |
| 44 | +
|
| 45 | + iex> create_budget_category(%{field: value}) |
| 46 | + {:ok, %BudgetCategory{}} |
| 47 | +
|
| 48 | + iex> create_budget_category(%{field: bad_value}) |
| 49 | + {:error, %Ecto.Changeset{}} |
| 50 | +
|
| 51 | + """ |
| 52 | + def create_budget_category(attrs \\ %{}) do |
| 53 | + %BudgetCategory{} |
| 54 | + |> BudgetCategory.changeset(attrs) |
| 55 | + |> Repo.insert() |
| 56 | + end |
| 57 | + |
| 58 | + @doc """ |
| 59 | + Updates a budget_category. |
| 60 | +
|
| 61 | + ## Examples |
| 62 | +
|
| 63 | + iex> update_budget_category(budget_category, %{field: new_value}) |
| 64 | + {:ok, %BudgetCategory{}} |
| 65 | +
|
| 66 | + iex> update_budget_category(budget_category, %{field: bad_value}) |
| 67 | + {:error, %Ecto.Changeset{}} |
| 68 | +
|
| 69 | + """ |
| 70 | + def update_budget_category(%BudgetCategory{} = budget_category, attrs) do |
| 71 | + budget_category |
| 72 | + |> BudgetCategory.changeset(attrs) |
| 73 | + |> Repo.update() |
| 74 | + end |
| 75 | + |
| 76 | + @doc """ |
| 77 | + Deletes a budget_category. |
| 78 | +
|
| 79 | + ## Examples |
| 80 | +
|
| 81 | + iex> delete_budget_category(budget_category) |
| 82 | + {:ok, %BudgetCategory{}} |
| 83 | +
|
| 84 | + iex> delete_budget_category(budget_category) |
| 85 | + {:error, %Ecto.Changeset{}} |
| 86 | +
|
| 87 | + """ |
| 88 | + def delete_budget_category(%BudgetCategory{} = budget_category) do |
| 89 | + Repo.delete(budget_category) |
| 90 | + end |
| 91 | + |
| 92 | + @doc """ |
| 93 | + Returns an `%Ecto.Changeset{}` for tracking budget_category changes. |
| 94 | +
|
| 95 | + ## Examples |
| 96 | +
|
| 97 | + iex> change_budget_category(budget_category) |
| 98 | + %Ecto.Changeset{data: %BudgetCategory{}} |
| 99 | +
|
| 100 | + """ |
| 101 | + def change_budget_category(%BudgetCategory{} = budget_category, attrs \\ %{}) do |
| 102 | + BudgetCategory.changeset(budget_category, attrs) |
| 103 | + end |
| 104 | +end |
0 commit comments