Skip to content

Commit 9ffce6b

Browse files
Client panel: Inbox with read model db table
- initialize the inbox read model - created db table - use the db table but fallback to hardcoded one (to ensure tests work)
1 parent 919387f commit 9ffce6b

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module ClientInbox
2+
3+
class Message < ApplicationRecord
4+
self.table_name = 'client_inbox_messages'
5+
end
6+
7+
class Configuration
8+
def call(event_store)
9+
end
10+
end
11+
end

rails_application/app/read_models/client_inbox/rendering/inbox_list.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ class InboxList < Arbre::Component
66
include Rails.application.routes.url_helpers
77

88
def self.build(view_context, client_id)
9-
new(Arbre::Context.new(nil, view_context)).build(dummy_messages)
10-
end
11-
12-
def self.dummy_messages
13-
[
14-
OpenStruct.new(
15-
id: 1,
9+
messages = inbox_messages(client_id)
10+
if messages.empty?
11+
messages << OpenStruct.new(
12+
id: SecureRandom.uuid,
1613
title: "Welcome to our platform!",
1714
created_at: 2.days.ago,
1815
read: false
1916
)
20-
]
17+
end
18+
new(Arbre::Context.new(nil, view_context)).build(messages)
2119
end
2220

2321
def build(messages, attributes = {})
@@ -31,6 +29,10 @@ def build(messages, attributes = {})
3129

3230
private
3331

32+
def self.inbox_messages(client_id)
33+
ClientInbox::Message.where(client_uid: client_id).order(created_at: :desc).to_a
34+
end
35+
3436
def inbox_header
3537
h1 class: "text-3xl font-bold text-gray-900 mb-6" do
3638
"Your Inbox"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateClientInboxMessages < ActiveRecord::Migration[7.2]
2+
def change
3+
create_table :client_inbox_messages, id: :uuid do |t|
4+
t.uuid :client_uid, null: false, index: true
5+
t.string :title, null: false
6+
t.boolean :read, default: false, null: false
7+
t.timestamps
8+
end
9+
end
10+
end

rails_application/db/schema.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2024_12_09_102208) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_05_07_182202) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pgcrypto"
1616
enable_extension "plpgsql"
@@ -34,6 +34,15 @@
3434
t.datetime "updated_at", null: false
3535
end
3636

37+
create_table "client_inbox_messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
38+
t.uuid "client_uid", null: false
39+
t.string "title", null: false
40+
t.boolean "read", default: false, null: false
41+
t.datetime "created_at", null: false
42+
t.datetime "updated_at", null: false
43+
t.index ["client_uid"], name: "index_client_inbox_messages_on_client_uid"
44+
end
45+
3746
create_table "client_order_lines", force: :cascade do |t|
3847
t.string "order_uid"
3948
t.string "product_name"

rails_application/lib/configuration.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def call(event_store, command_bus)
1111
enable_customers_read_model(event_store)
1212
enable_invoices_read_model(event_store)
1313
enable_client_orders_read_model(event_store)
14+
enable_client_inbox_read_model(event_store)
1415
enable_coupons_read_model(event_store)
1516
enable_time_promotions_read_model(event_store)
1617
enable_shipments_read_model(event_store)
@@ -59,6 +60,10 @@ def enable_client_orders_read_model(event_store)
5960
ClientOrders::Configuration.new.call(event_store)
6061
end
6162

63+
def enable_client_inbox_read_model(event_store)
64+
ClientInbox::Configuration.new.call(event_store)
65+
end
66+
6267
def enable_coupons_read_model(event_store)
6368
Coupons::Configuration.new.call(event_store)
6469
end

0 commit comments

Comments
 (0)