-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsighting.ex
More file actions
31 lines (27 loc) · 815 Bytes
/
sighting.ex
File metadata and controls
31 lines (27 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
defmodule CableCarSpotter.Sighting do
use CableCarSpotter.Web, :model
use Arc.Ecto.Schema
schema "sightings" do
field :comment, :string
field :photo, CableCarSpotter.Photo.Type
belongs_to :user, CableCarSpotter.User
belongs_to :cable_car, CableCarSpotter.CableCar
field :photo_taken_at, :utc_datetime
field :geom, Geo.Point
timestamps()
end
@doc """
Builds a changeset based on the `struct` and `params`.
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:comment, :user_id, :cable_car_id])
|> cast_attachments(params, [:photo])
|> validate_required([:user_id, :cable_car_id])
end
def changeset_with_photo(struct, params, metadata) do
struct
|> changeset(params)
|> cast(metadata, [:photo_taken_at, :geom])
end
end