Adds one resource to a domain of a dandelion project, in the layout the
project already uses — the way you'd copy shop and rename it, done for you.
mix dandelion.gen.domain DOMAIN RESOURCE [field:type ...]
mix dandelion.gen.domain Billing Invoice number:string amount_cents:integer paid:booleanwrites (for domain Billing, resource Invoice):
lib/app/billing/models/invoice.ex schema + validation
lib/app/billing/repos/invoice_repo.ex queries, nothing else
lib/app/billing/services/invoice_service.ex business rules: create / get / list
lib/app/billing/handlers/invoice_handler.ex HTTP: params → service → JSON
lib/app/billing/handlers/invoice_json.ex the JSON shape
priv/repo/migrations/<time>_create_invoices.exs
test/app/billing/services/invoice_service_test.exs
test/app/billing/handlers/invoice_handler_test.exs
test/support/app/billing/invoice_fixtures.exand adds POST /api/invoices, GET /api/invoices, GET /api/invoices/:id
to lib/platform/web/router.ex. Then run mix ecto.migrate and mix test.
If the router has an :authenticated pipeline (the example's login does), the
new routes go through it, so a new resource isn't public by accident. The
generated handlers don't ask who is calling: what a user may see is a rule —
add it to the service, the way OrderService scopes orders to their owner.
Field types: string (up to 255 characters), text (up to 10 000),
integer and boolean (false unless given). All fields are required except
booleans. There must be at least one that isn't a boolean. id,
inserted_at and updated_at come for free.
The table is the resource's plural (invoices); it can be changed with
--table. The task refuses to overwrite a file that exists.
It does not know your business: it gives you the shape — create, show, list —
and you add the rules (a cancel, a state change) the way shop does.