Skip to content

Commit c982cbb

Browse files
Add creator_id to the Notifications model
1 parent 00e07f0 commit c982cbb

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

front/lib/front/models/notification.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule Front.Models.Notification do
5858

5959
def create(user_id, org_id, notification_data, _metadata \\ nil) do
6060
Watchman.benchmark("notifications.create_notification_request.duration", fn ->
61-
notification = construct_notification(notification_data)
61+
notification = construct_notification(notification_data, user_id)
6262

6363
{:ok, channel} = GRPC.Stub.connect(api_endpoint())
6464

@@ -90,7 +90,7 @@ defmodule Front.Models.Notification do
9090

9191
def update(user_id, org_id, notification_data) do
9292
Watchman.benchmark("notifications.update_notification_request.duration", fn ->
93-
notification = construct_notification(notification_data)
93+
notification = construct_notification(notification_data, user_id)
9494

9595
{:ok, channel} = GRPC.Stub.connect(api_endpoint())
9696

@@ -110,13 +110,13 @@ defmodule Front.Models.Notification do
110110
end)
111111
end
112112

113-
def construct_notification(data) do
113+
def construct_notification(data, creator_id) do
114114
rules =
115115
data.rules
116116
|> Enum.map(&construct_rule(&1))
117117

118118
PublicApi.Notification.new(
119-
metadata: PublicApi.Notification.Metadata.new(name: data.name),
119+
metadata: PublicApi.Notification.Metadata.new(name: data.name, creator_id: creator_id),
120120
spec: PublicApi.Notification.Spec.new(rules: rules)
121121
)
122122
end

notifications/lib/notifications/api/internal_api.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ defmodule Notifications.Api.InternalApi do
77
use Sentry.Grpc, service: Api.NotificationsApi.Service
88

99
def list(req, _call) do
10+
IO.puts("LIST INTERNAL")
11+
IO.inspect(req)
1012
Notifications.Api.InternalApi.List.run(req)
1113
end
1214

notifications/lib/notifications/api/internal_api/create.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ defmodule Notifications.Api.InternalApi.Create do
88
alias InternalApi.Notifications.CreateResponse
99

1010
def run(req) do
11-
IO.puts("REQ RUN")
12-
IO.inspect(req.metadata)
13-
IO.inspect(req)
14-
1511
org_id = req.metadata.org_id
1612

1713
with {:ok, :valid} <- Validator.validate(req.notification),
@@ -37,6 +33,7 @@ defmodule Notifications.Api.InternalApi.Create do
3733
Models.Notification.new(
3834
org_id,
3935
notification.name,
36+
notification.creator_id,
4037
Notifications.Util.Transforms.encode_spec(%{rules: notification.rules})
4138
)
4239

notifications/lib/notifications/api/public_api/create.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ defmodule Notifications.Api.PublicApi.Create do
4545
Models.Notification.new(
4646
org_id,
4747
notification.metadata.name,
48+
notification.metadata.creator_id,
4849
Notifications.Util.Transforms.encode_spec(notification.spec)
4950
)
5051

notifications/lib/notifications/models/notification.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ defmodule Notifications.Models.Notification do
1818
timestamps()
1919
end
2020

21-
def new(org_id, name, spec) do
21+
def new(org_id, name, creator_id, spec) do
2222
%__MODULE__{}
2323
|> changeset(%{
2424
org_id: org_id,
25+
creator_id: creator_id,
2526
name: name,
2627
spec: spec
2728
})
@@ -78,8 +79,8 @@ defmodule Notifications.Models.Notification do
7879

7980
def changeset(notification, params \\ %{}) do
8081
notification
81-
|> cast(params, [:org_id, :name, :spec])
82-
|> validate_required([:org_id, :name, :spec])
82+
|> cast(params, [:org_id, :creator_id, :name, :spec])
83+
|> validate_required([:org_id, :creator_id, :name, :spec])
8384
|> valid_name_format(params)
8485
|> unique_constraint(
8586
:unique_names,

0 commit comments

Comments
 (0)