|
|
@ -3,11 +3,20 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do
|
|
|
|
alias DecentralisedBookIndex.Metadata.Author
|
|
|
|
alias DecentralisedBookIndex.Metadata.Author
|
|
|
|
|
|
|
|
|
|
|
|
def from_json(json_body) do
|
|
|
|
def from_json(json_body) do
|
|
|
|
author = %{
|
|
|
|
author =
|
|
|
|
|
|
|
|
if Map.has_key?(json_body, "data") do
|
|
|
|
|
|
|
|
%{
|
|
|
|
id: get_in(json_body, ["data", "id"]),
|
|
|
|
id: get_in(json_body, ["data", "id"]),
|
|
|
|
name: get_in(json_body, ["data", "attributes", "name"]),
|
|
|
|
name: get_in(json_body, ["data", "attributes", "name"]),
|
|
|
|
description: get_in(json_body, ["data", "attributes", "description"]),
|
|
|
|
description: get_in(json_body, ["data", "attributes", "description"]),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
id: get_in(json_body, ["id"]),
|
|
|
|
|
|
|
|
name: get_in(json_body, ["attributes", "name"]),
|
|
|
|
|
|
|
|
description: get_in(json_body, ["attributes", "description"]),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, author}
|
|
|
|
{:ok, author}
|
|
|
|
end
|
|
|
|
end
|
|
|
|