1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 21:15:19 +02:00

Scaffold out basic transactions model and UI (#478)

* Transaction scaffold

* Rough in transaction views

* Fix sort order

* Fix mass assignment issue

* Fix test

* Simplify CI workflow

* Don't seed db before test
This commit is contained in:
Zach Gollwitzer 2024-02-23 21:34:33 -05:00 committed by GitHub
parent e767aca37f
commit 87b97b3c41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 430 additions and 44 deletions

View file

@ -0,0 +1,13 @@
class CreateTransactions < ActiveRecord::Migration[7.2]
def change
create_table :transactions, id: :uuid do |t|
t.string :name
t.date :date, null: false
t.decimal :amount, precision: 19, scale: 4, null: false
t.string :currency, default: "USD", null: false
t.references :account, null: false, type: :uuid, foreign_key: { on_delete: :cascade }
t.timestamps
end
end
end

14
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_02_22_144849) do
ActiveRecord::Schema[7.2].define(version: 2024_02_23_162105) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -196,6 +196,17 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_22_144849) do
t.index ["token"], name: "index_invite_codes_on_token", unique: true
end
create_table "transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name"
t.date "date", null: false
t.decimal "amount", precision: 19, scale: 4, null: false
t.string "currency", default: "USD", null: false
t.uuid "account_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id"], name: "index_transactions_on_account_id"
end
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "family_id", null: false
t.string "first_name"
@ -220,6 +231,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_22_144849) do
add_foreign_key "account_balances", "accounts", on_delete: :cascade
add_foreign_key "accounts", "families"
add_foreign_key "transactions", "accounts", on_delete: :cascade
add_foreign_key "users", "families"
add_foreign_key "valuations", "accounts", on_delete: :cascade
end

View file

@ -40,6 +40,15 @@ valuations = [
{ date: Date.today - 3, value: 301900 }
]
transactions = [
{ date: Date.today - 27, amount: 7.56, currency: "USD", name: "Starbucks" },
{ date: Date.today - 18, amount: -2000, currency: "USD", name: "Paycheck" },
{ date: Date.today - 18, amount: 18.20, currency: "USD", name: "Walgreens" },
{ date: Date.today - 13, amount: 34.20, currency: "USD", name: "Chipotle" },
{ date: Date.today - 9, amount: -200, currency: "USD", name: "Birthday check" },
{ date: Date.today - 5, amount: 85.00, currency: "USD", name: "Amazon stuff" }
]
# Represent system-generated "Balances" at various dates, based on valuations
balances = [
{ date: Date.today - 30, balance: 300000 },
@ -75,6 +84,8 @@ balances = [
{ date: Date.today, balance: current_balance }
]
valuations.each do |valuation|
Valuation.find_or_create_by(
account_id: account.id,
@ -93,3 +104,14 @@ balances.each do |balance|
balance_record.balance = balance[:balance]
end
end
transactions.each do |transaction|
Transaction.find_or_create_by(
account_id: account.id,
date: transaction[:date],
amount: transaction[:amount]
) do |transaction_record|
transaction_record.currency = transaction[:currency]
transaction_record.name = transaction[:name]
end
end