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 2fe25485..38364f96 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: 5.seconds).perform_later(@job)
helpers.audit_accept_lend(@item)
end
end
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/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 @@
+
+
+
+
+
" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+
+
+
+
+
+ <%= notification.description %>
+
+
+
+
+
+
+
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"
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/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/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"
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