Skip to content
Snippets Groups Projects
Commit e0a01546 authored by FERRIEUX Etienne's avatar FERRIEUX Etienne
Browse files

added constraint on id db

parent 370f62e4
Branches
No related tags found
No related merge requests found
......@@ -47,13 +47,21 @@ defmodule SimpleServer.Router do
{:ok, body, conn} = read_body(conn)
body = Poison.decode!(body)
id = %Identity{uid: body["uid"], pubkey: body["pubkey"], member: body["member"]}
Repo.insert(id)
changeset = Identity.changeset(%Identity{},%{uid: body["uid"], pubkey: body["pubkey"], member: body["member"]})
result = Repo.insert(changeset)
case result do
{:error,changeset} -> send_resp(conn, 301, "failed creation: #{inspect changeset}")
_ ->
DynamicSupervisor.start_child(Identity.DynamicSupervisor, %{id: body["pubkey"], start: {IDGenserver, :start, [body["pubkey"]]}})
# We insert the Identity in the db and start the genserver that will its certifications.
send_resp(conn, 201, "created: #{inspect id}")
send_resp(conn, 201, "created: #{inspect changeset}")
end
end
......
......@@ -7,5 +7,7 @@ defmodule Duniter.Repo.Migrations.CreateIds do
add :pubkey, :string
add :member, :boolean
end
create unique_index(:identities, [:uid])
create unique_index(:identities, [:pubkey])
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment