Skip to content

Commit

Permalink
Edita model Notification
Browse files Browse the repository at this point in the history
-remove coluna read
-adiciona coluna status

Co-authored-by: ana resgalla <[email protected]>
  • Loading branch information
hreis1 and anaresgalla committed Feb 12, 2024
1 parent 5778287 commit 826608b
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class NotificationsController < ApplicationController

def index
@notifications = current_user.profile.notifications.order(created_at: :desc)
@notifications.update_all(read: true)
@notifications.update_all(status: :seen)
end
end
2 changes: 2 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Notification < ApplicationRecord
belongs_to :profile
belongs_to :notifiable, polymorphic: true

enum status: { unseen: 0, seen: 5, clicked: 10 }
end
2 changes: 1 addition & 1 deletion app/views/notifications/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %>
<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> comentou em sua publicação: <%= link_to notification.notifiable.post.title, post_path(notification.notifiable.post) %>
2 changes: 1 addition & 1 deletion app/views/notifications/_connection.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir
<%= link_to notification.notifiable.follower.user.full_name, profile_path(notification.notifiable.follower) %> começou a te seguir
2 changes: 1 addition & 1 deletion app/views/notifications/_invitation.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %>
Você recebeu um convite para <%= link_to notification.notifiable.project_title, invitation_path(notification.notifiable) %>
4 changes: 2 additions & 2 deletions app/views/notifications/_like.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if notification.notifiable.likeable.is_a?Post %>
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação
<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu sua publicação
<% else %>
<p><%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário
<%= link_to notification.notifiable.user.full_name, profile_path(notification.notifiable.user.profile) %> curtiu seu comentário
<% end %>
2 changes: 1 addition & 1 deletion app/views/notifications/_post.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %>
<%= notification.notifiable.user.full_name %> fez uma <%= link_to 'publicação', post_path(notification.notifiable) %>
18 changes: 10 additions & 8 deletions app/views/notifications/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<div class="container d-flex flex-column align-items-center">
<h2>Notificações</h2>
<% if @notifications&.any? %>
<ul class="list-group list-group-flush">
<% @notifications.each do |notification| %>
<div class="list-group">
<%= render(
partial: "#{notification.notifiable.class.name.downcase}" ,
locals: { notification: notification }
)%>
<%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %></p>
</div>
<li class="list-group-item">
<%= render(
partial: "#{notification.notifiable.class.name.downcase}" ,
locals: { notification: notification }
)%>
<%= distance_of_time_in_words_to_now(notification.notifiable.created_at) %>
</li>
<% end %>
</ul>
<% else %>
<p>Nenhuma notificação encontrada</p>
<% end %>
</div>
</div>
9 changes: 6 additions & 3 deletions app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
</li>
<li class="dropdown-item">
<%= link_to notifications_path, class: 'nav-link' do %>
Notificações <span class="badge bg-primary">
<%= current_user.profile.notifications.where(read: false).count if current_user.profile.notifications.where(read: false).count > 0 %>
</span>
Notificações
<% if current_user.profile.notifications.unseen.count > 0 %>
<span class="badge bg-primary">
<%= current_user.profile.notifications.unseen.count %>
</span>
<% end %>
<% end %>
</li>
<% if current_user.admin? %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240212195517_add_status_to_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStatusToNotifications < ActiveRecord::Migration[7.1]
def change
add_column :notifications, :status, :integer, default: 0
end
end
5 changes: 5 additions & 0 deletions db/migrate/20240212195603_remove_read_from_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveReadFromNotifications < ActiveRecord::Migration[7.1]
def change
remove_column :notifications, :read, :boolean
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

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

2 changes: 1 addition & 1 deletion spec/system/notifications/user_sees_notifications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

it 'contagem de notificações muda ao ir para página de notificações' do
user = create(:user)
invitation = create(:invitation, profile: user.profile)
create(:invitation, profile: user.profile)

login_as user
visit notifications_path
Expand Down

0 comments on commit 826608b

Please sign in to comment.