-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathingest_controller.ex
More file actions
44 lines (40 loc) · 1.18 KB
/
ingest_controller.ex
File metadata and controls
44 lines (40 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
defmodule BurnWeb.IngestController do
use BurnWeb, :controller
alias Burn.{
Ingest,
Repo,
Threads
}
alias Phoenix.Sync.Writer
alias Writer.Format
def ingest(%{assigns: %{current_user: user}} = conn, %{"mutations" => mutations}) do
{:ok, txid, _changes} =
Writer.new()
|> Writer.allow(
Threads.Event,
accept: [:insert],
check: &Ingest.check_event(&1, user)
)
|> Writer.allow(
Threads.Membership,
accept: [:insert, :delete],
check: &Ingest.check_membership(&1, user),
load: &Ingest.load_membership(&1, user),
insert: [
post_apply: &Ingest.on_insert_membership(&1, &2, &3, user)
]
)
|> Writer.allow(
Threads.Thread,
accept: [:insert, :update],
load: &Ingest.load_thread(&1, user),
insert: [
# N.b.: passing the current `user` as an argument implicitly
# assumes that the current user is the thread owner.
post_apply: &Ingest.on_insert_thread(&1, &2, &3, user)
]
)
|> Writer.apply(mutations, Repo, format: Format.TanstackDB)
json(conn, %{txid: Integer.to_string(txid)})
end
end