Update to refactor DataTransformers for Author and Publisher.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
4e8ce20bb0
commit
297821b693
@ -1,22 +1,20 @@
|
||||
defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do
|
||||
def from_json(json_body) do
|
||||
attrs =
|
||||
json_body =
|
||||
if Map.has_key?(json_body, "data") do
|
||||
%{
|
||||
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"]),
|
||||
}
|
||||
json_body["data"]
|
||||
else
|
||||
%{
|
||||
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"]),
|
||||
}
|
||||
json_body
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
@ -1,22 +1,20 @@
|
||||
defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformer do
|
||||
def from_json(json_body) do
|
||||
attrs =
|
||||
json_body =
|
||||
if Map.has_key?(json_body, "data") do
|
||||
%{
|
||||
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"]),
|
||||
}
|
||||
json_body["data"]
|
||||
else
|
||||
%{
|
||||
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"]),
|
||||
}
|
||||
json_body
|
||||
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}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in new issue