@@ -10,16 +10,13 @@ defmodule DiffoExample.Access.Cable do
1010 """
1111
1212 alias Diffo.Provider.BaseInstance
13- alias Diffo.Provider.Instance.Specification
1413 alias Diffo.Provider.Instance.Relationship
15- alias Diffo.Provider.Instance.Feature
1614 alias Diffo.Provider.Instance.Characteristic
17- alias Diffo.Provider.Instance.Place
18- alias Diffo.Provider.Instance.Party
1915 alias Diffo.Provider.Assigner
2016 alias Diffo.Provider.Assignment
2117
2218 alias DiffoExample.Access
19+ alias DiffoExample.Access.ActionHelper
2320
2421 use Ash.Resource ,
2522 fragments: [ BaseInstance ] ,
@@ -56,25 +53,10 @@ defmodule DiffoExample.Access.Cable do
5653
5754 change set_attribute ( :type , :resource )
5855
59- change before_action ( fn changeset , _context ->
60- changeset
61- |> Specification . set_specified_by_argument ( )
62- |> Feature . set_features_argument ( )
63- |> Characteristic . set_characteristics_argument ( )
64- end )
56+ change before_action ( fn changeset , _context -> ActionHelper . build_before ( changeset ) end )
6557
6658 change after_action ( fn changeset , result , _context ->
67- with { :ok , with_specification } <- Specification . relate_instance ( result , changeset ) ,
68- { :ok , with_relationships } <-
69- Relationship . relate_instance ( with_specification , changeset ) ,
70- { :ok , with_features } <-
71- Feature . relate_instance ( with_relationships , changeset ) ,
72- { :ok , with_characteristics } <-
73- Characteristic . relate_instance ( with_features , changeset ) ,
74- { :ok , with_places } <- Place . relate_instance ( with_characteristics , changeset ) ,
75- { :ok , _with_parties } <- Party . relate_instance ( with_places , changeset ) ,
76- { :ok , cable } <- Access . get_cable_by_id ( result . id ) ,
77- do: { :ok , cable }
59+ ActionHelper . build_after ( changeset , result , :get_cable_by_id )
7860 end )
7961
8062 change load [ :href ]
@@ -86,9 +68,9 @@ defmodule DiffoExample.Access.Cable do
8668 argument :characteristic_value_updates , { :array , :term }
8769
8870 change after_action ( fn changeset , result , _context ->
89- with { :ok , _result } <- Characteristic . update_values ( result , changeset ) ,
90- { :ok , cable } <- Access . get_cable_by_id ( result . id ) ,
91- do: { :ok , cable }
71+ with { :ok , result } <- Characteristic . update_values ( result , changeset ) ,
72+ { :ok , result } <- Access . get_cable_by_id ( result . id ) ,
73+ do: { :ok , result }
9274 end )
9375 end
9476
@@ -97,9 +79,9 @@ defmodule DiffoExample.Access.Cable do
9779 argument :relationships , { :array , :struct }
9880
9981 change after_action ( fn changeset , result , _context ->
100- with { :ok , _cable } <- Relationship . relate_instance ( result , changeset ) ,
101- { :ok , cable } <- Access . get_cable_by_id ( result . id ) ,
102- do: { :ok , cable }
82+ with { :ok , result } <- Relationship . relate_instance ( result , changeset ) ,
83+ { :ok , result } <- Access . get_cable_by_id ( result . id ) ,
84+ do: { :ok , result }
10385 end )
10486 end
10587
@@ -108,9 +90,9 @@ defmodule DiffoExample.Access.Cable do
10890 argument :assignment , :struct , constraints: [ instance_of: Assignment ]
10991
11092 change after_action ( fn changeset , result , _context ->
111- with { :ok , _cable } <- Assigner . assign ( result , changeset , :pairs , :pair ) ,
112- { :ok , cable } <- Access . get_cable_by_id ( result . id ) ,
113- do: { :ok , cable }
93+ with { :ok , result } <- Assigner . assign ( result , changeset , :pairs , :pair ) ,
94+ { :ok , result } <- Access . get_cable_by_id ( result . id ) ,
95+ do: { :ok , result }
11496 end )
11597 end
11698 end
0 commit comments