24 KiB
FAQ Admin Panel — Integration Guide
This guide documents how to integrate the FAQ management feature into the Rezina admin panel. It covers authentication, RBAC permissions, admin CRUD APIs, response shapes, validation, UI recommendations, and how admin content relates to the public help center.
Table of contents
- Feature overview
- Architecture
- Authentication & permissions
- RBAC setup & troubleshooting 403
- Data model
- Response envelopes
- Admin API reference
- Public API reference (preview only)
- Publish workflow (ACTIVE / INACTIVE)
- Categories & display order
- Recommended admin UI screens
- TypeScript types & API client
- Error handling
- Integration checklist
- Limitations & future work
- Quick reference
Feature overview
The FAQ system is a simple question / answer help center:
| Capability | Admin panel | Mobile / web app |
|---|---|---|
| List FAQs | All statuses (ACTIVE, INACTIVE) |
ACTIVE only |
| Create / edit / delete | Yes | No |
| Filter by category | Yes | Yes (public) |
| Sort order | display_order field |
Same order |
| Rich HTML answers | No (plain text) | Plain text |
Admin panel uses only /api/v1/admin/faqs* routes (authenticated + RBAC).
Public routes (/api/v1/faqs) are for learners and can be used in admin preview mode without auth.
Architecture
flowchart LR
subgraph AdminPanel["Admin panel"]
ListPage[List / filter]
FormPage[Create / edit form]
Preview[Preview public view]
end
subgraph API["Rezina API"]
AdminRoutes["/admin/faqs CRUD"]
PublicRoutes["/faqs read-only"]
end
subgraph DB["PostgreSQL"]
FAQsTable["faqs table"]
end
ListPage --> AdminRoutes
FormPage --> AdminRoutes
Preview --> PublicRoutes
AdminRoutes --> FAQsTable
PublicRoutes --> FAQsTable
- Migrations:
000059_faqs—faqstable000084_faq_rbac_permissions—faqs.*permission keys + role assignments forADMINandINSTRUCTOR
- Postman collection:
postman/FAQ-Management.postman_collection.json
Authentication & permissions
All admin FAQ endpoints require:
Authorization: Bearer <access_token>
Content-Type: application/json
How to obtain a token
| Login flow | Endpoint | Typical use |
|---|---|---|
| Team member (recommended for admin panel) | POST /api/v1/team/login |
Staff accounts in team_members |
| Platform admin user | POST /api/v1/auth/admin-login |
Users with users.role = ADMIN or SUPER_ADMIN |
Use the access_token from the login response on every admin FAQ request. Do not use a learner (STUDENT / OPEN_LEARNER) token.
RBAC permission keys
| Action | Permission | HTTP |
|---|---|---|
| List FAQs (admin) | faqs.list |
GET /admin/faqs |
| Get one FAQ (admin) | faqs.get |
GET /admin/faqs/:id |
| Create FAQ | faqs.create |
POST /admin/faqs |
| Update FAQ | faqs.update |
PUT /admin/faqs/:id |
| Delete FAQ | faqs.delete |
DELETE /admin/faqs/:id |
Default roles with FAQ access
After RBAC seeding (startup or sync), these system roles include all faqs.* permissions by default:
| RBAC role | FAQ admin access |
|---|---|
ADMIN |
Full access (also bypasses permission checks in middleware) |
SUPER_ADMIN |
Full access (bypass) |
INSTRUCTOR |
Full access via assigned faqs.* permissions |
Roles such as STUDENT, OPEN_LEARNER, and SUPPORT do not receive FAQ admin permissions by default.
Custom roles created in the RBAC UI must be assigned faqs.list, faqs.get, etc. explicitly.
Team role → JWT Role mapping
Team login embeds a platform Role in the JWT (decode at jwt.io and check the Role claim). This is what the API uses for RBAC—not the display label in the admin UI.
team_role (team_members) |
JWT Role |
FAQ admin |
|---|---|---|
SUPER_ADMIN |
SUPER_ADMIN |
Allowed (bypass) |
ADMIN |
ADMIN |
Allowed (bypass) |
CONTENT_MANAGER |
ADMIN |
Allowed (bypass) |
FINANCE, HR, ANALYST |
ADMIN |
Allowed (bypass) |
INSTRUCTOR |
INSTRUCTOR |
Allowed if faqs.* seeded (default after 000084) |
SUPPORT_AGENT |
SUPPORT |
Denied unless permissions added manually |
UI gating
Hide or disable FAQ menu items / buttons when the logged-in user lacks the corresponding permission. A 403 with message "You don't have permission to access this resource" means the JWT role does not have the required permission key (see RBAC setup & troubleshooting 403).
RBAC setup & troubleshooting 403
If GET /api/v1/admin/faqs returns 403 Forbidden, work through the steps below.
1. Confirm the JWT role
Decode the Bearer token and inspect Role:
{ "UserId": 42, "Role": "ADMIN", ... }
ADMIN/SUPER_ADMIN→ should always succeed on current backend builds.INSTRUCTOR→ succeeds after migration000084(or RBAC sync) assignsfaqs.*.SUPPORT,STUDENT, etc. → expected 403 for FAQ admin routes.
Fix: Log in with a team account whose team_role maps to ADMIN or INSTRUCTOR, or assign faqs.* to the user’s RBAC role.
2. Apply migrations
Ensure both FAQ migrations have run on the target database:
# however your deploy runs migrations, e.g.:
migrate -path db/migrations -database "$DATABASE_URL" up
Required versions:
000059— FAQ table000084— insertsfaqs.*permissions and links them toADMINandINSTRUCTOR
3. Sync RBAC permissions (no full redeploy)
If the API is already running but FAQ permissions were added after deploy, call:
POST /api/v1/rbac/permissions/sync
Authorization: Bearer <admin_or_super_admin_token>
This endpoint:
- Upserts all permission definitions from code (including
faqs.*) - Adds any missing default role-permission links (does not remove existing ones)
- Reloads the in-memory RBAC cache
Then re-login to obtain a fresh access token.
4. Restart the API (alternative)
On startup the server runs SeedPermissions, SeedDefaultRolePermissions, and reloads the RBAC cache. A restart after deploying FAQ code achieves the same result as step 3 for permission definitions and default role links.
5. Assign permissions to custom roles
For non-system roles, use the RBAC admin UI or API:
GET /api/v1/rbac/permissions
GET /api/v1/rbac/roles/{id}/permissions
PUT /api/v1/rbac/roles/{id}/permissions
Include permission IDs for: faqs.list, faqs.get, faqs.create, faqs.update, faqs.delete.
Common mistakes
| Mistake | Symptom |
|---|---|
| Using learner token | 403 on all admin routes |
| Old access token after RBAC sync | 403 until re-login |
Migration 000084 not applied |
INSTRUCTOR gets 403; permissions missing in DB |
SUPPORT_AGENT team account |
403 unless faqs.* granted to SUPPORT role |
| Calling API before deploy/restart | 404 or 403 depending on environment |
Data model
FAQ object (data in responses)
{
"id": 1,
"question": "How do I reset my password?",
"answer": "Go to login and click 'Forgot Password'.",
"category": "Account",
"display_order": 1,
"status": "ACTIVE",
"created_at": "2026-04-30 08:45:15.961307 +0000 UTC",
"updated_at": "2026-04-30 09:10:00.123456 +0000 UTC"
}
| Field | Type | Description |
|---|---|---|
id |
int64 | Primary key |
question |
string | FAQ question (required on create) |
answer |
string | FAQ answer, plain text (required on create) |
category |
string | omitted | Optional grouping label (free text, max 100 chars in DB) |
display_order |
int32 | Sort order (ascending). Default 0 on create |
status |
string | ACTIVE (published) or INACTIVE (hidden from public) |
created_at |
string | Timestamp string from server |
updated_at |
string | omitted | Set after first update |
Status values
| Value | Meaning | Visible on public /faqs? |
|---|---|---|
ACTIVE |
Published | Yes |
INACTIVE |
Draft / hidden | No |
List order (admin and public): display_order ASC, then id ASC.
Response envelopes
Success (domain.Response)
{
"message": "FAQs retrieved successfully",
"data": { },
"success": true,
"status_code": 200,
"metadata": null
}
Note: success and status_code in the JSON body may be 0 / false on some older responses; rely on HTTP status code as the source of truth.
Error (domain.ErrorResponse)
{
"message": "Validation failed",
"error": "question is required"
}
List payload (data)
{
"faqs": [ /* FAQ object[] */ ],
"total_count": 42
}
Admin API reference
Base path: {API_BASE_URL}/api/v1
1. List FAQs (admin)
GET /admin/faqs
Permission: faqs.list
Query parameters
| Param | Type | Default | Description |
|---|---|---|---|
status |
string | — | ACTIVE or INACTIVE (case-insensitive) |
category |
string | — | Exact category match |
limit |
int | 20 | Page size (max 200 enforced server-side) |
offset |
int | 0 | Pagination offset |
Omit status to return all FAQs (active + inactive).
Example
GET /api/v1/admin/faqs?status=ACTIVE&category=Account&limit=20&offset=0
Authorization: Bearer <token>
Response 200
{
"message": "FAQs retrieved successfully",
"data": {
"faqs": [
{
"id": 1,
"question": "How do I reset my password?",
"answer": "Go to login and click 'Forgot Password'.",
"category": "Account",
"display_order": 1,
"status": "ACTIVE",
"created_at": "2026-04-30 08:45:15.961307 +0000 UTC"
}
],
"total_count": 1
}
}
Pagination
page = 1-based page number
offset = (page - 1) * limit
total_pages = ceil(total_count / limit)
2. Get FAQ by ID (admin)
GET /admin/faqs/:id
Permission: faqs.get
Returns the FAQ regardless of status (unlike public GET).
Example
GET /api/v1/admin/faqs/1
Authorization: Bearer <token>
Response 200
{
"message": "FAQ retrieved successfully",
"data": {
"id": 1,
"question": "How do I reset my password?",
"answer": "Go to login and click 'Forgot Password'.",
"category": "Account",
"display_order": 1,
"status": "INACTIVE",
"created_at": "2026-04-30 08:45:15.961307 +0000 UTC",
"updated_at": "2026-05-01 10:00:00 +0000 UTC"
}
}
Errors
| HTTP | When |
|---|---|
400 |
Invalid ID |
404 |
FAQ not found |
Use this endpoint to populate the edit form.
3. Create FAQ
POST /admin/faqs
Permission: faqs.create
Request body
| Field | Type | Required | Description |
|---|---|---|---|
question |
string | Yes | Non-empty after trim |
answer |
string | Yes | Non-empty after trim |
category |
string | No | Optional label; empty string → stored as null |
display_order |
int32 | No | Default 0 |
status |
string | No | Default ACTIVE. Must be ACTIVE or INACTIVE |
Example
POST /api/v1/admin/faqs
Authorization: Bearer <token>
Content-Type: application/json
{
"question": "How do I reset my password?",
"answer": "Go to login and click 'Forgot Password'.",
"category": "Account",
"display_order": 1,
"status": "ACTIVE"
}
Response 201
{
"message": "FAQ created successfully",
"data": {
"id": 5,
"question": "How do I reset my password?",
"answer": "Go to login and click 'Forgot Password'.",
"category": "Account",
"display_order": 1,
"status": "ACTIVE",
"created_at": "2026-06-10 12:00:00 +0000 UTC"
}
}
Validation errors 400
| Error | Cause |
|---|---|
Validation failed |
Missing question or answer (validator) |
question is required |
Empty question after trim |
answer is required |
Empty answer after trim |
status must be one of ACTIVE, INACTIVE |
Invalid status |
4. Update FAQ
PUT /admin/faqs/:id
Permission: faqs.update
Partial update — send only fields you want to change.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
question |
string | No | Must not be empty if sent |
answer |
string | No | Must not be empty if sent |
category |
string | No | Send "" to clear category |
display_order |
int32 | No | New sort position |
status |
string | No | ACTIVE or INACTIVE |
Example — publish draft
{
"status": "ACTIVE"
}
Example — full edit
{
"question": "How can I reset my password?",
"answer": "Tap Forgot Password on the login screen and follow the email link.",
"category": "Account",
"display_order": 2,
"status": "ACTIVE"
}
Response 200
{
"message": "FAQ updated successfully",
"data": { /* updated FAQ object */ }
}
Errors
| HTTP | When |
|---|---|
400 |
Validation / invalid status |
404 |
FAQ not found |
5. Delete FAQ
DELETE /admin/faqs/:id
Permission: faqs.delete
Hard delete — row is removed from the database (not soft delete).
Example
DELETE /api/v1/admin/faqs/5
Authorization: Bearer <token>
Response 200
{
"message": "FAQ deleted successfully",
"data": {
"id": 5
}
}
Errors
| HTTP | When |
|---|---|
404 |
FAQ not found |
Show a confirmation dialog in the admin UI before calling delete.
Public API reference (preview only)
Use these in admin “Preview as learner” or to verify published content. No auth required.
| Method | Path | Behavior |
|---|---|---|
GET |
/api/v1/faqs |
List ACTIVE FAQs only |
GET |
/api/v1/faqs/:id |
Get one ACTIVE FAQ |
Query params for list: category, limit (default 50), offset (default 0).
If GET /faqs/:id returns 404 but admin GET returns the FAQ, it is likely INACTIVE (not published).
Publish workflow (ACTIVE / INACTIVE)
There is no separate publish endpoint. Publishing is done via status:
| Admin action | API call |
|---|---|
| Save as draft | POST or PUT with "status": "INACTIVE" |
| Publish | PUT with "status": "ACTIVE" |
| Unpublish (hide) | PUT with "status": "INACTIVE" |
Recommended UI:
- Status toggle or dropdown: Published (
ACTIVE) / Draft (INACTIVE) - List filter tabs: All | Published | Draft
- Badge on list rows: green = Active, gray = Inactive
Categories & display order
Categories
- Free-text string on each FAQ (e.g.
"Account","Billing","General"). - No backend API to list distinct categories.
- Admin panel pattern: load all FAQs (or a large page), derive unique categories client-side for filter dropdowns and create-form suggestions.
const categories = [...new Set(faqs.map(f => f.category).filter(Boolean))].sort();
Category filter on list uses exact match (case-sensitive in DB).
Display order
- Lower numbers appear first.
- Default
0for new FAQs if omitted. - No bulk reorder API — set
display_orderon create/update per item.
Admin panel patterns:
- Numeric input on create/edit form.
- Drag-and-drop reorder UI → on drop,
PUTeach affected FAQ with newdisplay_ordervalues (e.g. 1, 2, 3…). - When creating, suggest
max(display_order) + 1from current list.
Recommended admin UI screens
1. FAQ list page
Route example: /admin/help/faqs
| UI element | API |
|---|---|
| Table/cards of FAQs | GET /admin/faqs?limit=&offset= |
| Status filter | ?status=ACTIVE / INACTIVE |
| Category filter | ?category=Account |
| Search (client-side) | Filter loaded rows by question/answer text |
| “Add FAQ” button | Navigate to create form (faqs.create) |
| Edit row | GET /admin/faqs/:id → edit form |
| Delete row | DELETE /admin/faqs/:id with confirm |
| Publish toggle | PUT with status |
Columns: Question, Category, Order, Status, Updated, Actions
2. Create / edit form
Routes: /admin/help/faqs/new, /admin/help/faqs/:id/edit
| Field | Control |
|---|---|
| Question | Text input / textarea |
| Answer | Textarea (plain text; no HTML editor unless you add sanitization client-side only for display) |
| Category | Text input with datalist from known categories |
| Display order | Number input |
| Status | Select: Published / Draft |
| Action | API |
|---|---|
| Save (create) | POST /admin/faqs |
| Save (update) | PUT /admin/faqs/:id |
| Cancel | Back to list |
3. Preview (optional)
- Open public URL or call
GET /api/v1/faqsto show how learners see published FAQs. - Preview single item:
GET /api/v1/faqs/:id(only works whenACTIVE).
TypeScript types & API client
Types
export type FAQStatus = "ACTIVE" | "INACTIVE";
export interface FAQ {
id: number;
question: string;
answer: string;
category?: string | null;
display_order: number;
status: FAQStatus;
created_at: string;
updated_at?: string | null;
}
export interface FAQListData {
faqs: FAQ[];
total_count: number;
}
export interface ApiResponse<T> {
message: string;
data: T;
success?: boolean;
status_code?: number;
metadata?: unknown;
}
export interface ApiError {
message: string;
error?: string;
}
export interface CreateFAQInput {
question: string;
answer: string;
category?: string | null;
display_order?: number;
status?: FAQStatus;
}
export interface UpdateFAQInput {
question?: string;
answer?: string;
category?: string | null;
display_order?: number;
status?: FAQStatus;
}
Example client (fetch)
const API_BASE = import.meta.env.VITE_API_BASE_URL; // e.g. https://api.rezina.com
function authHeaders(token: string): HeadersInit {
return {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};
}
export async function listFAQsAdmin(
token: string,
params: { status?: FAQStatus; category?: string; limit?: number; offset?: number } = {}
): Promise<FAQListData> {
const qs = new URLSearchParams();
if (params.status) qs.set("status", params.status);
if (params.category) qs.set("category", params.category);
qs.set("limit", String(params.limit ?? 20));
qs.set("offset", String(params.offset ?? 0));
const res = await fetch(`${API_BASE}/api/v1/admin/faqs?${qs}`, {
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<FAQListData> = await res.json();
return body.data;
}
export async function getFAQAdmin(token: string, id: number): Promise<FAQ> {
const res = await fetch(`${API_BASE}/api/v1/admin/faqs/${id}`, {
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<FAQ> = await res.json();
return body.data;
}
export async function createFAQ(token: string, input: CreateFAQInput): Promise<FAQ> {
const res = await fetch(`${API_BASE}/api/v1/admin/faqs`, {
method: "POST",
headers: authHeaders(token),
body: JSON.stringify(input),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<FAQ> = await res.json();
return body.data;
}
export async function updateFAQ(
token: string,
id: number,
input: UpdateFAQInput
): Promise<FAQ> {
const res = await fetch(`${API_BASE}/api/v1/admin/faqs/${id}`, {
method: "PUT",
headers: authHeaders(token),
body: JSON.stringify(input),
});
if (!res.ok) throw await res.json();
const body: ApiResponse<FAQ> = await res.json();
return body.data;
}
export async function deleteFAQ(token: string, id: number): Promise<void> {
const res = await fetch(`${API_BASE}/api/v1/admin/faqs/${id}`, {
method: "DELETE",
headers: authHeaders(token),
});
if (!res.ok) throw await res.json();
}
React Query example (list + pagination)
const page = 1;
const limit = 20;
const { data, isLoading, error } = useQuery({
queryKey: ["admin-faqs", statusFilter, categoryFilter, page],
queryFn: () =>
listFAQsAdmin(token, {
status: statusFilter,
category: categoryFilter,
limit,
offset: (page - 1) * limit,
}),
});
Error handling
| HTTP | Typical message |
Admin UI action |
|---|---|---|
400 |
Validation failed / Failed to create FAQ | Show field errors from error |
401 |
Unauthorized | Redirect to login |
403 |
Forbidden — You don't have permission to access this resource |
Show “No permission”; verify JWT Role, migrations 000084, and RBAC sync |
404 |
FAQ not found | Toast + redirect to list |
500 |
Failed to list/get FAQ | Generic error + retry |
Always parse error field when present for detail.
Integration checklist
Backend / access
- Migration
000059_faqsapplied - Migration
000084_faq_rbac_permissionsapplied - RBAC seeded (
faqs.*onADMINandINSTRUCTOR; or custom role configured) - Team member or platform admin can obtain Bearer token (
POST /team/loginorPOST /auth/admin-login) - JWT
RoleisADMIN,SUPER_ADMIN, orINSTRUCTOR(or another role withfaqs.list) - If permissions were added after deploy:
POST /rbac/permissions/syncrun and user re-logged in
Admin panel — navigation
- Add “FAQs” or “Help center” menu item (gate on
faqs.list)
List page
GET /admin/faqswith pagination- Filters: status, category (optional)
- Status badges (ACTIVE / INACTIVE)
- Actions: Edit, Delete, quick publish/unpublish
Create / edit
- Form validation (question + answer required)
POST /admin/faqson createGET /admin/faqs/:idon edit loadPUT /admin/faqs/:idon save
Delete
- Confirmation modal
DELETE /admin/faqs/:id- Refresh list after delete
Optional enhancements
- Client-side search on question/answer
- Category datalist from existing FAQs
- Drag-and-drop reorder → multiple
PUTs withdisplay_order - Preview link using public
GET /faqs
QA scenarios
- Create ACTIVE FAQ → appears on public
GET /faqs - Create INACTIVE FAQ → hidden from public, visible in admin list
- Update status INACTIVE → ACTIVE → public visibility
- Delete FAQ → gone from admin and public
- Invalid status → 400 error shown in UI
Limitations & future work
| Topic | Current behavior |
|---|---|
| Reorder API | None — update display_order per FAQ |
| Category API | No list endpoint; derive client-side |
| Search | No server-side search |
| Rich text | Plain text answers only |
| i18n | Single language |
| Soft delete | Hard delete |
| Audit log | Not FAQ-specific |
If product needs HTML answers, server-side search, or bulk reorder, those require backend changes.
Quick reference
| Method | Path | Permission | Purpose |
|---|---|---|---|
GET |
/api/v1/admin/faqs |
faqs.list |
List (all statuses) |
GET |
/api/v1/admin/faqs/:id |
faqs.get |
Get one for edit |
POST |
/api/v1/admin/faqs |
faqs.create |
Create |
PUT |
/api/v1/admin/faqs/:id |
faqs.update |
Update / publish |
DELETE |
/api/v1/admin/faqs/:id |
faqs.delete |
Delete |
GET |
/api/v1/faqs |
— | Public list (preview) |
GET |
/api/v1/faqs/:id |
— | Public detail (preview) |
Postman: Import postman/FAQ-Management.postman_collection.json for executable examples and test scripts.