1.2 KiB · text History bdf21c8
defmodule CartosnapApp.Photos.Photo do
  use Ecto.Schema
  import Ecto.Changeset

  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id
  schema "photo_photos" do
    field :blurhash, :string
    field :date, :utc_datetime
    field :exif, :map
    field :filename, :string
    field :geo_point,  Geo.PostGIS.Geometry
    field :name, :string
    field :promoted, :boolean, default: false
    field :url_full, :string
    field :url_original, :string
    field :url_preview, :string
    field :url_thumb, :string
    field :user, :binary_id

    timestamps()
  end

  @doc false
  def changeset_boot(photo, attrs) do
    photo
    |> cast(attrs, [:id, :name, :exif, :filename, :date, :url_original, :url_full, :url_preview, :url_thumb, :blurhash, :geo_point, :promoted, :user])
    |> validate_required([:id, :exif, :filename, :date, :url_original, :blurhash, :user])
  end

  @doc false
  def changeset(photo, attrs) do
    photo
    |> cast(attrs, [:name, :exif, :filename, :date, :url_original, :url_full, :url_preview, :url_thumb, :blurhash, :geo_point, :promoted])
    |> validate_required([:exif, :filename, :date, :url_original, :url_full, :url_preview, :url_thumb, :blurhash, :promoted])
  end
end