Packages
boruta
1.0.1
3.0.0-beta.4
3.0.0-beta.3
3.0.0-beta.2
3.0.0-beta.1
2.3.6
2.3.5
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.2
2.2.1
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.1
2.0.0
2.0.0-rc.1
2.0.0-rc.0
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc.3
1.0.0-rc.2
1.0.0-rc.1
1.0.0-rc.0
0.2.1
0.2.0
0.1.1
0.1.0
0.1.0-rc.5
0.1.0-rc.4
0.1.0-rc.3
0.1.0-rc.2
0.1.0-rc.1
Core of an OAuth/OpenID Connect provider enabling authorization in your applications.
Current section
Files
Jump to
Current section
Files
lib/boruta/adapters/ecto/admin/clients.ex
defmodule Boruta.Ecto.Admin.Clients do
@moduledoc """
`Boruta.Ecto.Client` resource administration.
"""
import Ecto.Query, warn: false
import Boruta.Config, only: [repo: 0]
alias Boruta.Ecto.Client
alias Boruta.Ecto.Clients
alias Boruta.Oauth
@doc """
Returns the list of clients.
## Examples
iex> list_clients()
[%Client{}, ...]
"""
def list_clients do
clients = repo().all(Client)
repo().preload(clients, :authorized_scopes)
end
@doc """
Gets a single client.
Raises `Ecto.NoResultsError` if the Client does not exist.
## Examples
iex> get_client!(123)
%Client{}
iex> get_client!(456)
** (Ecto.NoResultsError)
"""
def get_client!(id) do
client = repo().get!(Client, id)
repo().preload(client, :authorized_scopes)
end
@doc """
Creates a client.
## Examples
iex> create_client(%{field: value})
{:ok, %Client{}}
iex> create_client(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_client(attrs \\ %{}) do
%Client{}
|> Client.create_changeset(attrs)
|> repo().insert()
end
@doc """
Updates a client.
## Examples
iex> update_client(client, %{field: new_value})
{:ok, %Client{}}
iex> update_client(client, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_client(%Client{} = client, attrs) do
with {:ok, client} <- client |> Client.update_changeset(attrs) |> repo().update(),
:ok <- Clients.invalidate(%Oauth.Client{id: client.id})do
{:ok, client}
end
end
@doc """
Deletes a Client.
## Examples
iex> delete_client(client)
{:ok, %Client{}}
iex> delete_client(client)
{:error, %Ecto.Changeset{}}
"""
def delete_client(%Client{} = client) do
with :ok <- Clients.invalidate(%Oauth.Client{id: client.id})do
repo().delete(client)
end
end
end