Update to refactor DataTransformers for Author and Publisher.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user