Add very simple context for face gallery.
This commit is contained in:
parent
be7f3a2981
commit
d38a867de1
4 changed files with 61 additions and 0 deletions
23
lib/faces/gallery/gallery.ex
Normal file
23
lib/faces/gallery/gallery.ex
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule Faces.Gallery do
|
||||
@moduledoc """
|
||||
The Gallery context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Faces.Repo
|
||||
|
||||
alias Faces.Gallery.Person
|
||||
|
||||
@doc """
|
||||
Returns the list of people.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_people()
|
||||
[%Person{}, ...]
|
||||
|
||||
"""
|
||||
def list_people do
|
||||
Repo.all(Person)
|
||||
end
|
||||
end
|
20
lib/faces/gallery/person.ex
Normal file
20
lib/faces/gallery/person.ex
Normal file
|
@ -0,0 +1,20 @@
|
|||
defmodule Faces.Gallery.Person do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
|
||||
schema "people" do
|
||||
field :avatar_url, :string
|
||||
field :location, :string
|
||||
field :name, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(person, attrs) do
|
||||
person
|
||||
|> cast(attrs, [:name, :location, :avatar_url])
|
||||
|> validate_required([:name, :location, :avatar_url])
|
||||
end
|
||||
end
|
14
priv/repo/migrations/20180407212640_create_people.exs
Normal file
14
priv/repo/migrations/20180407212640_create_people.exs
Normal file
|
@ -0,0 +1,14 @@
|
|||
defmodule Faces.Repo.Migrations.CreatePeople do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:people) do
|
||||
add :name, :string
|
||||
add :location, :string
|
||||
add :avatar_url, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
end
|
||||
end
|
4
test/faces/gallery/gallery_test.exs
Normal file
4
test/faces/gallery/gallery_test.exs
Normal file
|
@ -0,0 +1,4 @@
|
|||
defmodule Faces.GalleryTest do
|
||||
use Faces.DataCase
|
||||
alias Faces.Gallery
|
||||
end
|
Reference in a new issue