Skip to content

Commit

Permalink
simplify use of AuthPlugOptional in router.ex #65
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Oct 2, 2020
1 parent 0c883ce commit 28dc5a6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 123 deletions.
96 changes: 0 additions & 96 deletions lib/app/ctx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -202,102 +202,6 @@ defmodule App.Ctx do
Status.changeset(status, %{})
end

alias App.Ctx.Item

@doc """
Returns the list of items.
## Examples
iex> list_items()
[%Item{}, ...]
"""
def list_items do
Repo.all(Item)
end

@doc """
Gets a single item.
Raises `Ecto.NoResultsError` if the Item does not exist.
## Examples
iex> get_item!(123)
%Item{}
iex> get_item!(456)
** (Ecto.NoResultsError)
"""
def get_item!(id), do: Repo.get!(Item, id)

@doc """
Creates a item.
## Examples
iex> create_item(%{field: value})
{:ok, %Item{}}
iex> create_item(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_item(attrs \\ %{}) do
%Item{}
|> Item.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a item.
## Examples
iex> update_item(item, %{field: new_value})
{:ok, %Item{}}
iex> update_item(item, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_item(%Item{} = item, attrs) do
item
|> Item.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a Item.
## Examples
iex> delete_item(item)
{:ok, %Item{}}
iex> delete_item(item)
{:error, %Ecto.Changeset{}}
"""
def delete_item(%Item{} = item) do
Repo.delete(item)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking item changes.
## Examples
iex> change_item(item)
%Ecto.Changeset{source: %Item{}}
"""
def change_item(%Item{} = item) do
Item.changeset(item, %{})
end

alias App.Ctx.List

@doc """
Expand Down
23 changes: 0 additions & 23 deletions lib/app/ctx/session.ex

This file was deleted.

6 changes: 2 additions & 4 deletions lib/app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule AppWeb.Router do
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
# plug AppWeb.Auth
plug AuthPlugOptional
end

pipeline :api do
Expand All @@ -21,10 +21,8 @@ defmodule AppWeb.Router do
plug :accepts, ["json"]
end

pipeline :auth_optional, do: plug(AuthPlugOptional, %{})

scope "/", AppWeb do
pipe_through [:browser, :auth_optional]
pipe_through [:browser]

get "/", PageController, :index
# post "/register", PageController, :index
Expand Down

0 comments on commit 28dc5a6

Please sign in to comment.