Zongzi.Util.Model behaviour (zongzi v0.3.0)

Copy Markdown

Domain model helper.

by invoke use Zongzi.Util.Model, keys: [...], id_prefix: "xxx" will generate automatically:

  • struct defination
  • new/1 — Have to provide :id explicitly (a pure function, not automatically generated).
  • validate/1
  • update/2

ID Generation

new/1 no longer generates an ID automatically. The caller generates the ID using Zongzi.Util.ID.generate_id/1 and passes it in. It ensures the Domain layer does not rely on random numbers.

Return {:ok, result} or {:error, reason} .

Summary

Callbacks

Check if the domain model is valid.

Callbacks

validate(model)

(optional)
@callback validate(model :: struct()) :: {:ok, struct()} | {:error, term()}

Check if the domain model is valid.