Parity PR 5a: the admin JSON API (Erlang routes, through the desk entry points) #17

Closed
mercurius wants to merge 0 commits from mercurius/4-pr5-facade into main
Member

Refs macula-services/mcl-bookclub-phoenix#4: parity PR 5 (the facade), first half. Gap table §D "admin JSON API: missing" and §F "admin over HTTP: thinner".

What

The Erlang twin's admin JSON API (mcl_bookclub_admin.erl:30-34, 63-93), served by the Phoenix endpoint beside the LiveView console:

  • POST /api/{plural}/{verb}: the nine commands, each through its desk's *_api entry point. 200 {"ok":true,"version":v,"events":[...]} or 400 {"ok":false,"error":reason}.
  • GET /api/{clubs|members|books|readings}/:id and GET /api/members/:id/readings: the five QRY desks. 200 with the row, or 404 {"ok":false,"error":reason}.
  • A route with no desk behind it: 404 {"error":"not_found"}, as E's dispatch(_, _, _).

MclBookclubPhoenixWeb.ClubName.enrich/1 stamps the club's name into register and procure, as E's enrich_club_name/1 (:100-108). It keeps a name the caller brings. The LiveView now calls the same module instead of its own private copy, so the console and the API cannot drift apart.

Choices a reviewer may question

  • The controller reads its own body rather than using Plug.Parsers. E turns an unreadable body into empty params, and the desk then refuses the missing fields with a 400 JSON (decode/1, :124-135). Plug.Parsers would raise ParseError, and this endpoint's ErrorView renders HTML only. The :api pipeline therefore parses nothing.
  • Each route lists the fields it passes on. E decodes with {labels, atom}. In Elixir a body key never becomes an atom, so only the route's own fields reach the entry point.
  • A refusal richer than an atom (a tuple carrying the bad value) is shown with inspect/1, because JSON has no tuples.

Tests (apps/mcl_bookclub_phoenix_web/test/admin_api_test.exs)

E's mcl_bookclub_admin_tests case for case, through Phoenix.ConnTest against a real reckon-db store and the PRJ projections (ProjectBookclub.TestEnv). The cases: club initiated and read back; member registered with the club's name and read back; reading started and finished, then listed by member; a missing field is a 400; an unknown id is a 404. Added: an unreadable or non-object body is empty params (400, not a crash); a caller's own club name is kept; a route with no desk is a 404. E's static-UI case becomes the LiveView mount test in the next PR.

Not in this PR

  • Next PR (stacked): E's service tests (info version = the app's, with the "0.1.0" drift fixed; health probes the stores) and a LiveView mount/click test.
  • PR 6: the capability-through-the-wire test (mcl_om_wire_test, which comes with E's mcl_om 1.6 / macula 18 line), @moduledoc text, CHANGELOG.

Checks (msi00, CI image)

At 7ed3ef3: deps, format, compile --warnings-as-errors, credo --strict, dialyzer, all rc 0. mix test: host 186, prj 20, qry 16, fac 11, web 15 (8 new); 0 failures.

Mutants (each killed):

  • register not enriched → "a member registers, carries the club's name…"
  • an unreadable body raises → "a body that is not a JSON object…"
  • a refusal answers 200 → "a missing field is a 400…" (and the body test)
  • an unknown route answers 200 → "a route with no desk behind it is a 404"
  • the readings route removed, or reading one reading by the member's id → "a reading starts and finishes over http"
  • the clause that keeps a caller's club name removed → "a club name the caller brings is kept…"
Refs macula-services/mcl-bookclub-phoenix#4: parity PR 5 (the facade), first half. Gap table §D "admin JSON API: missing" and §F "admin over HTTP: thinner". ## What The Erlang twin's admin JSON API (`mcl_bookclub_admin.erl:30-34, 63-93`), served by the Phoenix endpoint beside the LiveView console: - `POST /api/{plural}/{verb}`: the nine commands, each through its desk's `*_api` entry point. `200 {"ok":true,"version":v,"events":[...]}` or `400 {"ok":false,"error":reason}`. - `GET /api/{clubs|members|books|readings}/:id` and `GET /api/members/:id/readings`: the five QRY desks. `200` with the row, or `404 {"ok":false,"error":reason}`. - A route with no desk behind it: `404 {"error":"not_found"}`, as E's `dispatch(_, _, _)`. `MclBookclubPhoenixWeb.ClubName.enrich/1` stamps the club's name into register and procure, as E's `enrich_club_name/1` (`:100-108`). It keeps a name the caller brings. The LiveView now calls the same module instead of its own private copy, so the console and the API cannot drift apart. ## Choices a reviewer may question - **The controller reads its own body** rather than using `Plug.Parsers`. E turns an unreadable body into empty params, and the desk then refuses the missing fields with a 400 JSON (`decode/1`, `:124-135`). `Plug.Parsers` would raise `ParseError`, and this endpoint's `ErrorView` renders HTML only. The `:api` pipeline therefore parses nothing. - **Each route lists the fields it passes on.** E decodes with `{labels, atom}`. In Elixir a body key never becomes an atom, so only the route's own fields reach the entry point. - **A refusal richer than an atom** (a tuple carrying the bad value) is shown with `inspect/1`, because JSON has no tuples. ## Tests (`apps/mcl_bookclub_phoenix_web/test/admin_api_test.exs`) E's `mcl_bookclub_admin_tests` case for case, through `Phoenix.ConnTest` against a real reckon-db store and the PRJ projections (`ProjectBookclub.TestEnv`). The cases: club initiated and read back; member registered with the club's name and read back; reading started and finished, then listed by member; a missing field is a 400; an unknown id is a 404. Added: an unreadable or non-object body is empty params (400, not a crash); a caller's own club name is kept; a route with no desk is a 404. E's static-UI case becomes the LiveView mount test in the next PR. ## Not in this PR - Next PR (stacked): E's service tests (info version = the app's, with the "0.1.0" drift fixed; health probes the stores) and a LiveView mount/click test. - PR 6: the capability-through-the-wire test (`mcl_om_wire_test`, which comes with E's mcl_om 1.6 / macula 18 line), @moduledoc text, CHANGELOG. ## Checks (msi00, CI image) At 7ed3ef3: deps, format, compile `--warnings-as-errors`, credo `--strict`, dialyzer, all rc 0. mix test: host 186, prj 20, qry 16, fac 11, web 15 (8 new); 0 failures. Mutants (each killed): - register not enriched → "a member registers, carries the club's name…" - an unreadable body raises → "a body that is not a JSON object…" - a refusal answers 200 → "a missing field is a 400…" (and the body test) - an unknown route answers 200 → "a route with no desk behind it is a 404" - the readings route removed, or reading one reading by the member's id → "a reading starts and finishes over http" - the clause that keeps a caller's club name removed → "a club name the caller brings is kept…"
Serve the admin's JSON API: the Erlang twin's routes, through the desk entry points
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m25s
c4 model / c4-model-1 (push) Successful in 3s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 6m56s
7ed3ef30ba
Member

Landed by fast-forward: main is 7ed3ef30ba (from 26c55732). This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is 7ed3ef30ba8281c2d8a7b3ed41ef848c09150933 (from 26c55732). This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-01 12:11:19 +00:00
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 3s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m25s
c4 model / c4-model-1 (push) Successful in 3s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 6m56s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-bookclub-phoenix!17
No description provided.