RezinaLMS-BackEnd/docs/demo-and-public-catalog.md

174 lines
9.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Makeup academy discovery and pre-production demo
## Browse without signing in
Public discovery is intended for customer-facing web and mobile learning apps.
The admin panel is a staff application: signed-out visitors to `/` are redirected
to `/login`, and signed-in staff go to their role's default management page.
The admin panel does not host customer catalog pages or use anonymous catalog APIs
for content management. Its course, chapter, lesson, and quiz tools continue to
use authenticated `/api/v1/admin` endpoints.
Anonymous APIs:
| Endpoint | Result |
| --- | --- |
| `GET /api/v1/catalog/courses?q=&limit=20&offset=0` | Searchable published course highlights, access tiers, chapter/lesson/quiz counts and pagination |
| `GET /api/v1/catalog/courses/:id` | Published course outline with chapter descriptions, lesson highlights, and quiz titles/question counts |
These endpoints accept no authentication requirement and never expand their
visibility for staff tokens. Draft courses return 404; draft chapters, lessons,
quiz shells and question sets are excluded. Public DTOs contain no video URLs,
questions, correct answers, author identities, or learner progress. Playback,
question delivery, and completion remain behind the existing learning endpoints
and their authentication/subscription rules. Previewing a premium lesson does not
grant access to it.
### Client app integration
Use the backend's public API base (for example `https://api.example.com/api/v1`)
in the customer app, without the `/admin` suffix. No bearer token is required.
Render course highlights from the list response and load the course outline
when a visitor selects a course. For browser requests, omit staff credentials:
```javascript
const apiBase = "https://api.example.com/api/v1";
const response = await fetch(`${apiBase}/catalog/courses?limit=20&offset=0`, {
credentials: "omit",
});
if (!response.ok) throw new Error("Unable to load course highlights");
const { data } = await response.json();
// data.courses, data.total_count, data.limit, data.offset
```
Use `GET /catalog/courses/{id}` on the same base for the published outline.
Customer apps should offer their own learner sign-in flow when visitors choose
to start learning; authenticated playback, quiz, and progress APIs enforce access.
## Install the demo fixture
Apply database migrations through `000005_makeup_artistry_focus`, then run from
the backend directory:
```powershell
go run ./cmd/demo-seed -environment development
```
The command reads `DB_URL` from the environment or the backend `.env`. It needs
only PostgreSQL; it does not start the application or require payment, email,
SMS, or storage provider credentials. `-environment` must explicitly be
`development`, `test`, or `staging`. `APP_ENV`, `ENVIRONMENT`, `GO_ENV`, or `ENV` set to
`production`/`prod` prevents seeding. The CLI logs a skip and exits successfully
before reading database configuration or opening a connection, so an unconditional
optional seed step does not block a production release. An invalid or missing
`-environment` remains an error. Production deployment scripts should omit demo
seeding altogether; this behavior is a compatibility safeguard for existing runners.
For the repository's Docker PostgreSQL:
```powershell
docker compose up -d postgres
docker compose run --rm migrate
$env:DB_URL = 'postgresql://root:secret@localhost:5592/gh?sslmode=disable'
go run ./cmd/demo-seed -environment development
```
The Docker host mapping is `5592:5432`. Use your actual database credentials when
connecting to another development or staging database. A Docker app image also
contains `/app/bin/demo-seed` for explicitly running the same command; it never
runs automatically on application startup. Do not use the older broad
`db/data`/`db/dev_data` scripts for this new hierarchy fixture.
Optional settings:
| Variable | Default / purpose |
| --- | --- |
| `DEMO_SEED_PASSWORD` | `RezinaDemo!2026`; set a custom password of 12–72 bytes for every demo account |
| `DEMO_VIDEO_URL` | Public Big Buck Bunny sample clip for testing playback; replace with your own media URL for realistic lesson videos |
| `DEMO_TEST_DB_URL` | Disposable, fully migrated PostgreSQL database used only by the opt-in integration test |
The supplied videos are playback fixtures, not makeup instructional recordings.
Use `DEMO_VIDEO_URL` or the lesson editor to attach your own licensed teaching
media. A black makeup artistry SVG course cover is included in the backend image.
## Demo accounts
All accounts use **`RezinaDemo!2026`** unless `DEMO_SEED_PASSWORD` is set.
| Email | Role | Login endpoint | Expected access |
| --- | --- | --- | --- |
| `superadmin@demo.rezina.test` | `SUPER_ADMIN` | `POST /api/v1/admin/team/login` | Full staff permissions, including team invitations |
| `admin@demo.rezina.test` | `ADMIN` | `POST /api/v1/admin/team/login` | Administrative permissions under existing role rules |
| `contentmanager@demo.rezina.test` | `CONTENT_MANAGER` | `POST /api/v1/admin/team/login` | Content management permissions and restricted admin navigation |
| `student@demo.rezina.test` | `STUDENT` | `POST /api/v1/auth/customer-login` | Unsubscribed learner; verifies premium restrictions |
| `premium@demo.rezina.test` | `STUDENT` | `POST /api/v1/auth/customer-login` | 30-day makeup academy subscription (`EDUCATION`), refreshed on seed rerun |
| `openlearner@demo.rezina.test` | `OPEN_LEARNER` | `POST /api/v1/auth/customer-login` | Existing unrestricted learner access rules |
Both login endpoints accept `{"email":"...","password":"..."}`. Staff sign in
through the admin web app. Customer accounts use the customer API or learning
app; they do not sign in through the staff form. Accounts are active, email
verified, and use bcrypt password hashes compatible with the real login paths.
No email delivery or invitation acceptance is required for these fixtures.
These cover all currently assignable staff roles and both customer learner roles.
Legacy names such as Instructor, Support Agent, Finance, HR, and Analyst are not
seeded as team accounts: the current database and team service allow only Super
Admin, Admin, and Content Manager. The seeder does not change role restrictions
or grant every role administrator permissions. Standard RBAC seeds are applied;
restart a running backend after seeding so its permission cache reloads.
## Included learning data and reruns
- Makeup Artistry Foundations: 2 chapters, 6 lessons, 2 quizzes; free course.
- Bridal and Occasion Makeup: 2 chapters, 6 lessons, 2 quizzes; premium course.
- Creative and Editorial Makeup: 2 chapters, 6 lessons, 2 quizzes; free course.
- Each quiz contains 3 subject-specific multiple-choice questions, explanations, and varied correct-answer positions.
- One unpublished course verifies that public discovery hides drafts.
- One inactive demo subscription plan provides the premium test account access
without appearing as a purchasable production plan.
The fixture runs in one transaction under an advisory lock. It uses generated
IDs and the `demo_seed_entities` ownership map rather than fixed IDs or table
truncation. Makeup fixtures have their own `makeup-*` keys. Reruns reuse existing
makeup content, preserve edits to it, reset the six
demo account passwords/statuses to the configured test credentials, and refresh
the seed-owned premium subscription. Existing unrelated accounts and learning
content are not deleted. Keep these fixtures in a separate pre-production
database; this command is not part of production migration or startup.
When upgrading the old general-learning demo, untouched seed-owned Everyday
English, Workplace Communication, and Digital Skills courses are changed to
drafts. Their records and progress are retained. Courses with recorded edits
or additions (including changed descendants) stay as authored. The original
inactive demo plan is relabeled as `[Demo] Makeup Academy Pass` only when its
name and description still match the original defaults; its ID and subscription
links are retained. The new course keys prevent old quiz attempts from being
reinterpreted as attempts on different subject matter. Demo learners receive
makeup profile defaults only for empty fields.
## Verification
```powershell
go test ./internal/demoseed ./internal/services/examprep ./internal/web_server/... ./internal/apidocs/...
```
For the database-backed seed and catalog test, use a disposable migrated database:
```powershell
$env:DEMO_TEST_DB_URL = '<disposable migrated PostgreSQL URL>'
go test ./internal/demoseed -run TestDemoSeedAndPublicCatalogIntegration -count=1 -v
```
That test writes demo data, runs the seed twice, checks login password hashes,
and verifies unpublished-course/descendant filtering. It is skipped unless
`DEMO_TEST_DB_URL` is explicitly provided and never reads application `DB_URL`.
In `RezinaLMS-Admin`, run `npm run test:learning` and `npm run build`.
### Production curriculum versus optional demo fixtures
Migration `000006_makeup_course_catalog` installs makeup starter drafts without test accounts
or sample video fixtures and archives untouched legacy course fixtures. It runs even when the
production demo-seed command is skipped. See [the catalog conversion notes](makeup-artistry-backend.md#production-course-catalog-conversion).
The demo seeder reuses these course/chapter/lesson/quiz IDs and does not automatically publish
existing starter drafts; publish reviewed content explicitly in the admin.