103 lines
6.0 KiB
Markdown
103 lines
6.0 KiB
Markdown
# Admin API prefix
|
|
|
|
Only APIs used by the admin panel receive the `/admin` prefix, under the existing API version:
|
|
|
|
| Consumer | Base URL | Documentation |
|
|
| --- | --- | --- |
|
|
| Admin panel | `/api/v1/admin` | `/swagger/admin/index.html` |
|
|
| Customer web and mobile apps | `/api/v1` (unchanged) | `/swagger/client/index.html` |
|
|
|
|
Customer apps do not need a `/client` prefix or a base URL change. The checkout website retains its
|
|
existing base URL configuration. Protected customer requests still use customer authentication and
|
|
subscription checks; protected admin requests require staff authentication and existing RBAC permissions.
|
|
|
|
## Admin panel changes
|
|
|
|
Admin route registrations live in `internal/web_server/routes_admin.go`. All panel operations,
|
|
including login, refresh, catalog authoring, question banks, users, subscriptions, payments, settings,
|
|
referrals, analytics, RBAC, notification management, CSV exports, and WebSockets, use `/api/v1/admin`.
|
|
Endpoints already under `/admin` keep a single prefix. Admin-account management is `/admin/admins`.
|
|
|
|
The admin panel's API helper accepts `VITE_API_BASE_URL` ending in either `/api/v1` or `/api/v1/admin`.
|
|
It ensures the `/admin` prefix is added exactly once. Panel endpoint definitions no longer supply a
|
|
second `/admin` segment. Raw refresh calls, CSV downloads, and notification sockets use the same base.
|
|
Staff profiles use `/api/v1/admin/team/me` rather than the customer self-profile endpoint.
|
|
|
|
Shared reads have separate registrations: the panel reads `/api/v1/admin/exam-prep/catalog-courses`,
|
|
while customers continue reading `/api/v1/exam-prep/catalog-courses`. Admin reads retain their existing
|
|
permissions and staff visibility. Customer reads retain publication, subscription, and free-content rules.
|
|
Raw authoring endpoints belong to the admin API; customer practice questions are delivered through
|
|
`/api/v1/exam-prep/practices/{practiceId}/questions`.
|
|
|
|
## Examples
|
|
|
|
| Purpose | Route |
|
|
| --- | --- |
|
|
| Staff login | `POST /api/v1/admin/team/login` |
|
|
| Staff refresh | `POST /api/v1/admin/team/refresh` |
|
|
| Manage learners | `GET /api/v1/admin/users` |
|
|
| View all payments | `GET /api/v1/admin/payments` |
|
|
| Configure referrals | `PUT /api/v1/admin/referrals/settings` |
|
|
| Author a catalog course | `POST /api/v1/admin/exam-prep/catalog-courses` |
|
|
| Customer login | `POST /api/v1/auth/customer-login` (unchanged) |
|
|
| Customer registration | `POST /api/v1/user/register` (unchanged) |
|
|
| Customer catalog | `GET /api/v1/exam-prep/catalog-courses` (unchanged) |
|
|
| Customer checkout | `POST /api/v1/payments/subscribe` (unchanged) |
|
|
| Customer subscriptions | `GET /api/v1/subscriptions/me` (unchanged) |
|
|
| Customer referrals | `GET /api/v1/referrals/me` (unchanged) |
|
|
|
|
See `api-route-migration.json` for the complete method/path mapping. Customer and staff tokens cannot
|
|
be used interchangeably. Customer plan discovery excludes inactive plans. Customer profile-picture
|
|
updates are restricted to the authenticated account. Notification queries and live delivery distinguish
|
|
customer IDs from team-member IDs, including when numeric IDs match.
|
|
|
|
## External integrations and documentation
|
|
|
|
Gateway URLs retain their existing paths and verification behavior:
|
|
|
|
- `POST /api/v1/payments/webhook`
|
|
- `GET /api/v1/payments/chapa/callback`
|
|
- `GET /api/v1/payments/chapa/success`
|
|
- `GET /api/v1/payments/arifpay/success`
|
|
- `GET /payment/success`
|
|
- `GET /api/v1/auth/google/callback`
|
|
|
|
No payment callback configuration or database migration is required for the prefix change.
|
|
Separate OpenAPI documents are available at `/swagger/admin/doc.json` and `/swagger/client/doc.json`;
|
|
these documentation paths do not change the customer API base. The `/routes` and `/auth/test` debugging
|
|
endpoints are not exposed.
|
|
|
|
## Verification
|
|
|
|
Run `go test ./...` in the backend and `npm run build` in the admin and checkout repositories.
|
|
Notification SQL isolation can be checked with `node db/tests/notification-audiences.test.cjs`, using
|
|
the scratch PGlite setup and `REFERRAL_TEST_PACKAGE_JSON` described in `referral-system.md`.
|
|
|
|
## Swagger maintenance
|
|
|
|
Run `make swagger` (or `swag init -g cmd/main.go`) after changing handler annotations. Commit
|
|
`docs/docs.go`, `docs/swagger.json`, and `docs/swagger.yaml` together. Documentation-only operations in
|
|
`swagger_admin_shared.go` distinguish staff-only reads from public customer operations that share a handler;
|
|
they are not registered as runtime handlers. Referral request and response models include decimal-string
|
|
amounts, percentage limits, nullable reversals, and pagination bounds.
|
|
|
|
Run `go test ./internal/web_server -run 'TestSwagger|TestGeneratedSwagger|TestAudienceSpecifications'`
|
|
to check every registered API method/path, path parameters, request-body coverage, authorization,
|
|
WebSocket query-token authentication, referenced schemas, and generated artifact consistency.
|
|
The admin and customer Swagger pages prune unrelated paths and models. Their Authorize dialogs expect
|
|
`Bearer <access_token>`; WebSockets instead use the documented `token` query parameter.
|
|
Authentication/authorization middleware may return plain-text errors, while application handlers also
|
|
return the JSON error shapes documented for their operations. Payment webhook authentication uses the
|
|
provider signature headers, not a customer Bearer token.
|
|
|
|
## Offline export
|
|
|
|
Run `make swagger-export` to regenerate and package the current docs, or run
|
|
`go run ./cmd/swagger-export -out exports/swagger-offline` to export the already-generated specifications.
|
|
The command creates `exports/swagger-offline/index.html` and `exports/swagger-offline.zip`.
|
|
Extract the ZIP completely and open `index.html` directly in a browser. No server or internet connection
|
|
is required. Admin, customer, and complete API pages embed their specifications and use bundled Swagger UI
|
|
assets. JSON and YAML specs for all three views are included in `specs/` for importing into API tools.
|
|
API execution is disabled in the offline reference. Use the running application's Swagger UI when you
|
|
need to send requests. The export contains no account tokens, environment files, or server configuration.
|