parent
bbe5de8cb2
commit
1a326cc8aa
@ -0,0 +1,31 @@
|
|||||||
|
defmodule DecentralisedBookIndex.Sync.AuthorAliasRegistrySync do
|
||||||
|
alias DecentralisedBookIndex.Metadata
|
||||||
|
alias DecentralisedBookIndex.Metadata.AuthorAliasRegistry
|
||||||
|
|
||||||
|
def create_update(attrs, server_id) do
|
||||||
|
case Metadata.get_author_alias_registry_by_id(attrs.id) do
|
||||||
|
{:ok, author} ->
|
||||||
|
attrs =
|
||||||
|
attrs
|
||||||
|
|> Map.delete(:id)
|
||||||
|
|> Map.put(:dbi_server_id, server_id)
|
||||||
|
|
||||||
|
author
|
||||||
|
|> Ash.Changeset.for_update(:sync, attrs)
|
||||||
|
|> Ash.update!()
|
||||||
|
|
||||||
|
:ok
|
||||||
|
|
||||||
|
{:error, %Ash.Error.Query.NotFound{}} ->
|
||||||
|
attrs =
|
||||||
|
attrs
|
||||||
|
|> Map.put(:dbi_server_id, server_id)
|
||||||
|
|
||||||
|
AuthorAliasRegistry
|
||||||
|
|> Ash.Changeset.for_create(:sync_create, attrs)
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue