Add very simple context for face gallery.

This commit is contained in:
James Harton 2018-04-08 09:29:25 +12:00
parent be7f3a2981
commit d38a867de1
4 changed files with 61 additions and 0 deletions

View 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

View 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

View 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

View file

@ -0,0 +1,4 @@
defmodule Faces.GalleryTest do
use Faces.DataCase
alias Faces.Gallery
end