Skip to content

Commit

Permalink
feat: more transaction categories (#180)
Browse files Browse the repository at this point in the history
* schema: add investments transaction category

* fix: interest income transaction category spelling
  • Loading branch information
nicolasauler authored Dec 18, 2024
1 parent 6d478dd commit 7151b42
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
26 changes: 26 additions & 0 deletions migrations/20241218042446_even-more-categories.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BEGIN;

ALTER TYPE expense_category RENAME TO expense_category_old;

CREATE TYPE expense_category AS ENUM (
'restaurants',
'shopping',
'services',
'entertainment',
'groceries',
'salary',
'interest Income',
'utilities',
'pharmacy',
'transfer',
'transport',
'others'
);

ALTER TABLE expenses
ALTER COLUMN category TYPE expense_category
USING category::text::expense_category;

DROP TYPE expense_category_old;

COMMIT;
22 changes: 22 additions & 0 deletions migrations/20241218042446_even-more-categories.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BEGIN;
ALTER TYPE expense_category RENAME TO expense_category_old;
CREATE TYPE expense_category AS ENUM (
'restaurants',
'shopping',
'services',
'entertainment',
'groceries',
'salary',
'interestincome',
'utilities',
'pharmacy',
'transfer',
'transport',
'others',
'investments'
);
ALTER TABLE expenses
ALTER COLUMN category TYPE expense_category
USING category::text::expense_category;
DROP TYPE expense_category_old;
COMMIT;
7 changes: 5 additions & 2 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ pub enum ExpenseCategory {
Entertainment,
Groceries,
Salary,
#[serde(rename = "Interest Income")]
InterestIncome,
Utilities,
Pharmacy,
Transfer,
Transport,
#[default]
Others,
Investments,
}

impl FromStr for ExpenseCategory {
Expand All @@ -37,7 +39,7 @@ impl FromStr for ExpenseCategory {
"Entertainment" => return Ok(Self::Entertainment),
"Groceries" => return Ok(Self::Groceries),
"Salary" => return Ok(Self::Salary),
"InterestIncome" => return Ok(Self::InterestIncome),
"Interest Income" => return Ok(Self::InterestIncome),
"Utilities" => return Ok(Self::Utilities),
"Pharmacy" => return Ok(Self::Pharmacy),
"Transfer" => return Ok(Self::Transfer),
Expand All @@ -57,12 +59,13 @@ impl Display for ExpenseCategory {
Self::Entertainment => return write!(fmtr, "Entertainment"),
Self::Groceries => return write!(fmtr, "Groceries"),
Self::Salary => return write!(fmtr, "Salary"),
Self::InterestIncome => return write!(fmtr, "InterestIncome"),
Self::InterestIncome => return write!(fmtr, "Interest Income"),
Self::Utilities => return write!(fmtr, "Utilities"),
Self::Pharmacy => return write!(fmtr, "Pharmacy"),
Self::Transfer => return write!(fmtr, "Transfer"),
Self::Transport => return write!(fmtr, "Transport"),
Self::Others => return write!(fmtr, "Others"),
Self::Investments => return write!(fmtr, "Investments"),
}
}
}
Expand Down

0 comments on commit 7151b42

Please sign in to comment.