Add Translators/deepl_accounts
mix phx.gen.live Translators DeeplAccount deepl_accounts\ name:string description:text auth_key:string character_limit:integer\ character_count:integer our_character_count:integer user_id:references:users
This commit is contained in:
104
lib/outlook/translators.ex
Normal file
104
lib/outlook/translators.ex
Normal file
@ -0,0 +1,104 @@
|
||||
defmodule Outlook.Translators do
|
||||
@moduledoc """
|
||||
The Translators context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Outlook.Repo
|
||||
|
||||
alias Outlook.Translators.DeeplAccount
|
||||
|
||||
@doc """
|
||||
Returns the list of deepl_accounts.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_deepl_accounts()
|
||||
[%DeeplAccount{}, ...]
|
||||
|
||||
"""
|
||||
def list_deepl_accounts do
|
||||
Repo.all(DeeplAccount)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single deepl_account.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Deepl account does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_deepl_account!(123)
|
||||
%DeeplAccount{}
|
||||
|
||||
iex> get_deepl_account!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_deepl_account!(id), do: Repo.get!(DeeplAccount, id)
|
||||
|
||||
@doc """
|
||||
Creates a deepl_account.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_deepl_account(%{field: value})
|
||||
{:ok, %DeeplAccount{}}
|
||||
|
||||
iex> create_deepl_account(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_deepl_account(attrs \\ %{}) do
|
||||
%DeeplAccount{}
|
||||
|> DeeplAccount.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a deepl_account.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_deepl_account(deepl_account, %{field: new_value})
|
||||
{:ok, %DeeplAccount{}}
|
||||
|
||||
iex> update_deepl_account(deepl_account, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_deepl_account(%DeeplAccount{} = deepl_account, attrs) do
|
||||
deepl_account
|
||||
|> DeeplAccount.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a deepl_account.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_deepl_account(deepl_account)
|
||||
{:ok, %DeeplAccount{}}
|
||||
|
||||
iex> delete_deepl_account(deepl_account)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_deepl_account(%DeeplAccount{} = deepl_account) do
|
||||
Repo.delete(deepl_account)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking deepl_account changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_deepl_account(deepl_account)
|
||||
%Ecto.Changeset{data: %DeeplAccount{}}
|
||||
|
||||
"""
|
||||
def change_deepl_account(%DeeplAccount{} = deepl_account, attrs \\ %{}) do
|
||||
DeeplAccount.changeset(deepl_account, attrs)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user