Add transformers for AuthorRole.

This commit is contained in:
2025-04-07 21:51:35 +03:00
parent 4d48795ccd
commit b64aa37c4f
4 changed files with 162 additions and 0 deletions
@@ -0,0 +1,20 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorRoleTransformer do
def from_json(json_body) do
json_body =
if Map.has_key?(json_body, "data") do
json_body["data"]
else
json_body
end
attrs =
%{
id: get_in(json_body, ["id"]),
order: get_in(json_body, ["attributes", "order"]),
role: get_in(json_body, ["attributes", "role"]),
author_id: get_in(json_body, ["attributes", "author_id"])
}
{:ok, attrs}
end
end
@@ -0,0 +1,21 @@
defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorRolesTransformer do
alias DecentralisedBookIndex.Sync.DataTransformers.AuthorRoleTransformer
def from_json(json_body) do
json_body =
if Map.has_key?(json_body, "data") do
json_body["data"]
else
json_body
end
{:ok,
Enum.map(
json_body,
fn record ->
{:ok, record} = AuthorRoleTransformer.from_json(record)
record
end
)}
end
end