Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/home page categories #8

Merged
merged 13 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class GroupsController < ApplicationController
before_action { redirect_to splash_index_path unless user_signed_in? }
def index; end
def index
@categories = current_user.groups
end

def show; end

def new; end
end
5 changes: 5 additions & 0 deletions app/models/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ class Entity < ApplicationRecord
validates :name, presence: true
validates :amount, presence: true
validates :author, presence: true
after_save :update_group_transactions_counter

def update_group_transactions_counter
group.update(transactions_counter: group.entities.count)
end
end
4 changes: 4 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class Group < ApplicationRecord
belongs_to :user
has_many :entities
validates :name, presence: true
def initialize(attributes = {})
super
self.transactions_counter = 0
end
end
10 changes: 10 additions & 0 deletions app/views/app/_category_card.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div id="category-card" class="card">
<div class="card-body">
<a href="<%=group_path(category)%>">
<img class="stroke-2" src="<%=category.icon%>">
<h5 class="card-title"><%= category.name %></h5>
<p class="card-text">transactions: <%= category.transactions_counter %></p>
<p class="card-text">Total amount: <%=total_amount%></p>
</a>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<% @categories.each do |category| %>
<% @total_amount = category.entities.sum(:amount) %>
<%= render partial: 'app/category_card', locals: { category: category, total_amount: @total_amount } %>
<% end %>
<%= link_to 'New Group', new_group_path %>
1 change: 1 addition & 0 deletions app/views/groups/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Placeholder for the new group form.
3 changes: 3 additions & 0 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This will display Entiteis for each group
<%# go back button %>
<%= link_to 'Back', groups_path %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
root to: 'groups#index'
resources :users
resources :splash, only: [:index]
resources :entities
resources :groups
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTransactionsCounterToGroups < ActiveRecord::Migration[7.1]
def change
add_column :groups, :transactions_counter, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading