Skip to content

Commit 812cc7b

Browse files
committed
nbn and access on diffo 040
1 parent 56bc977 commit 812cc7b

61 files changed

Lines changed: 679 additions & 455 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ config :spark,
3838
]
3939

4040
config :diffo, ash_domains: [Diffo.Provider]
41-
config :diffo_example, ash_domains: [DiffoExample.Access]
41+
config :diffo_example, ash_domains: [DiffoExample.Access, DiffoExample.Nbn]
4242
import_config "#{config_env()}.exs"

lib/access/resources/cable.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ defmodule DiffoExample.Access.Cable do
7777

7878
change after_action(fn changeset, result, _context ->
7979
with {:ok, result} <- Ash.load(result, [:characteristics]),
80-
{:ok, result} <- Characteristic.update_all(result, changeset, characteristics()),
80+
{:ok, result} <-
81+
Characteristic.update_all(result, changeset, characteristics()),
8182
{:ok, result} <- Pool.update_pools(result, changeset, pools()),
8283
{:ok, result} <- Access.get_cable_by_id(result.id),
8384
do: {:ok, result}

lib/access/resources/card.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ defmodule DiffoExample.Access.Card do
7777

7878
change after_action(fn changeset, result, _context ->
7979
with {:ok, result} <- Ash.load(result, [:characteristics]),
80-
{:ok, result} <- Characteristic.update_all(result, changeset, characteristics()),
80+
{:ok, result} <-
81+
Characteristic.update_all(result, changeset, characteristics()),
8182
{:ok, result} <- Pool.update_pools(result, changeset, pools()),
8283
{:ok, result} <- Access.get_card_by_id(result.id),
8384
do: {:ok, result}

lib/access/resources/characteristic_values/cable_characteristic.ex

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ defmodule DiffoExample.Access.CableCharacteristic do
1515
plural_name :cable_characteristics
1616
end
1717

18-
attributes do
19-
attribute :pairs, :integer, public?: true
20-
attribute :length_amount, :integer, public?: true
21-
attribute :length_unit, :atom, public?: true
22-
attribute :loss_amount, :float, public?: true
23-
attribute :loss_unit, :atom, public?: true
24-
attribute :technology, :atom, public?: true
25-
end
26-
27-
calculations do
28-
calculate :value, Diffo.Type.CharacteristicValue,
29-
DiffoExample.Access.CableCharacteristic.ValueCalculation do
30-
public? true
31-
end
32-
end
33-
3418
actions do
3519
create :create do
3620
accept [:name, :pairs, :length_amount, :length_unit, :loss_amount, :loss_unit, :technology]
@@ -53,6 +37,23 @@ defmodule DiffoExample.Access.CableCharacteristic do
5337
end
5438
end
5539

40+
attributes do
41+
attribute :pairs, :integer, public?: true
42+
attribute :length_amount, :integer, public?: true
43+
attribute :length_unit, :atom, public?: true
44+
attribute :loss_amount, :float, public?: true
45+
attribute :loss_unit, :atom, public?: true
46+
attribute :technology, :atom, public?: true
47+
end
48+
49+
calculations do
50+
calculate :value,
51+
Diffo.Type.CharacteristicValue,
52+
DiffoExample.Access.CableCharacteristic.ValueCalculation do
53+
public? true
54+
end
55+
end
56+
5657
preparations do
5758
prepare build(load: [:value])
5859
end
@@ -70,20 +71,20 @@ defmodule DiffoExample.Access.CableCharacteristic.Value do
7071
alias DiffoExample.Access.IntegerUnit
7172
alias DiffoExample.Access.FloatUnit
7273

73-
typed_struct do
74-
field :pairs, :integer
75-
field :length, IntegerUnit
76-
field :loss, FloatUnit
77-
field :technology, :atom
74+
jason do
75+
pick [:pairs, :length, :loss, :technology]
76+
compact true
7877
end
7978

8079
outstanding do
8180
expect [:pairs, :loss]
8281
end
8382

84-
jason do
85-
pick [:pairs, :length, :loss, :technology]
86-
compact true
83+
typed_struct do
84+
field :pairs, :integer
85+
field :length, IntegerUnit
86+
field :loss, FloatUnit
87+
field :technology, :atom
8788
end
8889
end
8990

lib/access/resources/characteristic_values/card_characteristic.ex

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ defmodule DiffoExample.Access.CardCharacteristic do
1313
plural_name :card_characteristics
1414
end
1515

16-
attributes do
17-
attribute :family, :atom, public?: true
18-
attribute :model, :string, public?: true
19-
attribute :technology, :atom, public?: true
20-
end
21-
22-
calculations do
23-
calculate :value, Diffo.Type.CharacteristicValue,
24-
Diffo.Provider.Calculations.CharacteristicValue do
25-
public? true
26-
end
27-
end
28-
2916
actions do
3017
create :create do
3118
accept [:name, :family, :model, :technology]
@@ -40,6 +27,20 @@ defmodule DiffoExample.Access.CardCharacteristic do
4027
end
4128
end
4229

30+
attributes do
31+
attribute :family, :atom, public?: true
32+
attribute :model, :string, public?: true
33+
attribute :technology, :atom, public?: true
34+
end
35+
36+
calculations do
37+
calculate :value,
38+
Diffo.Type.CharacteristicValue,
39+
Diffo.Provider.Calculations.CharacteristicValue do
40+
public? true
41+
end
42+
end
43+
4344
preparations do
4445
prepare build(load: [:value])
4546
end
@@ -54,14 +55,14 @@ defmodule DiffoExample.Access.CardCharacteristic.Value do
5455
@moduledoc false
5556
use Ash.TypedStruct, extensions: [AshJason.TypedStruct]
5657

58+
jason do
59+
pick [:family, :model, :technology]
60+
compact true
61+
end
62+
5763
typed_struct do
5864
field :family, :atom
5965
field :model, :string
6066
field :technology, :atom
6167
end
62-
63-
jason do
64-
pick [:family, :model, :technology]
65-
compact true
66-
end
6768
end

lib/access/resources/characteristic_values/path_characteristic.ex

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,36 @@ defmodule DiffoExample.Access.PathCharacteristic do
1515
plural_name :path_characteristics
1616
end
1717

18-
attributes do
19-
attribute :device_name, :string, public?: true
20-
attribute :sections, :integer, public?: true
21-
attribute :length_amount, :integer, public?: true
22-
attribute :length_unit, :atom, public?: true
23-
attribute :loss_amount, :float, public?: true
24-
attribute :loss_unit, :atom, public?: true
25-
attribute :technology, :atom, public?: true
26-
end
27-
28-
calculations do
29-
calculate :value, Diffo.Type.CharacteristicValue,
30-
DiffoExample.Access.PathCharacteristic.ValueCalculation do
31-
public? true
32-
end
33-
end
34-
3518
actions do
3619
create :create do
37-
accept [:name, :device_name, :sections, :length_amount, :length_unit, :loss_amount, :loss_unit, :technology]
20+
accept [
21+
:name,
22+
:device_name,
23+
:sections,
24+
:length_amount,
25+
:length_unit,
26+
:loss_amount,
27+
:loss_unit,
28+
:technology
29+
]
30+
3831
argument :instance_id, :uuid
3932
argument :feature_id, :uuid
4033
change manage_relationship(:instance_id, :instance, type: :append)
4134
change manage_relationship(:feature_id, :feature, type: :append)
4235
end
4336

4437
update :update do
45-
accept [:device_name, :sections, :technology, :length_amount, :length_unit, :loss_amount, :loss_unit]
38+
accept [
39+
:device_name,
40+
:sections,
41+
:technology,
42+
:length_amount,
43+
:length_unit,
44+
:loss_amount,
45+
:loss_unit
46+
]
47+
4648
argument :length, :term, allow_nil?: true
4749
argument :loss, :term, allow_nil?: true
4850

@@ -54,6 +56,24 @@ defmodule DiffoExample.Access.PathCharacteristic do
5456
end
5557
end
5658

59+
attributes do
60+
attribute :device_name, :string, public?: true
61+
attribute :sections, :integer, public?: true
62+
attribute :length_amount, :integer, public?: true
63+
attribute :length_unit, :atom, public?: true
64+
attribute :loss_amount, :float, public?: true
65+
attribute :loss_unit, :atom, public?: true
66+
attribute :technology, :atom, public?: true
67+
end
68+
69+
calculations do
70+
calculate :value,
71+
Diffo.Type.CharacteristicValue,
72+
DiffoExample.Access.PathCharacteristic.ValueCalculation do
73+
public? true
74+
end
75+
end
76+
5777
preparations do
5878
prepare build(load: [:value])
5979
end
@@ -71,22 +91,22 @@ defmodule DiffoExample.Access.PathCharacteristic.Value do
7191
alias DiffoExample.Access.IntegerUnit
7292
alias DiffoExample.Access.FloatUnit
7393

74-
typed_struct do
75-
field :device_name, :string
76-
field :sections, :integer
77-
field :length, IntegerUnit
78-
field :loss, FloatUnit
79-
field :technology, :atom
94+
jason do
95+
pick [:device_name, :sections, :length, :loss, :technology]
96+
compact true
97+
rename device_name: "name"
8098
end
8199

82100
outstanding do
83101
expect [:loss]
84102
end
85103

86-
jason do
87-
pick [:device_name, :sections, :length, :loss, :technology]
88-
compact true
89-
rename device_name: "name"
104+
typed_struct do
105+
field :device_name, :string
106+
field :sections, :integer
107+
field :length, IntegerUnit
108+
field :loss, FloatUnit
109+
field :technology, :atom
90110
end
91111
end
92112

lib/access/resources/characteristic_values/shelf_characteristic.ex

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ defmodule DiffoExample.Access.ShelfCharacteristic do
1313
plural_name :shelf_characteristics
1414
end
1515

16-
attributes do
17-
attribute :device_name, :string, public?: true
18-
attribute :family, :atom, public?: true
19-
attribute :model, :string, public?: true
20-
attribute :technology, :atom, public?: true
21-
end
22-
23-
calculations do
24-
calculate :value, Diffo.Type.CharacteristicValue,
25-
Diffo.Provider.Calculations.CharacteristicValue do
26-
public? true
27-
end
28-
end
29-
3016
actions do
3117
create :create do
3218
accept [:name, :device_name, :family, :model, :technology]
@@ -41,6 +27,21 @@ defmodule DiffoExample.Access.ShelfCharacteristic do
4127
end
4228
end
4329

30+
attributes do
31+
attribute :device_name, :string, public?: true
32+
attribute :family, :atom, public?: true
33+
attribute :model, :string, public?: true
34+
attribute :technology, :atom, public?: true
35+
end
36+
37+
calculations do
38+
calculate :value,
39+
Diffo.Type.CharacteristicValue,
40+
Diffo.Provider.Calculations.CharacteristicValue do
41+
public? true
42+
end
43+
end
44+
4445
preparations do
4546
prepare build(load: [:value])
4647
end
@@ -55,16 +56,16 @@ defmodule DiffoExample.Access.ShelfCharacteristic.Value do
5556
@moduledoc false
5657
use Ash.TypedStruct, extensions: [AshJason.TypedStruct]
5758

59+
jason do
60+
pick [:device_name, :family, :model, :technology]
61+
compact true
62+
rename device_name: "name"
63+
end
64+
5865
typed_struct do
5966
field :device_name, :string
6067
field :family, :atom
6168
field :model, :string
6269
field :technology, :atom
6370
end
64-
65-
jason do
66-
pick [:device_name, :family, :model, :technology]
67-
compact true
68-
rename device_name: "name"
69-
end
7071
end

lib/access/resources/path.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ defmodule DiffoExample.Access.Path do
6868

6969
change after_action(fn changeset, result, _context ->
7070
with {:ok, result} <- Ash.load(result, [:characteristics]),
71-
{:ok, result} <- Characteristic.update_all(result, changeset, characteristics()),
71+
{:ok, result} <-
72+
Characteristic.update_all(result, changeset, characteristics()),
7273
{:ok, result} <- Access.get_path_by_id(result.id),
7374
do: {:ok, result}
7475
end)

lib/access/resources/shelf.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ defmodule DiffoExample.Access.Shelf do
7777

7878
change after_action(fn changeset, result, _context ->
7979
with {:ok, result} <- Ash.load(result, [:characteristics]),
80-
{:ok, result} <- Characteristic.update_all(result, changeset, characteristics()),
80+
{:ok, result} <-
81+
Characteristic.update_all(result, changeset, characteristics()),
8182
{:ok, result} <- Pool.update_pools(result, changeset, pools()),
8283
{:ok, result} <- Access.get_shelf_by_id(result.id),
8384
do: {:ok, result}

0 commit comments

Comments
 (0)