Update to refactor DataTransformers for Author and Publisher.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 3 months ago
parent 4e8ce20bb0
commit 297821b693

@ -1,22 +1,20 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do
def from_json(json_body) do def from_json(json_body) do
attrs = json_body =
if Map.has_key?(json_body, "data") do if Map.has_key?(json_body, "data") do
%{ json_body["data"]
id: get_in(json_body, ["data", "id"]),
name: get_in(json_body, ["data", "attributes", "name"]),
description: get_in(json_body, ["data", "attributes", "description"]),
avatar_url: get_in(json_body, ["data", "attributes", "avatar_url"]),
}
else else
%{ json_body
id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]),
description: get_in(json_body, ["attributes", "description"]),
avatar_url: get_in(json_body, ["attributes", "avatar_url"]),
}
end end
attrs =
%{
id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]),
description: get_in(json_body, ["attributes", "description"]),
avatar_url: get_in(json_body, ["attributes", "avatar_url"])
}
{:ok, attrs} {:ok, attrs}
end end
end end

@ -1,22 +1,20 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformer do defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformer do
def from_json(json_body) do def from_json(json_body) do
attrs = json_body =
if Map.has_key?(json_body, "data") do if Map.has_key?(json_body, "data") do
%{ json_body["data"]
id: get_in(json_body, ["data", "id"]),
name: get_in(json_body, ["data", "attributes", "name"]),
inserted_at: get_in(json_body, ["data", "attributes", "inserted_at"]),
updated_at: get_in(json_body, ["data", "attributes", "updated_at"]),
}
else else
%{ json_body
id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]),
inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"]),
}
end end
attrs =
%{
id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]),
inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"])
}
{:ok, attrs} {:ok, attrs}
end end
end end

Loading…
Cancel
Save