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,21 +1,19 @@
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
end
attrs =
%{ %{
id: get_in(json_body, ["id"]), id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]), name: get_in(json_body, ["attributes", "name"]),
description: get_in(json_body, ["attributes", "description"]), description: get_in(json_body, ["attributes", "description"]),
avatar_url: get_in(json_body, ["attributes", "avatar_url"]), avatar_url: get_in(json_body, ["attributes", "avatar_url"])
} }
end
{:ok, attrs} {:ok, attrs}
end end

@ -1,21 +1,19 @@
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
end
attrs =
%{ %{
id: get_in(json_body, ["id"]), id: get_in(json_body, ["id"]),
name: get_in(json_body, ["attributes", "name"]), name: get_in(json_body, ["attributes", "name"]),
inserted_at: get_in(json_body, ["attributes", "inserted_at"]), inserted_at: get_in(json_body, ["attributes", "inserted_at"]),
updated_at: get_in(json_body, ["attributes", "updated_at"]), updated_at: get_in(json_body, ["attributes", "updated_at"])
} }
end
{:ok, attrs} {:ok, attrs}
end end

Loading…
Cancel
Save