diff --git a/Gemfile b/Gemfile index 79573056..31fe41c7 100644 --- a/Gemfile +++ b/Gemfile @@ -107,3 +107,5 @@ gem "image_processing", ">= 1.2" gem "devise-i18n", "~> 1.10" gem "dockerfile-rails", ">= 1.5", group: :development + +gem "noticed", "~> 1.6" diff --git a/Gemfile.lock b/Gemfile.lock index 899b155a..ef1b3d97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,6 +149,7 @@ GEM activerecord (>= 4.2, < 8) dockerfile-rails (1.5.3) rails + domain_name (0.6.20231109) dotenv (2.8.1) dotenv-rails (2.8.1) dotenv (= 2.8.1) @@ -164,6 +165,9 @@ GEM faker (3.0.0) i18n (>= 1.8.11, < 2) ffi (1.15.5) + ffi-compiler (1.0.1) + ffi (>= 1.0.0) + rake formatador (1.1.0) globalid (1.0.1) activesupport (>= 5.0) @@ -181,6 +185,14 @@ GEM guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) + http (5.1.1) + addressable (~> 2.8) + http-cookie (~> 1.0) + http-form_data (~> 2.2) + llhttp-ffi (~> 0.4.0) + http-cookie (1.0.5) + domain_name (~> 0.5) + http-form_data (2.3.0) i18n (1.14.1) concurrent-ruby (~> 1.0) image_processing (1.12.2) @@ -222,6 +234,9 @@ GEM listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) + llhttp-ffi (0.4.0) + ffi-compiler (~> 1.0) + rake (~> 13.0) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -257,6 +272,9 @@ GEM racc (~> 1.4) nokogiri (1.16.0-x86_64-linux) racc (~> 1.4) + noticed (1.6.3) + http (>= 4.0.0) + rails (>= 5.2.0) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) @@ -489,6 +507,7 @@ DEPENDENCIES kaminari (~> 1.2) mobility (~> 1.2) mobility-ransack (~> 1.2.2) + noticed (~> 1.6) pg (~> 1.1) puma (~> 6.4) pundit (~> 2.2) diff --git a/app/models/notification.rb b/app/models/notification.rb new file mode 100644 index 00000000..99cf7cee --- /dev/null +++ b/app/models/notification.rb @@ -0,0 +1,4 @@ +class Notification < ApplicationRecord + include Noticed::Model + belongs_to :recipient, polymorphic: true +end diff --git a/app/models/user.rb b/app/models/user.rb index 81e7e25d..5f3ad8ff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,6 +9,7 @@ class User < ApplicationRecord has_many :discussions, dependent: :destroy has_many :posts, dependent: :destroy has_one :preference, dependent: :destroy + has_many :notifications, as: :recipient, dependent: :destroy # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable diff --git a/db/migrate/20240102141608_create_notifications.rb b/db/migrate/20240102141608_create_notifications.rb new file mode 100644 index 00000000..feacf502 --- /dev/null +++ b/db/migrate/20240102141608_create_notifications.rb @@ -0,0 +1,13 @@ +class CreateNotifications < ActiveRecord::Migration[7.0] + def change + create_table :notifications do |t| + t.references :recipient, polymorphic: true, null: false + t.string :type, null: false + t.jsonb :params + t.datetime :read_at + + t.timestamps + end + add_index :notifications, :read_at + end +end diff --git a/db/schema.rb b/db/schema.rb index e4ed0297..12dc7976 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_06_17_123104) do +ActiveRecord::Schema[7.0].define(version: 2024_01_02_141608) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" enable_extension "plpgsql" @@ -58,6 +58,18 @@ t.index ["user_id"], name: "index_discussions_on_user_id" end + create_table "notifications", force: :cascade do |t| + t.string "recipient_type", null: false + t.bigint "recipient_id", null: false + t.string "type", null: false + t.jsonb "params" + t.datetime "read_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["read_at"], name: "index_notifications_on_read_at" + t.index ["recipient_type", "recipient_id"], name: "index_notifications_on_recipient" + end + create_table "permissions", force: :cascade do |t| t.string "name", null: false t.datetime "created_at", null: false diff --git a/spec/factories/notifications.rb b/spec/factories/notifications.rb new file mode 100644 index 00000000..bf5291a2 --- /dev/null +++ b/spec/factories/notifications.rb @@ -0,0 +1,8 @@ +FactoryBot.define do + factory :notification do + recipient factory: :user + type { "" } + params { "" } + read_at { Time.zone.today } + end +end diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb new file mode 100644 index 00000000..c2a886e5 --- /dev/null +++ b/spec/models/notification_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +RSpec.describe Notification, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end