1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00

Scaffold out rules domain

This commit is contained in:
Zach Gollwitzer 2025-02-25 11:34:37 -05:00
parent b2d8da8857
commit f12fc1efd7
16 changed files with 129 additions and 28 deletions

View file

@ -0,0 +1,27 @@
class Rule::ActionsController < ApplicationController
before_action :set_rule
before_action :set_action, only: [ :update, :destroy ]
def create
end
def update
end
def destroy
end
private
def set_rule
@rule = Current.family.rules.find(params[:rule_id])
end
def set_action
@action = @rule.actions.find(params[:id])
end
def action_params
params.require(:action).permit(:action_type)
end
end

View file

@ -0,0 +1,27 @@
class Rule::TriggersController < ApplicationController
before_action :set_rule
before_action :set_trigger, only: [ :update, :destroy ]
def create
end
def update
end
def destroy
end
private
def set_rule
@rule = Current.family.rules.find(params[:rule_id])
end
def set_trigger
@trigger = @rule.triggers.find(params[:id])
end
def trigger_params
params.require(:trigger).permit(:trigger_type)
end
end

View file

View file

@ -0,0 +1,36 @@
class RulesController < ApplicationController
before_action :set_rule, only: [ :show, :edit, :update, :destroy ]
def index
@rules = Current.family.rules
render layout: "settings"
end
def show
end
def new
end
def create
end
def edit
end
def update
end
def destroy
end
private
def set_rule
@rule = Current.family.rules.find(params[:id])
end
def rule_params
params.require(:rule).permit(:effective_date, :active)
end
end

View file

@ -9,6 +9,7 @@ module SettingsHelper
{ name: I18n.t("settings.settings_nav.imports_label"), path: :imports_path },
{ name: I18n.t("settings.settings_nav.tags_label"), path: :tags_path },
{ name: I18n.t("settings.settings_nav.categories_label"), path: :categories_path },
{ name: "Rules", path: :rules_path },
{ name: I18n.t("settings.settings_nav.merchants_label"), path: :merchants_path },
{ name: I18n.t("settings.settings_nav.whats_new_label"), path: :changelog_path },
{ name: I18n.t("settings.settings_nav.feedback_label"), path: :feedback_path }

7
app/models/rule.rb Normal file
View file

@ -0,0 +1,7 @@
class Rule < ApplicationRecord
belongs_to :family
has_many :triggers, dependent: :destroy
has_many :actions, dependent: :destroy
validates :effective_date, presence: true
end

View file

@ -0,0 +1,5 @@
class Rule::Action < ApplicationRecord
belongs_to :rule
validates :action_type, presence: true
end

View file

@ -0,0 +1,7 @@
class Rule::Trigger < ApplicationRecord
self.table_name = "rule_triggers"
belongs_to :rule
validates :trigger_type, presence: true
end

View file

@ -0,0 +1,2 @@
<p>Placeholder: rules/_form partial</p>

View file

@ -0,0 +1,2 @@
<p>Placeholder: rules#edit</p>

View file

@ -0,0 +1,3 @@
<% content_for :page_title, "Rules" %>
<p>Placeholder: rules#index</p>

View file

@ -0,0 +1,2 @@
<p>Placeholder: rules#new</p>

View file

@ -0,0 +1,2 @@
<p>Placeholder: rules#show</p>

View file

@ -60,6 +60,9 @@
<li>
<%= render "settings/settings_nav_item", name: t(".categories_label"), path: categories_path, icon: "shapes" %>
</li>
<li>
<%= render "settings/settings_nav_item", name: "Rules", path: rules_path, icon: "git-branch" %>
</li>
<li>
<%= render "settings/settings_nav_item", name: t(".merchants_label"), path: merchants_path, icon: "store" %>
</li>

View file

@ -143,6 +143,11 @@ Rails.application.routes.draw do
end
end
resources :rules do
resources :triggers, only: %i[create update destroy]
resources :actions, only: %i[create update destroy]
end
# Convenience routes for polymorphic paths
# Example: account_path(Account.new(accountable: Depository.new)) => /depositories/123
direct :account do |model, options|

28
db/schema.rb generated
View file

@ -468,31 +468,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_03_19_212839) do
t.index ["outflow_transaction_id"], name: "index_rejected_transfers_on_outflow_transaction_id"
end
create_table "rule_actions", force: :cascade do |t|
t.uuid "rule_id", null: false
t.string "action_type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["rule_id"], name: "index_rule_actions_on_rule_id"
end
create_table "rule_triggers", force: :cascade do |t|
t.uuid "rule_id", null: false
t.string "trigger_type", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["rule_id"], name: "index_rule_triggers_on_rule_id"
end
create_table "rules", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "family_id", null: false
t.date "effective_date", null: false
t.boolean "active", default: true, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["family_id"], name: "index_rules_on_family_id"
end
create_table "securities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "ticker", null: false
t.string "name"
@ -686,9 +661,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_03_19_212839) do
add_foreign_key "plaid_items", "families"
add_foreign_key "rejected_transfers", "account_transactions", column: "inflow_transaction_id"
add_foreign_key "rejected_transfers", "account_transactions", column: "outflow_transaction_id"
add_foreign_key "rule_actions", "rules"
add_foreign_key "rule_triggers", "rules"
add_foreign_key "rules", "families"
add_foreign_key "security_prices", "securities"
add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id"
add_foreign_key "sessions", "users"