| 1 |
|
defmodule DaProductApp.QRValidation.QRValidationEvent do |
| 2 |
|
@moduledoc """ |
| 3 |
|
Event record for QR Validation aggregate with hash chaining. |
| 4 |
|
""" |
| 5 |
|
use Ecto.Schema |
| 6 |
|
import Ecto.Changeset |
| 7 |
|
|
| 8 |
:-( |
schema "qr_validation_events" do |
| 9 |
|
field :seq, :integer |
| 10 |
|
field :event_type, :string |
| 11 |
|
field :payload, :map |
| 12 |
|
field :prev_hash, :binary |
| 13 |
|
field :hash, :binary |
| 14 |
|
belongs_to :qr_validation, DaProductApp.QRValidation.QRValidation |
| 15 |
|
field :inserted_at, :utc_datetime |
| 16 |
|
end |
| 17 |
|
|
| 18 |
|
@required ~w(seq event_type hash inserted_at qr_validation_id)a |
| 19 |
|
@optional ~w(payload prev_hash)a |
| 20 |
|
|
| 21 |
|
def changeset(struct, attrs) do |
| 22 |
|
struct |
| 23 |
|
|> cast(attrs, @required ++ @optional) |
| 24 |
|
|> validate_required(@required) |
| 25 |
:-( |
|> unique_constraint([:qr_validation_id, :seq]) |
| 26 |
|
end |
| 27 |
|
end |