Add transformers for BookId.
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-04-07 22:02:52 +03:00
parent b64aa37c4f
commit d1a44a5457
4 changed files with 146 additions and 0 deletions
@@ -0,0 +1,20 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.BidTransformer do
def from_json(json_body) do
json_body =
if Map.has_key?(json_body, "data") do
json_body["data"]
else
json_body
end
attrs =
%{
id: get_in(json_body, ["id"]),
order: get_in(json_body, ["attributes", "order"]),
type: get_in(json_body, ["attributes", "type"]),
bid: get_in(json_body, ["attributes", "bid"])
}
{:ok, attrs}
end
end
@@ -0,0 +1,21 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.BidsTransformer do
alias DecentralisedBookIndex.Sync.DataTransformers.BidTransformer
def from_json(json_body) do
json_body =
if Map.has_key?(json_body, "data") do
json_body["data"]
else
json_body
end
{:ok,
Enum.map(
json_body,
fn record ->
{:ok, record} = BidTransformer.from_json(record)
record
end
)}
end
end