From c3512b713745273fdbe4017d0e7d8c55bf276244 Mon Sep 17 00:00:00 2001 From: Till-B Date: Tue, 24 Jan 2023 16:40:10 +0100 Subject: [PATCH 1/4] create PickupReminder Notification --- app/controllers/notifications_controller.rb | 2 +- .../_pickup_reminder_notification.html.erb | 34 +++++++++++++++++++ config/locales/en.yml | 3 ++ db/schema.rb | 10 +++++- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/views/notifications/_pickup_reminder_notification.html.erb diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 2fe25485..03bbf3b3 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -65,10 +65,10 @@ def accept_item @job = Job.create @job.item = @item @job.save - ReminderNotificationJob.set(wait: 4.days).perform_later(@job) @item.set_rental_start_time @item.update(holder: @notification.borrower.id) @item.save + ReminderNotificationJob.set(wait: 2.days).perform_later(@job) helpers.audit_accept_lend(@item) end end diff --git a/app/views/notifications/_pickup_reminder_notification.html.erb b/app/views/notifications/_pickup_reminder_notification.html.erb new file mode 100644 index 00000000..9ee50d35 --- /dev/null +++ b/app/views/notifications/_pickup_reminder_notification.html.erb @@ -0,0 +1,34 @@ + + + + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index d4eab79c..ab2c58c8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -123,6 +123,9 @@ en: removed_from_group: title: "Removed from group" description: "You have been removed from the group \"%{group_name}\"." + pickupreminder: + title: "Pickup Reminder" + description: "You have lend %{item}. Please pick it up soon." no_notifications: "You have not received any notifications yet" search: title: "Search" diff --git a/db/schema.rb b/db/schema.rb index c1dfdec2..8957cf6b 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_01_21_122621) do +ActiveRecord::Schema[7.0].define(version: 2023_01_24_150601) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false @@ -160,6 +160,13 @@ t.index ["user_or_group_type", "user_or_group_id"], name: "index_permissions_on_user_or_group" end + create_table "pickup_reminder_notifications", force: :cascade do |t| + t.integer "item_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["item_id"], name: "index_pickup_reminder_notifications_on_item_id" + end + create_table "removed_from_group_notifications", force: :cascade do |t| t.string "group_name" t.datetime "created_at", null: false @@ -233,6 +240,7 @@ add_foreign_key "move_up_on_waitlist_notifications", "items" add_foreign_key "notifications", "users", column: "receiver_id" add_foreign_key "permissions", "items" + add_foreign_key "pickup_reminder_notifications", "items" add_foreign_key "return_accepted_notifications", "items" add_foreign_key "return_accepted_notifications", "users", column: "owner_id" add_foreign_key "return_declined_notifications", "users", column: "owner_id" From 998c52ec72099fbb9ba21bb91348ce971303e3f6 Mon Sep 17 00:00:00 2001 From: Till-B Date: Tue, 24 Jan 2023 16:40:59 +0100 Subject: [PATCH 2/4] create PickupReminder Notification --- config/locales/de.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/locales/de.yml b/config/locales/de.yml index e4b0eeee..17fcd449 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -92,6 +92,9 @@ de: removed_from_group: title: "Aus Gruppe entfernt" description: "Du wurdest aus der Gruppe \"%{group_name}\" entfernt." + pickupreminder: + title: "Abholungserinnerung" + description: "Du hast %{item} ausgeliehen. Bitte hole es bald ab." no_notifications: "Du hast noch keine Nachrichten erhalten" search: title: "Suche" From 53ec8db4383587076f98ef38b76157534fc298d4 Mon Sep 17 00:00:00 2001 From: Till-B Date: Tue, 24 Jan 2023 16:43:52 +0100 Subject: [PATCH 3/4] unversioned files which were forgotten in the lase commit --- app/models/item.rb | 1 + app/models/pickup_reminder_notification.rb | 14 ++++++++++++++ ...4150601_create_pickup_reminder_notifications.rb | 9 +++++++++ spec/factories/pickup_reminder_notifications.rb | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 app/models/pickup_reminder_notification.rb create mode 100644 db/migrate/20230124150601_create_pickup_reminder_notifications.rb create mode 100644 spec/factories/pickup_reminder_notifications.rb diff --git a/app/models/item.rb b/app/models/item.rb index 3cb22bc4..bcb819f7 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -139,6 +139,7 @@ def status_pending_pickup? def perform_pickup_check return unless status_pending_pickup? + PickupReminderNotification.create(item: self, receiver: holder, date: Time.zone.now, unread: true, active: true) job = Job.find_by(item: self) job.destroy reset_status diff --git a/app/models/pickup_reminder_notification.rb b/app/models/pickup_reminder_notification.rb new file mode 100644 index 00000000..e082faed --- /dev/null +++ b/app/models/pickup_reminder_notification.rb @@ -0,0 +1,14 @@ +class PickupReminderNotification < ApplicationRecord + acts_as :notification + + belongs_to :item + + def title + I18n.t "views.notifications.pickupreminder.title" + end + + def description + I18n.t "views.notifications.pickupreminder.description", item: item.name + end +end + diff --git a/db/migrate/20230124150601_create_pickup_reminder_notifications.rb b/db/migrate/20230124150601_create_pickup_reminder_notifications.rb new file mode 100644 index 00000000..0bca0978 --- /dev/null +++ b/db/migrate/20230124150601_create_pickup_reminder_notifications.rb @@ -0,0 +1,9 @@ +class CreatePickupReminderNotifications < ActiveRecord::Migration[7.0] + def change + create_table :pickup_reminder_notifications do |t| + t.references :item, null: false, foreign_key: true + + t.timestamps + end + end +end diff --git a/spec/factories/pickup_reminder_notifications.rb b/spec/factories/pickup_reminder_notifications.rb new file mode 100644 index 00000000..2d328856 --- /dev/null +++ b/spec/factories/pickup_reminder_notifications.rb @@ -0,0 +1,6 @@ +FactoryBot.define do + factory :pickup_reminder_notification do + item { "MyString" } + references { "MyString" } + end +end From ce0b47811d4064545b9a1402797186103e40972d Mon Sep 17 00:00:00 2001 From: Jan Fehse Date: Mon, 30 Jan 2023 16:21:14 +0100 Subject: [PATCH 4/4] Added sidekiq for job system have to do more work and research --- Gemfile | 3 +++ Gemfile.lock | 17 +++++++++++++---- app/controllers/notifications_controller.rb | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index d2fba112..4b3432ff 100644 --- a/Gemfile +++ b/Gemfile @@ -53,6 +53,9 @@ gem "sassc-rails" # we should be able to remove this after upgrading to Ruby 3 gem 'net-http' +# Adding gem for Job queueing +gem 'sidekiq' + # Use devise as an authentication solution [https://github.com/plataformatec/devise] gem "devise", github: "heartcombo/devise", ref: "f8d1ea90bc3" # https://steve-condylios.medium.com/how-to-set-up-devise-for-rails-7-466619f6d627 gem "devise-i18n" # https://github.com/tigrish/devise-i18n diff --git a/Gemfile.lock b/Gemfile.lock index 2dbb036b..f269f01a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,6 +111,7 @@ GEM childprocess (4.1.0) chunky_png (1.4.0) concurrent-ruby (1.1.10) + connection_pool (2.3.0) crass (1.0.6) debug (1.6.3) irb (>= 1.3.6) @@ -151,16 +152,16 @@ GEM actionview (>= 5.0.0) activesupport (>= 5.0.0) json (2.6.2) - launchy (2.5.0) - addressable (~> 2.7) - letter_opener (1.8.1) - launchy (>= 2.2, < 3) json-jwt (1.16.1) activesupport (>= 4.2) aes_key_wrap bindata faraday (~> 2.0) faraday-follow_redirects + launchy (2.5.0) + addressable (~> 2.7) + letter_opener (1.8.1) + launchy (>= 2.2, < 3) loofah (2.19.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -261,6 +262,8 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) + redis-client (0.12.1) + connection_pool regexp_parser (2.6.0) reline (0.3.1) io-console (~> 0.5) @@ -330,6 +333,11 @@ GEM websocket (~> 1.0) shoulda-matchers (5.2.0) activesupport (>= 5.2.0) + sidekiq (7.0.3) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + rack (>= 2.2.4) + redis-client (>= 0.11.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -425,6 +433,7 @@ DEPENDENCIES sassc-rails selenium-webdriver shoulda-matchers (~> 5.0) + sidekiq simplecov sprockets-rails sqlite3 (~> 1.4) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 03bbf3b3..38364f96 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -68,7 +68,7 @@ def accept_item @item.set_rental_start_time @item.update(holder: @notification.borrower.id) @item.save - ReminderNotificationJob.set(wait: 2.days).perform_later(@job) + ReminderNotificationJob.set(wait: 5.seconds).perform_later(@job) helpers.audit_accept_lend(@item) end end