Add the task to sync authors from the API.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
da0e5246c7
commit
f01a5eda1b
@ -0,0 +1,25 @@
|
|||||||
|
defmodule DecentralisedBookIndex.SyncTasks.SyncAuthorsTask do
|
||||||
|
alias DecentralisedBookIndex.Sync.ApiClients.FetchJsons
|
||||||
|
alias DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer
|
||||||
|
alias DecentralisedBookIndex.Sync.AuthorSync
|
||||||
|
|
||||||
|
def sync(endpoint) do
|
||||||
|
url = "#{endpoint}/api/v1/json/author"
|
||||||
|
FetchJsons.get(url, &sync_author_chunk/1)
|
||||||
|
endpoint
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_author_chunk(json_chunk) do
|
||||||
|
for json <- json_chunk do
|
||||||
|
with {:ok, attrs} <- AuthorTransformer.from_json(json),
|
||||||
|
:ok <- AuthorSync.create_update(attrs) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
{:error, reason} ->
|
||||||
|
Logger.error("Pipeline error: #{inspect(reason)}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,20 @@
|
|||||||
|
defmodule DecentralisedBookIndex.SyncTasks.SyncAuthorsTaskTest do
|
||||||
|
use DecentralisedBookIndex.DataCase
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.SyncTasks.SyncAuthorsTask
|
||||||
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
|
||||||
|
alias DecentralisedBookIndex.TestEndpoints
|
||||||
|
@test_server_endpoint TestEndpoints.test_api_endpoint()
|
||||||
|
|
||||||
|
describe "sync authors tasks" do
|
||||||
|
test "sync authors" do
|
||||||
|
{:ok, author} = Metadata.create_author("Author", "An description")
|
||||||
|
{:ok, author} = Metadata.create_author("Author2", "An description")
|
||||||
|
|
||||||
|
endpoint = @test_server_endpoint
|
||||||
|
|
||||||
|
assert endpoint = SyncAuthorsTask.sync(endpoint)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue