Prefix admin panel APIs and preserve customer API paths
This commit is contained in:
parent
c04440914c
commit
84d908e292
|
|
@ -92,7 +92,7 @@ cmd/main.go
|
|||
| `internal/web_server` | Routes, middleware, validators, cron |
|
||||
| `db/query` + `db/migrations` | SQL source of truth; `sqlc generate` → `gen/db` |
|
||||
|
||||
API base path: **`/api/v1`** (see Swagger `@BasePath` and route groups).
|
||||
API bases: **`/api/v1/admin`** for staff and **`/api/v1`** for customer web/mobile apps. See [API separation and migration](docs/api-audiences.md).
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -41,18 +41,21 @@ FROM notifications;
|
|||
SELECT *
|
||||
FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2 OFFSET $3;
|
||||
|
||||
-- name: GetUserNotificationCount :one
|
||||
SELECT COUNT(*)
|
||||
FROM notifications
|
||||
WHERE user_id = $1;
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type');
|
||||
|
||||
-- name: CountUnreadNotifications :one
|
||||
SELECT COUNT(*)
|
||||
FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
AND is_read = FALSE;
|
||||
|
||||
-- name: MarkNotificationAsRead :one
|
||||
|
|
@ -60,6 +63,7 @@ UPDATE notifications
|
|||
SET is_read = TRUE,
|
||||
read_at = NOW()
|
||||
WHERE id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type') AND user_id = sqlc.arg('requester_id')
|
||||
RETURNING *;
|
||||
|
||||
-- name: MarkAllUserNotificationsAsRead :exec
|
||||
|
|
@ -67,6 +71,7 @@ UPDATE notifications
|
|||
SET is_read = TRUE,
|
||||
read_at = NOW()
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
AND is_read = FALSE;
|
||||
|
||||
-- name: MarkNotificationAsUnread :one
|
||||
|
|
@ -74,6 +79,7 @@ UPDATE notifications
|
|||
SET is_read = FALSE,
|
||||
read_at = NULL
|
||||
WHERE id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type') AND user_id = sqlc.arg('requester_id')
|
||||
RETURNING *;
|
||||
|
||||
-- name: MarkAllUserNotificationsAsUnread :exec
|
||||
|
|
@ -81,21 +87,25 @@ UPDATE notifications
|
|||
SET is_read = FALSE,
|
||||
read_at = NULL
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
AND is_read = TRUE;
|
||||
|
||||
-- name: DeleteUserNotifications :exec
|
||||
DELETE FROM notifications
|
||||
WHERE user_id = $1;
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type');
|
||||
|
||||
-- name: DeleteUserInAppNotification :execrows
|
||||
DELETE FROM notifications
|
||||
WHERE id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
AND user_id = $2
|
||||
AND channel = 'in_app';
|
||||
|
||||
-- name: DeleteUserInAppNotificationsByIDs :execrows
|
||||
DELETE FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = sqlc.arg('receiver_type')
|
||||
AND channel = 'in_app'
|
||||
AND id = ANY($2::BIGINT[]);
|
||||
|
||||
|
|
|
|||
32
db/tests/notification-audiences.test.cjs
Normal file
32
db/tests/notification-audiences.test.cjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const { createRequire } = require('node:module');
|
||||
const { readFileSync } = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const assert = require('node:assert/strict');
|
||||
const load = process.env.REFERRAL_TEST_PACKAGE_JSON ? createRequire(process.env.REFERRAL_TEST_PACKAGE_JSON) : require;
|
||||
const { PGlite } = load('@electric-sql/pglite');
|
||||
(async()=>{
|
||||
const db=new PGlite();
|
||||
try {
|
||||
await db.exec(`CREATE TABLE notifications(id BIGINT PRIMARY KEY,user_id BIGINT,receiver_type TEXT,channel TEXT,is_read BOOLEAN DEFAULT FALSE,created_at TIMESTAMPTZ DEFAULT NOW(),read_at TIMESTAMPTZ);
|
||||
INSERT INTO notifications(id,user_id,receiver_type,channel) VALUES (1,42,'user','in_app'),(2,42,'team_member','in_app'),(3,99,'user','in_app');`);
|
||||
const source=readFileSync(path.join(__dirname,'../query/notification.sql'),'utf8');
|
||||
function sql(name){
|
||||
let statement=source.split('-- name: '+name+' :')[1].split('\n').slice(1).join('\n').split('-- name:')[0];
|
||||
const positional=[...statement.matchAll(/\$(\d+)/g)].map(match=>Number(match[1]));let next=Math.max(...positional)+1;
|
||||
for(const argument of ['receiver_type','requester_id']){if(statement.includes("sqlc.arg('"+argument+"')")){statement=statement.replaceAll("sqlc.arg('"+argument+"')",'$'+next++);}}
|
||||
return statement;
|
||||
}
|
||||
assert.deepEqual((await db.query(sql('GetUserNotifications'),[42,20,0,'user'])).rows.map(row=>row.id),[1]);
|
||||
assert.deepEqual((await db.query(sql('GetUserNotifications'),[42,20,0,'team_member'])).rows.map(row=>row.id),[2]);
|
||||
assert.equal((await db.query(sql('MarkNotificationAsRead'),[2,'user',42])).rows.length,0,'receiver collision');
|
||||
assert.equal((await db.query(sql('MarkNotificationAsRead'),[3,'user',42])).rows.length,0,'other customer');
|
||||
await db.query(sql('MarkAllUserNotificationsAsRead'),[42,'user']);
|
||||
assert.equal((await db.query('SELECT is_read FROM notifications WHERE id=1')).rows[0].is_read,true);
|
||||
assert.equal((await db.query('SELECT is_read FROM notifications WHERE id=2')).rows[0].is_read,false,'staff row unchanged');
|
||||
assert.equal(Number((await db.query(sql('CountUnreadNotifications'),[42,'team_member'])).rows[0].count),1);
|
||||
assert.equal((await db.query(sql('DeleteUserInAppNotification'),[2,42,'user'])).affectedRows,0);
|
||||
await db.query(sql('DeleteUserNotifications'),[42,'user']);
|
||||
assert.deepEqual((await db.query('SELECT id FROM notifications ORDER BY id')).rows.map(row=>row.id),[2,3]);
|
||||
console.log('Notification SQL audience isolation checks passed.');
|
||||
}finally{await db.close()}
|
||||
})().catch(error=>{console.error(error);process.exitCode=1});
|
||||
74
docs/api-audiences.md
Normal file
74
docs/api-audiences.md
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# 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`.
|
||||
2006
docs/api-route-migration.json
Normal file
2006
docs/api-route-migration.json
Normal file
File diff suppressed because it is too large
Load Diff
15465
docs/docs.go
15465
docs/docs.go
File diff suppressed because it is too large
Load Diff
15465
docs/swagger.json
15465
docs/swagger.json
File diff suppressed because it is too large
Load Diff
10259
docs/swagger.yaml
10259
docs/swagger.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -15,11 +15,17 @@ const CountUnreadNotifications = `-- name: CountUnreadNotifications :one
|
|||
SELECT COUNT(*)
|
||||
FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $2
|
||||
AND is_read = FALSE
|
||||
`
|
||||
|
||||
func (q *Queries) CountUnreadNotifications(ctx context.Context, userID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountUnreadNotifications, userID)
|
||||
type CountUnreadNotificationsParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) CountUnreadNotifications(ctx context.Context, arg CountUnreadNotificationsParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, CountUnreadNotifications, arg.UserID, arg.ReceiverType)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
|
|
@ -92,17 +98,19 @@ func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotification
|
|||
const DeleteUserInAppNotification = `-- name: DeleteUserInAppNotification :execrows
|
||||
DELETE FROM notifications
|
||||
WHERE id = $1
|
||||
AND receiver_type = $3
|
||||
AND user_id = $2
|
||||
AND channel = 'in_app'
|
||||
`
|
||||
|
||||
type DeleteUserInAppNotificationParams struct {
|
||||
ID int64 `json:"id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ID int64 `json:"id"`
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserInAppNotification(ctx context.Context, arg DeleteUserInAppNotificationParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, DeleteUserInAppNotification, arg.ID, arg.UserID)
|
||||
result, err := q.db.Exec(ctx, DeleteUserInAppNotification, arg.ID, arg.UserID, arg.ReceiverType)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -112,17 +120,19 @@ func (q *Queries) DeleteUserInAppNotification(ctx context.Context, arg DeleteUse
|
|||
const DeleteUserInAppNotificationsByIDs = `-- name: DeleteUserInAppNotificationsByIDs :execrows
|
||||
DELETE FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $3
|
||||
AND channel = 'in_app'
|
||||
AND id = ANY($2::BIGINT[])
|
||||
`
|
||||
|
||||
type DeleteUserInAppNotificationsByIDsParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
Column2 []int64 `json:"column_2"`
|
||||
UserID int64 `json:"user_id"`
|
||||
Column2 []int64 `json:"column_2"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserInAppNotificationsByIDs(ctx context.Context, arg DeleteUserInAppNotificationsByIDsParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, DeleteUserInAppNotificationsByIDs, arg.UserID, arg.Column2)
|
||||
result, err := q.db.Exec(ctx, DeleteUserInAppNotificationsByIDs, arg.UserID, arg.Column2, arg.ReceiverType)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
@ -132,10 +142,16 @@ func (q *Queries) DeleteUserInAppNotificationsByIDs(ctx context.Context, arg Del
|
|||
const DeleteUserNotifications = `-- name: DeleteUserNotifications :exec
|
||||
DELETE FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $2
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteUserNotifications(ctx context.Context, userID int64) error {
|
||||
_, err := q.db.Exec(ctx, DeleteUserNotifications, userID)
|
||||
type DeleteUserNotificationsParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteUserNotifications(ctx context.Context, arg DeleteUserNotificationsParams) error {
|
||||
_, err := q.db.Exec(ctx, DeleteUserNotifications, arg.UserID, arg.ReceiverType)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -329,10 +345,16 @@ const GetUserNotificationCount = `-- name: GetUserNotificationCount :one
|
|||
SELECT COUNT(*)
|
||||
FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $2
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserNotificationCount(ctx context.Context, userID int64) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, GetUserNotificationCount, userID)
|
||||
type GetUserNotificationCountParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserNotificationCount(ctx context.Context, arg GetUserNotificationCountParams) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, GetUserNotificationCount, arg.UserID, arg.ReceiverType)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
|
|
@ -342,18 +364,25 @@ const GetUserNotifications = `-- name: GetUserNotifications :many
|
|||
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
|
||||
FROM notifications
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $4
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2 OFFSET $3
|
||||
`
|
||||
|
||||
type GetUserNotificationsParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
UserID int64 `json:"user_id"`
|
||||
Limit int32 `json:"limit"`
|
||||
Offset int32 `json:"offset"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserNotifications(ctx context.Context, arg GetUserNotificationsParams) ([]Notification, error) {
|
||||
rows, err := q.db.Query(ctx, GetUserNotifications, arg.UserID, arg.Limit, arg.Offset)
|
||||
rows, err := q.db.Query(ctx, GetUserNotifications,
|
||||
arg.UserID,
|
||||
arg.Limit,
|
||||
arg.Offset,
|
||||
arg.ReceiverType,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -390,11 +419,17 @@ UPDATE notifications
|
|||
SET is_read = TRUE,
|
||||
read_at = NOW()
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $2
|
||||
AND is_read = FALSE
|
||||
`
|
||||
|
||||
func (q *Queries) MarkAllUserNotificationsAsRead(ctx context.Context, userID int64) error {
|
||||
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsRead, userID)
|
||||
type MarkAllUserNotificationsAsReadParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkAllUserNotificationsAsRead(ctx context.Context, arg MarkAllUserNotificationsAsReadParams) error {
|
||||
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsRead, arg.UserID, arg.ReceiverType)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -403,11 +438,17 @@ UPDATE notifications
|
|||
SET is_read = FALSE,
|
||||
read_at = NULL
|
||||
WHERE user_id = $1
|
||||
AND receiver_type = $2
|
||||
AND is_read = TRUE
|
||||
`
|
||||
|
||||
func (q *Queries) MarkAllUserNotificationsAsUnread(ctx context.Context, userID int64) error {
|
||||
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsUnread, userID)
|
||||
type MarkAllUserNotificationsAsUnreadParams struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkAllUserNotificationsAsUnread(ctx context.Context, arg MarkAllUserNotificationsAsUnreadParams) error {
|
||||
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsUnread, arg.UserID, arg.ReceiverType)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -416,11 +457,18 @@ UPDATE notifications
|
|||
SET is_read = TRUE,
|
||||
read_at = NOW()
|
||||
WHERE id = $1
|
||||
AND receiver_type = $2 AND user_id = $3
|
||||
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
|
||||
`
|
||||
|
||||
func (q *Queries) MarkNotificationAsRead(ctx context.Context, id int64) (Notification, error) {
|
||||
row := q.db.QueryRow(ctx, MarkNotificationAsRead, id)
|
||||
type MarkNotificationAsReadParams struct {
|
||||
ID int64 `json:"id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
RequesterID int64 `json:"requester_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkNotificationAsRead(ctx context.Context, arg MarkNotificationAsReadParams) (Notification, error) {
|
||||
row := q.db.QueryRow(ctx, MarkNotificationAsRead, arg.ID, arg.ReceiverType, arg.RequesterID)
|
||||
var i Notification
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
|
|
@ -444,11 +492,18 @@ UPDATE notifications
|
|||
SET is_read = FALSE,
|
||||
read_at = NULL
|
||||
WHERE id = $1
|
||||
AND receiver_type = $2 AND user_id = $3
|
||||
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
|
||||
`
|
||||
|
||||
func (q *Queries) MarkNotificationAsUnread(ctx context.Context, id int64) (Notification, error) {
|
||||
row := q.db.QueryRow(ctx, MarkNotificationAsUnread, id)
|
||||
type MarkNotificationAsUnreadParams struct {
|
||||
ID int64 `json:"id"`
|
||||
ReceiverType string `json:"receiver_type"`
|
||||
RequesterID int64 `json:"requester_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) MarkNotificationAsUnread(ctx context.Context, arg MarkNotificationAsUnreadParams) (Notification, error) {
|
||||
row := q.db.QueryRow(ctx, MarkNotificationAsUnread, arg.ID, arg.ReceiverType, arg.RequesterID)
|
||||
var i Notification
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
|
|
|
|||
19
internal/domain/notification_scope.go
Normal file
19
internal/domain/notification_scope.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package domain
|
||||
|
||||
import "context"
|
||||
|
||||
type NotificationScope struct {
|
||||
UserID int64
|
||||
ReceiverType ReceiverType
|
||||
}
|
||||
type notificationScopeKey struct{}
|
||||
|
||||
func WithNotificationScope(ctx context.Context, userID int64, receiver ReceiverType) context.Context {
|
||||
return context.WithValue(ctx, notificationScopeKey{}, NotificationScope{UserID: userID, ReceiverType: receiver})
|
||||
}
|
||||
func NotificationScopeFromContext(ctx context.Context) NotificationScope {
|
||||
if scope, ok := ctx.Value(notificationScopeKey{}).(NotificationScope); ok {
|
||||
return scope
|
||||
}
|
||||
return NotificationScope{ReceiverType: ReceiverTypeUser}
|
||||
}
|
||||
|
|
@ -76,9 +76,10 @@ func (r *Store) GetUserNotifications(
|
|||
) ([]domain.Notification, int64, error) {
|
||||
|
||||
params := dbgen.GetUserNotificationsParams{
|
||||
UserID: userID,
|
||||
Limit: int32(limit),
|
||||
Offset: int32(offset),
|
||||
ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType),
|
||||
UserID: userID,
|
||||
Limit: int32(limit),
|
||||
Offset: int32(offset),
|
||||
}
|
||||
|
||||
rows, err := r.queries.GetUserNotifications(ctx, params)
|
||||
|
|
@ -86,7 +87,7 @@ func (r *Store) GetUserNotifications(
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
total, err := r.queries.GetUserNotificationCount(ctx, userID)
|
||||
total, err := r.queries.GetUserNotificationCount(ctx, dbgen.GetUserNotificationCountParams{UserID: userID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
|
@ -179,7 +180,7 @@ func (r *Store) CountUnreadNotifications(
|
|||
ctx context.Context,
|
||||
userID int64,
|
||||
) (int64, error) {
|
||||
return r.queries.CountUnreadNotifications(ctx, userID)
|
||||
return r.queries.CountUnreadNotifications(ctx, dbgen.CountUnreadNotificationsParams{UserID: userID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
}
|
||||
|
||||
/* =========================
|
||||
|
|
@ -191,7 +192,7 @@ func (r *Store) MarkNotificationAsRead(
|
|||
id int64,
|
||||
) (*domain.Notification, error) {
|
||||
|
||||
dbNotif, err := r.queries.MarkNotificationAsRead(ctx, id)
|
||||
dbNotif, err := r.queries.MarkNotificationAsRead(ctx, dbgen.MarkNotificationAsReadParams{ID: id, RequesterID: domain.NotificationScopeFromContext(ctx).UserID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -203,7 +204,7 @@ func (r *Store) MarkAllUserNotificationsAsRead(
|
|||
ctx context.Context,
|
||||
userID int64,
|
||||
) error {
|
||||
return r.queries.MarkAllUserNotificationsAsRead(ctx, userID)
|
||||
return r.queries.MarkAllUserNotificationsAsRead(ctx, dbgen.MarkAllUserNotificationsAsReadParams{UserID: userID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
}
|
||||
|
||||
func (r *Store) MarkNotificationAsUnread(
|
||||
|
|
@ -211,7 +212,7 @@ func (r *Store) MarkNotificationAsUnread(
|
|||
id int64,
|
||||
) (*domain.Notification, error) {
|
||||
|
||||
dbNotif, err := r.queries.MarkNotificationAsUnread(ctx, id)
|
||||
dbNotif, err := r.queries.MarkNotificationAsUnread(ctx, dbgen.MarkNotificationAsUnreadParams{ID: id, RequesterID: domain.NotificationScopeFromContext(ctx).UserID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -223,7 +224,7 @@ func (r *Store) MarkAllUserNotificationsAsUnread(
|
|||
ctx context.Context,
|
||||
userID int64,
|
||||
) error {
|
||||
return r.queries.MarkAllUserNotificationsAsUnread(ctx, userID)
|
||||
return r.queries.MarkAllUserNotificationsAsUnread(ctx, dbgen.MarkAllUserNotificationsAsUnreadParams{UserID: userID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
}
|
||||
|
||||
/* =========================
|
||||
|
|
@ -234,7 +235,7 @@ func (r *Store) DeleteUserNotifications(
|
|||
ctx context.Context,
|
||||
userID int64,
|
||||
) error {
|
||||
return r.queries.DeleteUserNotifications(ctx, userID)
|
||||
return r.queries.DeleteUserNotifications(ctx, dbgen.DeleteUserNotificationsParams{UserID: userID, ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType)})
|
||||
}
|
||||
|
||||
func (r *Store) DeleteUserInAppNotification(
|
||||
|
|
@ -242,8 +243,9 @@ func (r *Store) DeleteUserInAppNotification(
|
|||
id, userID int64,
|
||||
) (int64, error) {
|
||||
return r.queries.DeleteUserInAppNotification(ctx, dbgen.DeleteUserInAppNotificationParams{
|
||||
ID: id,
|
||||
UserID: userID,
|
||||
ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType),
|
||||
ID: id,
|
||||
UserID: userID,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -253,8 +255,9 @@ func (r *Store) DeleteUserInAppNotificationsByIDs(
|
|||
ids []int64,
|
||||
) (int64, error) {
|
||||
return r.queries.DeleteUserInAppNotificationsByIDs(ctx, dbgen.DeleteUserInAppNotificationsByIDsParams{
|
||||
UserID: userID,
|
||||
Column2: ids,
|
||||
ReceiverType: string(domain.NotificationScopeFromContext(ctx).ReceiverType),
|
||||
UserID: userID,
|
||||
Column2: ids,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,18 +65,18 @@ func New(
|
|||
hub := ws.NewNotificationHub()
|
||||
|
||||
svc := &Service{
|
||||
store: store,
|
||||
Hub: hub,
|
||||
mongoLogger: mongoLogger,
|
||||
logger: logger,
|
||||
connections: sync.Map{},
|
||||
notificationCh: make(chan *domain.Notification, 1000),
|
||||
stopCh: make(chan struct{}),
|
||||
messengerSvc: messengerSvc,
|
||||
userSvc: userSvc,
|
||||
teamStore: teamStore,
|
||||
store: store,
|
||||
Hub: hub,
|
||||
mongoLogger: mongoLogger,
|
||||
logger: logger,
|
||||
connections: sync.Map{},
|
||||
notificationCh: make(chan *domain.Notification, 1000),
|
||||
stopCh: make(chan struct{}),
|
||||
messengerSvc: messengerSvc,
|
||||
userSvc: userSvc,
|
||||
teamStore: teamStore,
|
||||
emailTemplateSvc: emailTemplateSvc,
|
||||
config: cfg,
|
||||
config: cfg,
|
||||
}
|
||||
|
||||
mongoLogger.Info("FCM credentials config at startup",
|
||||
|
|
@ -277,9 +277,10 @@ func (s *Service) SendNotification(ctx context.Context, notification *domain.Not
|
|||
|
||||
if notification.DeliveryChannel == domain.DeliveryChannelInApp {
|
||||
s.Hub.Broadcast <- map[string]interface{}{
|
||||
"type": "CREATED_NOTIFICATION",
|
||||
"recipient_id": notification.RecipientID,
|
||||
"payload": notification,
|
||||
"type": "CREATED_NOTIFICATION",
|
||||
"recipient_id": notification.RecipientID,
|
||||
"receiver_type": notification.ReceiverType,
|
||||
"payload": notification,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +347,8 @@ func (s *Service) GetNotificationByID(ctx context.Context, id, requesterID int64
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if !allowAll && notification.RecipientID != requesterID {
|
||||
scope := domain.NotificationScopeFromContext(ctx)
|
||||
if !allowAll && (notification.RecipientID != requesterID || (notification.ReceiverType != "" && notification.ReceiverType != scope.ReceiverType)) {
|
||||
return nil, ErrNotificationForbidden
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,3 +91,15 @@ func TestGetNotificationByID_notFound(t *testing.T) {
|
|||
t.Fatalf("expected ErrNotificationNotFound, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetNotificationByID_DistinguishesReceiverTypes(t *testing.T) {
|
||||
svc := &Service{store: &getNotificationStoreStub{notification: &domain.Notification{ID: "10", RecipientID: 42, ReceiverType: domain.ReceiverTypeTeamMember}}}
|
||||
customerCtx := domain.WithNotificationScope(context.Background(), 42, domain.ReceiverTypeUser)
|
||||
if _, err := svc.GetNotificationByID(customerCtx, 10, 42, false); !errors.Is(err, ErrNotificationForbidden) {
|
||||
t.Fatalf("customer read a team member notification: %v", err)
|
||||
}
|
||||
staffCtx := domain.WithNotificationScope(context.Background(), 42, domain.ReceiverTypeTeamMember)
|
||||
if _, err := svc.GetNotificationByID(staffCtx, 10, 42, false); err != nil {
|
||||
t.Fatalf("staff could not read own notification: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
46
internal/web_server/api_audience.go
Normal file
46
internal/web_server/api_audience.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/domain"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
const apiAudienceKey = "api_audience"
|
||||
|
||||
// apiAudience marks public and authenticated requests so shared handlers can apply audience defaults.
|
||||
func apiAudience(audience string) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error { c.Locals(apiAudienceKey, audience); return c.Next() }
|
||||
}
|
||||
|
||||
func validateAPIAudience(role domain.Role, audience string) error {
|
||||
if !role.IsValid() {
|
||||
return fiber.NewError(fiber.StatusForbidden, "Unknown account role")
|
||||
}
|
||||
switch audience {
|
||||
case "admin":
|
||||
if role.IsCustomerLearnerRole() {
|
||||
return fiber.NewError(fiber.StatusForbidden, "A staff account is required for the admin API")
|
||||
}
|
||||
case "client":
|
||||
if !role.IsCustomerLearnerRole() {
|
||||
return fiber.NewError(fiber.StatusForbidden, "A customer account is required for the client API")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (a *App) adminAuthMiddleware(c *fiber.Ctx) error {
|
||||
c.Locals(apiAudienceKey, "admin")
|
||||
return a.authMiddleware(c)
|
||||
}
|
||||
func (a *App) clientAuthMiddleware(c *fiber.Ctx) error {
|
||||
c.Locals(apiAudienceKey, "client")
|
||||
return a.authMiddleware(c)
|
||||
}
|
||||
func (a *App) adminWebsocketAuthMiddleware(c *fiber.Ctx) error {
|
||||
c.Locals(apiAudienceKey, "admin")
|
||||
return a.WebsocketAuthMiddleware(c)
|
||||
}
|
||||
func (a *App) clientWebsocketAuthMiddleware(c *fiber.Ctx) error {
|
||||
c.Locals(apiAudienceKey, "client")
|
||||
return a.WebsocketAuthMiddleware(c)
|
||||
}
|
||||
126
internal/web_server/api_audience_test.go
Normal file
126
internal/web_server/api_audience_test.go
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/domain"
|
||||
"Rezina-Backend/internal/ports"
|
||||
userservice "Rezina-Backend/internal/services/user"
|
||||
"Rezina-Backend/internal/web_server/handlers"
|
||||
jwtutil "Rezina-Backend/internal/web_server/jwt"
|
||||
"context"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"go.uber.org/zap"
|
||||
"log/slog"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type audienceUserStore struct {
|
||||
ports.UserStore
|
||||
status domain.UserStatus
|
||||
}
|
||||
|
||||
func (s audienceUserStore) GetUserByID(context.Context, int64) (domain.User, error) {
|
||||
return domain.User{ID: 42, Status: s.status}, nil
|
||||
}
|
||||
func audienceTestApp(status domain.UserStatus) *App {
|
||||
return &App{JwtConfig: jwtutil.JwtConfig{JwtAccessKey: "audience-test-key"}, mongoLoggerSvc: zap.NewNop(), logger: slog.Default(), userSvc: userservice.NewService(nil, audienceUserStore{status: status}, nil, nil, nil, nil, nil)}
|
||||
}
|
||||
func audienceToken(t *testing.T, a *App, role domain.Role) string {
|
||||
t.Helper()
|
||||
token, err := jwtutil.CreateJwt(42, role, a.JwtConfig.JwtAccessKey, 3600)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return token
|
||||
}
|
||||
func TestAPIAudienceAuthentication(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, audience string
|
||||
role domain.Role
|
||||
status domain.UserStatus
|
||||
want int
|
||||
}{
|
||||
{"student client", "client", domain.RoleStudent, domain.UserStatusActive, 204},
|
||||
{"open learner client", "client", domain.RoleOpenLearner, domain.UserStatusActive, 204},
|
||||
{"admin panel", "admin", domain.RoleAdmin, domain.UserStatusActive, 204},
|
||||
{"content manager panel", "admin", domain.RoleContentManager, domain.UserStatusActive, 204},
|
||||
{"instructor panel", "admin", domain.RoleInstructor, domain.UserStatusActive, 204},
|
||||
{"student cannot administer", "admin", domain.RoleStudent, domain.UserStatusActive, 403},
|
||||
{"open learner cannot administer", "admin", domain.RoleOpenLearner, domain.UserStatusActive, 403},
|
||||
{"admin cannot act as customer", "client", domain.RoleAdmin, domain.UserStatusActive, 403},
|
||||
{"instructor cannot act as customer", "client", domain.RoleInstructor, domain.UserStatusActive, 403},
|
||||
{"suspended customer", "client", domain.RoleStudent, domain.UserStatusSuspended, 403},
|
||||
{"unknown role", "admin", domain.Role("UNKNOWN"), domain.UserStatusActive, 403},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
a := audienceTestApp(tc.status)
|
||||
server := fiber.New()
|
||||
auth := a.adminAuthMiddleware
|
||||
if tc.audience == "client" {
|
||||
auth = a.clientAuthMiddleware
|
||||
}
|
||||
server.Get("/me", auth, func(c *fiber.Ctx) error { return c.SendStatus(204) })
|
||||
request := httptest.NewRequest("GET", "/me", nil)
|
||||
request.Header.Set("Authorization", "Bearer "+audienceToken(t, a, tc.role))
|
||||
response, err := server.Test(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode != tc.want {
|
||||
t.Fatalf("status=%d want=%d", response.StatusCode, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestRegisteredAPISurfaces(t *testing.T) {
|
||||
a := audienceTestApp(domain.UserStatusActive)
|
||||
server := fiber.New()
|
||||
h := &handlers.Handler{}
|
||||
api := server.Group("/api/v1")
|
||||
a.initAdminRoutes(api.Group("/admin", apiAudience("admin")), h)
|
||||
a.initClientRoutes(api, h)
|
||||
a.initIntegrationRoutes(api, h)
|
||||
routes := map[string]bool{}
|
||||
for _, stack := range server.Stack() {
|
||||
for _, route := range stack {
|
||||
routes[route.Method+" "+route.Path] = true
|
||||
}
|
||||
}
|
||||
for _, route := range []string{"POST /api/v1/admin/exam-prep/catalog-courses", "GET /api/v1/exam-prep/catalog-courses", "POST /api/v1/admin/team/login", "POST /api/v1/user/register", "GET /api/v1/admin/users", "GET /api/v1/referrals/me", "POST /api/v1/payments/webhook", "GET /api/v1/payments/chapa/callback", "GET /api/v1/auth/google/callback"} {
|
||||
if !routes[route] {
|
||||
t.Errorf("missing route %s", route)
|
||||
}
|
||||
}
|
||||
for _, route := range []string{"POST /api/v1/exam-prep/catalog-courses", "GET /api/v1/questions", "GET /api/v1/users", "GET /api/v1/rbac/roles", "POST /api/v1/team/login", "GET /api/v1/questions", "POST /api/v1/admin/user/register", "GET /api/v1/client/subscriptions/me", "POST /api/v1/admin/subscriptions/checkout"} {
|
||||
if routes[route] {
|
||||
t.Errorf("unexpected route %s", route)
|
||||
}
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
path string
|
||||
role domain.Role
|
||||
}{
|
||||
{"/api/v1/admin/users", domain.RoleStudent},
|
||||
{"/api/v1/admin/exam-prep/catalog-courses", domain.RoleOpenLearner},
|
||||
{"/api/v1/subscriptions/me", domain.RoleAdmin},
|
||||
{"/api/v1/admin/ws/connect?token=", domain.RoleStudent},
|
||||
{"/api/v1/ws/connect?token=", domain.RoleAdmin},
|
||||
} {
|
||||
token := audienceToken(t, a, tc.role)
|
||||
path := tc.path
|
||||
if path[len(path)-1:] == "=" {
|
||||
path += token
|
||||
}
|
||||
request := httptest.NewRequest("GET", path, nil)
|
||||
request.Header.Set("Authorization", "Bearer "+token)
|
||||
response, err := server.Test(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response.Body.Close()
|
||||
if response.StatusCode != 403 {
|
||||
t.Errorf("%s returned %d", tc.path, response.StatusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
71
internal/web_server/api_docs.go
Normal file
71
internal/web_server/api_docs.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/docs"
|
||||
"encoding/json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func specificationPathMatchesAudience(path, audience string) bool {
|
||||
isAdmin := strings.HasPrefix(path, "/api/v1/admin/")
|
||||
if audience == "admin" {
|
||||
return isAdmin
|
||||
}
|
||||
if audience != "client" || !strings.HasPrefix(path, "/api/v1/") || isAdmin {
|
||||
return false
|
||||
}
|
||||
switch path {
|
||||
case "/api/v1/payments/webhook", "/api/v1/payments/chapa/callback", "/api/v1/payments/chapa/success", "/api/v1/payments/arifpay/success", "/api/v1/auth/google/callback":
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// audienceSpecification exposes only an audience's routes and referenced schemas.
|
||||
func audienceSpecification(audience string) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
var spec map[string]any
|
||||
if err := json.Unmarshal([]byte(docs.SwaggerInfo.ReadDoc()), &spec); err != nil {
|
||||
return fiber.NewError(500, "Unable to load API documentation")
|
||||
}
|
||||
paths, _ := spec["paths"].(map[string]any)
|
||||
selected := map[string]any{}
|
||||
for path, operation := range paths {
|
||||
if specificationPathMatchesAudience(path, audience) {
|
||||
selected[path] = operation
|
||||
}
|
||||
}
|
||||
spec["paths"] = selected
|
||||
if info, ok := spec["info"].(map[string]any); ok {
|
||||
info["title"] = "Rezina " + audience + " API"
|
||||
}
|
||||
definitions, _ := spec["definitions"].(map[string]any)
|
||||
used := map[string]any{}
|
||||
var collect func(any)
|
||||
collect = func(value any) {
|
||||
switch node := value.(type) {
|
||||
case map[string]any:
|
||||
if ref, ok := node["$ref"].(string); ok && strings.HasPrefix(ref, "#/definitions/") {
|
||||
name := strings.TrimPrefix(ref, "#/definitions/")
|
||||
if _, seen := used[name]; !seen {
|
||||
if definition, found := definitions[name]; found {
|
||||
used[name] = definition
|
||||
collect(definition)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, child := range node {
|
||||
collect(child)
|
||||
}
|
||||
case []any:
|
||||
for _, child := range node {
|
||||
collect(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
collect(selected)
|
||||
spec["definitions"] = used
|
||||
return c.JSON(spec)
|
||||
}
|
||||
}
|
||||
37
internal/web_server/api_docs_test.go
Normal file
37
internal/web_server/api_docs_test.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAudienceSpecifications(t *testing.T) {
|
||||
for _, audience := range []string{"admin", "client"} {
|
||||
t.Run(audience, func(t *testing.T) {
|
||||
server := fiber.New()
|
||||
server.Get("/doc", audienceSpecification(audience))
|
||||
response, err := server.Test(httptest.NewRequest("GET", "/doc", nil))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer response.Body.Close()
|
||||
var spec struct {
|
||||
Paths map[string]any `json:"paths"`
|
||||
}
|
||||
if err := json.NewDecoder(response.Body).Decode(&spec); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(spec.Paths) == 0 {
|
||||
t.Fatal("empty API specification")
|
||||
}
|
||||
for path := range spec.Paths {
|
||||
if (audience == "admin" && !strings.HasPrefix(path, "/api/v1/admin/")) || (audience == "client" && (!strings.HasPrefix(path, "/api/v1/") || strings.HasPrefix(path, "/api/v1/admin/"))) {
|
||||
t.Errorf("foreign path %s", path)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ type activityLogListRes struct {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/activity-logs [get]
|
||||
// @Router /api/v1/admin/activity-logs [get]
|
||||
func (h *Handler) GetActivityLogs(c *fiber.Ctx) error {
|
||||
var filter domain.ActivityLogFilter
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ func (h *Handler) GetActivityLogs(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/activity-logs/{id} [get]
|
||||
// @Router /api/v1/admin/activity-logs/{id} [get]
|
||||
func (h *Handler) GetActivityLogByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ type CreateAdminReq struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/admin [post]
|
||||
// @Router /api/v1/admin/admins [post]
|
||||
func (h *Handler) CreateAdmin(c *fiber.Ctx) error {
|
||||
// var OrganizationID domain.ValidInt64
|
||||
var req CreateAdminReq
|
||||
|
|
@ -172,7 +172,7 @@ type AdminRes struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/admin [get]
|
||||
// @Router /api/v1/admin/admins [get]
|
||||
func (h *Handler) GetAllAdmins(c *fiber.Ctx) error {
|
||||
searchQuery := c.Query("query")
|
||||
searchString := domain.ValidString{
|
||||
|
|
@ -288,7 +288,7 @@ func (h *Handler) GetAllAdmins(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/admin/{id} [get]
|
||||
// @Router /api/v1/admin/admins/{id} [get]
|
||||
func (h *Handler) GetAdminByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -342,7 +342,7 @@ type updateAdminReq struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/admin/{id} [put]
|
||||
// @Router /api/v1/admin/admins/{id} [put]
|
||||
func (h *Handler) UpdateAdmin(c *fiber.Ctx) error {
|
||||
var req updateAdminReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -435,7 +435,7 @@ func (h *Handler) bulkAccountsRoleFromPath(c *fiber.Ctx) (roleKey string, ok boo
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/roles/{role}/bulk-deactivate [post]
|
||||
// @Router /api/v1/admin/admins/roles/{role}/bulk-deactivate [post]
|
||||
func (h *Handler) BulkDeactivateAccountsByRole(c *fiber.Ctx) error {
|
||||
callerRole, ok := c.Locals("role").(domain.Role)
|
||||
if !ok {
|
||||
|
|
@ -559,7 +559,7 @@ func (h *Handler) BulkDeactivateAccountsByRole(c *fiber.Ctx) error {
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/roles/{role}/bulk-reactivate [post]
|
||||
// @Router /api/v1/admin/admins/roles/{role}/bulk-reactivate [post]
|
||||
func (h *Handler) BulkReactivateAccountsByRole(c *fiber.Ctx) error {
|
||||
callerRole, ok := c.Locals("role").(domain.Role)
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ func (h *Handler) ExportAdminPaymentsCSV(c *fiber.Ctx) error {
|
|||
// @Summary Export users as CSV (admin)
|
||||
// @Tags user
|
||||
// @Produce text/csv
|
||||
// @Router /api/v1/users/export [get]
|
||||
// @Router /api/v1/admin/users/export [get]
|
||||
func (h *Handler) ExportUsersCSV(c *fiber.Ctx) error {
|
||||
filter, err := parseUserListFilter(c)
|
||||
if err != nil {
|
||||
|
|
@ -244,7 +244,7 @@ func (h *Handler) ExportUsersCSV(c *fiber.Ctx) error {
|
|||
// @Summary Export activity logs as CSV (admin)
|
||||
// @Tags activity-logs
|
||||
// @Produce text/csv
|
||||
// @Router /api/v1/activity-logs/export [get]
|
||||
// @Router /api/v1/admin/activity-logs/export [get]
|
||||
func (h *Handler) ExportActivityLogsCSV(c *fiber.Ctx) error {
|
||||
filter, err := parseActivityLogFilterFields(c)
|
||||
if err != nil {
|
||||
|
|
@ -357,7 +357,7 @@ func (h *Handler) ExportUserSubscriptionsCSV(c *fiber.Ctx) error {
|
|||
// @Summary Export team members as CSV (admin)
|
||||
// @Tags team
|
||||
// @Produce text/csv
|
||||
// @Router /api/v1/team/members/export [get]
|
||||
// @Router /api/v1/admin/team/members/export [get]
|
||||
func (h *Handler) ExportTeamMembersCSV(c *fiber.Ctx) error {
|
||||
filter := parseTeamMemberListFilter(c)
|
||||
ctx := exportRequestContext(c)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func toTime(v interface{}) time.Time {
|
|||
// @Success 200 {object} domain.AnalyticsDashboard
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/analytics/dashboard [get]
|
||||
// @Router /api/v1/admin/analytics/dashboard [get]
|
||||
func (h *Handler) GetAnalyticsDashboard(c *fiber.Ctx) error {
|
||||
filter, err := domain.ParseAnalyticsDateFilter(c)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -383,7 +383,6 @@ func (h *Handler) HandleArifpaySuccessPage(c *fiber.Ctx) error {
|
|||
// @Param body body domain.WebhookRequest true "Webhook payload"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/payments/webhook [post]
|
||||
func (h *Handler) HandleArifpayWebhook(c *fiber.Ctx) error {
|
||||
var req domain.WebhookRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -419,7 +418,6 @@ func (h *Handler) HandleArifpayWebhook(c *fiber.Ctx) error {
|
|||
// @Tags payments
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/payments/methods [get]
|
||||
func (h *Handler) GetArifpayPaymentMethods(c *fiber.Ctx) error {
|
||||
methods := h.arifpaySvc.GetPaymentMethodsMapping()
|
||||
|
||||
|
|
|
|||
|
|
@ -256,7 +256,7 @@ func (h *Handler) GoogleCallback(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user-login [post]
|
||||
// @Router /api/v1/auth/customer-login [post]
|
||||
func (h *Handler) LoginUser(c *fiber.Ctx) error {
|
||||
var req domain.LoginRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -322,6 +322,9 @@ func (h *Handler) LoginUser(c *fiber.Ctx) error {
|
|||
}
|
||||
}
|
||||
|
||||
if !successRes.Role.IsCustomerLearnerRole() {
|
||||
return fiber.NewError(fiber.StatusForbidden, "Use the admin API to sign in with a staff account")
|
||||
}
|
||||
// if successRes.Role != domain.RoleStudent {
|
||||
// h.mongoLoggerSvc.Info("Login attempt: user login of other role",
|
||||
// zap.Int("status_code", fiber.StatusForbidden),
|
||||
|
|
@ -402,7 +405,7 @@ type LoginAdminRes struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/admin-login [post]
|
||||
// @Router /api/v1/admin/auth/admin-login [post]
|
||||
func (h *Handler) LoginAdmin(c *fiber.Ctx) error {
|
||||
var req domain.LoginRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -504,7 +507,7 @@ func (h *Handler) LoginAdmin(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/super-login [post]
|
||||
// @Router /api/v1/admin/auth/super-login [post]
|
||||
func (h *Handler) LoginSuper(c *fiber.Ctx) error {
|
||||
var req domain.LoginRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -685,6 +688,9 @@ func (h *Handler) RefreshToken(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to retrieve user information:"+err.Error())
|
||||
}
|
||||
|
||||
if c.Locals("api_audience") == "client" && !user.Role.IsCustomerLearnerRole() {
|
||||
return fiber.NewError(fiber.StatusForbidden, "A customer account is required")
|
||||
}
|
||||
if err := domain.ValidateUserCanAuthenticate(user.Status); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrUserAccountLocked):
|
||||
|
|
|
|||
|
|
@ -127,7 +127,6 @@ func (h *Handler) HandleChapaCallback(c *fiber.Ctx) error {
|
|||
// @Param status query string false "Payment status from Chapa redirect"
|
||||
// @Success 200 {string} string "HTML success page"
|
||||
// @Router /api/v1/payments/chapa/success [get]
|
||||
// @Router /payment/success [get]
|
||||
func (h *Handler) HandleChapaSuccessPage(c *fiber.Ctx) error {
|
||||
txRef := firstNonEmpty(
|
||||
c.Query("trx_ref"),
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import (
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/{id}/courses [post]
|
||||
func (h *Handler) CreateCourse(c *fiber.Ctx) error {
|
||||
programID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -82,7 +81,6 @@ func (h *Handler) CreateCourse(c *fiber.Ctx) error {
|
|||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/{id}/courses [get]
|
||||
func (h *Handler) ListCoursesByProgram(c *fiber.Ctx) error {
|
||||
programID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -184,7 +182,6 @@ func (h *Handler) ListCoursesByProgram(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Course ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/courses/{id} [get]
|
||||
func (h *Handler) GetCourse(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -254,7 +251,6 @@ func (h *Handler) GetCourse(c *fiber.Ctx) error {
|
|||
// @Param body body domain.UpdateCourseInput true "Fields to update"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/courses/{id} [put]
|
||||
func (h *Handler) UpdateCourse(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -304,7 +300,6 @@ func (h *Handler) UpdateCourse(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Course ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/courses/{id} [delete]
|
||||
func (h *Handler) DeleteCourse(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@ func assessmentParentFromQuery(c *fiber.Ctx) (domain.ExamPrepAssessmentParent, e
|
|||
return domain.ExamPrepAssessmentParent{Kind: kind, ID: parentID}, nil
|
||||
}
|
||||
|
||||
// ListExamPrepAssessments godoc
|
||||
// @Summary ListExamPrepAssessments
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/exam-prep/assessments [get]
|
||||
// @Router /api/v1/exam-prep/assessments [get]
|
||||
func (h *Handler) ListExamPrepAssessments(c *fiber.Ctx) error {
|
||||
parent, err := assessmentParentFromQuery(c)
|
||||
if err != nil || parent.Kind == "" {
|
||||
|
|
@ -32,6 +38,11 @@ func (h *Handler) ListExamPrepAssessments(c *fiber.Ctx) error {
|
|||
return c.JSON(domain.Response{Message: "Assessments retrieved successfully", Data: fiber.Map{"assessments": sets}, Success: true, StatusCode: fiber.StatusOK})
|
||||
}
|
||||
|
||||
// LinkExamPrepAssessment godoc
|
||||
// @Summary LinkExamPrepAssessment
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/exam-prep/assessments [post]
|
||||
func (h *Handler) LinkExamPrepAssessment(c *fiber.Ctx) error {
|
||||
var input domain.LinkExamPrepAssessmentInput
|
||||
if err := c.BodyParser(&input); err != nil {
|
||||
|
|
@ -48,6 +59,11 @@ func (h *Handler) LinkExamPrepAssessment(c *fiber.Ctx) error {
|
|||
return c.Status(fiber.StatusCreated).JSON(domain.Response{Message: "Assessment linked successfully", Data: fiber.Map{"assessment": set, "parent_kind": input.ParentKind, "parent_id": input.ParentID}, Success: true, StatusCode: fiber.StatusCreated})
|
||||
}
|
||||
|
||||
// UnlinkExamPrepAssessment godoc
|
||||
// @Summary UnlinkExamPrepAssessment
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/exam-prep/assessments/{questionSetId}/parents/{parentKind}/{parentId} [delete]
|
||||
func (h *Handler) UnlinkExamPrepAssessment(c *fiber.Ctx) error {
|
||||
questionSetID, err := parseAssessmentID(c.Params("questionSetId"))
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
// @Param body body domain.CreateExamPrepCatalogCourseInput true "Catalog course"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses [post]
|
||||
func (h *Handler) CreateExamPrepCatalogCourse(c *fiber.Ctx) error {
|
||||
var req domain.CreateExamPrepCatalogCourseInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -56,6 +57,8 @@ func (h *Handler) CreateExamPrepCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size" default(20)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses [get]
|
||||
// @Router /api/v1/exam-prep/catalog-courses [get]
|
||||
func (h *Handler) ListExamPrepCatalogCourses(c *fiber.Ctx) error {
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
|
|
@ -95,6 +98,7 @@ func (h *Handler) ListExamPrepCatalogCourses(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids: every catalog course id exactly once"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/reorder [put]
|
||||
func (h *Handler) ReorderExamPrepCatalogCourses(c *fiber.Ctx) error {
|
||||
var req domain.ReorderIDsRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -134,6 +138,8 @@ func (h *Handler) ReorderExamPrepCatalogCourses(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param id path int true "Catalog course ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{id} [get]
|
||||
// @Router /api/v1/exam-prep/catalog-courses/{id} [get]
|
||||
func (h *Handler) GetExamPrepCatalogCourseByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -184,6 +190,7 @@ func (h *Handler) GetExamPrepCatalogCourseByID(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Catalog course ID"
|
||||
// @Param body body domain.UpdateExamPrepCatalogCourseInput true "Fields to update"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{id} [put]
|
||||
func (h *Handler) UpdateExamPrepCatalogCourse(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -226,6 +233,7 @@ func (h *Handler) UpdateExamPrepCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param id path int true "Catalog course ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{id} [delete]
|
||||
func (h *Handler) DeleteExamPrepCatalogCourse(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
// @Tags exam-prep
|
||||
// @Param moduleId path int true "Exam prep unit module ID"
|
||||
// @Param body body domain.CreateExamPrepLessonInput true "Lesson"
|
||||
// @Router /api/v1/admin/exam-prep/modules/{moduleId}/lessons [post]
|
||||
func (h *Handler) CreateExamPrepLesson(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -64,6 +65,8 @@ func (h *Handler) CreateExamPrepLesson(c *fiber.Ctx) error {
|
|||
// @Param moduleId path int true "Exam prep unit module ID"
|
||||
// @Param limit query int false "Page size" default(20)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Router /api/v1/admin/exam-prep/modules/{moduleId}/lessons [get]
|
||||
// @Router /api/v1/exam-prep/modules/{moduleId}/lessons [get]
|
||||
func (h *Handler) ListExamPrepLessonsByUnitModule(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -125,6 +128,7 @@ func (h *Handler) ListExamPrepLessonsByUnitModule(c *fiber.Ctx) error {
|
|||
// ReorderExamPrepLessonsInUnitModule godoc
|
||||
// @Summary Reorder lessons within an exam-prep unit module
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/modules/{moduleId}/lessons/reorder [put]
|
||||
func (h *Handler) ReorderExamPrepLessonsInUnitModule(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -175,6 +179,8 @@ func (h *Handler) ReorderExamPrepLessonsInUnitModule(c *fiber.Ctx) error {
|
|||
// GetExamPrepLessonByID godoc
|
||||
// @Summary Get exam-prep lesson by ID
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/lessons/{id} [get]
|
||||
// @Router /api/v1/exam-prep/lessons/{id} [get]
|
||||
func (h *Handler) GetExamPrepLessonByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -224,6 +230,7 @@ func (h *Handler) GetExamPrepLessonByID(c *fiber.Ctx) error {
|
|||
// UpdateExamPrepLesson godoc
|
||||
// @Summary Update exam-prep lesson
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/lessons/{id} [put]
|
||||
func (h *Handler) UpdateExamPrepLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -264,6 +271,7 @@ func (h *Handler) UpdateExamPrepLesson(c *fiber.Ctx) error {
|
|||
// DeleteExamPrepLesson godoc
|
||||
// @Summary Delete exam-prep lesson
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/lessons/{id} [delete]
|
||||
func (h *Handler) DeleteExamPrepLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import (
|
|||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Unit ID"
|
||||
// @Param body body domain.CreateExamPrepModuleInput true "Module"
|
||||
// @Router /api/v1/admin/exam-prep/units/{unitId}/modules [post]
|
||||
func (h *Handler) CreateExamPrepModule(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -62,6 +63,8 @@ func (h *Handler) CreateExamPrepModule(c *fiber.Ctx) error {
|
|||
// @Summary List exam-prep modules for a unit
|
||||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Unit ID"
|
||||
// @Router /api/v1/admin/exam-prep/units/{unitId}/modules [get]
|
||||
// @Router /api/v1/exam-prep/units/{unitId}/modules [get]
|
||||
func (h *Handler) ListExamPrepModulesByUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -125,6 +128,7 @@ func (h *Handler) ListExamPrepModulesByUnit(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Unit ID"
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids"
|
||||
// @Router /api/v1/admin/exam-prep/units/{unitId}/modules/reorder [put]
|
||||
func (h *Handler) ReorderExamPrepModulesInUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -175,6 +179,8 @@ func (h *Handler) ReorderExamPrepModulesInUnit(c *fiber.Ctx) error {
|
|||
// GetExamPrepModuleByID godoc
|
||||
// @Summary Get exam-prep module by ID
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/modules/{id} [get]
|
||||
// @Router /api/v1/exam-prep/modules/{id} [get]
|
||||
func (h *Handler) GetExamPrepModuleByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -224,6 +230,7 @@ func (h *Handler) GetExamPrepModuleByID(c *fiber.Ctx) error {
|
|||
// UpdateExamPrepModule godoc
|
||||
// @Summary Update exam-prep module
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/modules/{id} [put]
|
||||
func (h *Handler) UpdateExamPrepModule(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -264,6 +271,7 @@ func (h *Handler) UpdateExamPrepModule(c *fiber.Ctx) error {
|
|||
// DeleteExamPrepModule godoc
|
||||
// @Summary Delete exam-prep module
|
||||
// @Tags exam-prep
|
||||
// @Router /api/v1/admin/exam-prep/modules/{id} [delete]
|
||||
func (h *Handler) DeleteExamPrepModule(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import (
|
|||
// @Summary Create exam-prep practice (optional parents; link later via PUT /exam-prep/practices/:id/parents)
|
||||
// @Tags exam-prep
|
||||
// @Param body body domain.CreateExamPrepPracticeInput true "Practice"
|
||||
// @Router /api/v1/admin/exam-prep/practices [post]
|
||||
func (h *Handler) CreateExamPrepPracticeFromInput(c *fiber.Ctx) error {
|
||||
var req domain.CreateExamPrepPracticeInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -53,6 +54,8 @@ func (h *Handler) CreateExamPrepPracticeFromInput(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size. Omit (with offset) to return all practices."
|
||||
// @Param offset query int false "Offset. Defaults to 0 when limit is provided; ignored semantics when both omitted (all rows)."
|
||||
// @Param unlinked_only query bool false "When true, return only practices with no parent links (admin)"
|
||||
// @Router /api/v1/admin/exam-prep/practices [get]
|
||||
// @Router /api/v1/exam-prep/practices [get]
|
||||
func (h *Handler) ListAllExamPrepPractices(c *fiber.Ctx) error {
|
||||
limit, offset, err := parseOptionalExamPrepPracticePagination(c)
|
||||
if err != nil {
|
||||
|
|
@ -127,6 +130,8 @@ func (h *Handler) CreateExamPrepPractice(c *fiber.Ctx) error {
|
|||
// @Param lessonId path int true "Exam prep lesson ID"
|
||||
// @Param limit query int false "Page size. Omit to return all practices for the lesson."
|
||||
// @Param offset query int false "Offset (used when limit is provided)"
|
||||
// @Router /api/v1/admin/exam-prep/lessons/{lessonId}/practices [get]
|
||||
// @Router /api/v1/exam-prep/lessons/{lessonId}/practices [get]
|
||||
func (h *Handler) ListExamPrepPracticesByLesson(c *fiber.Ctx) error {
|
||||
lessonID, err := strconv.ParseInt(c.Params("lessonId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -160,6 +165,8 @@ func (h *Handler) ListExamPrepPracticesByLesson(c *fiber.Ctx) error {
|
|||
// @Summary Get exam-prep practice by ID
|
||||
// @Tags exam-prep
|
||||
// @Param id path int true "Exam prep practice ID"
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id} [get]
|
||||
// @Router /api/v1/exam-prep/practices/{id} [get]
|
||||
func (h *Handler) GetExamPrepPracticeByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -200,6 +207,7 @@ func (h *Handler) GetExamPrepPracticeByID(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param id path int true "Exam prep practice ID"
|
||||
// @Param body body domain.UpdateExamPrepPracticeInput true "Fields to update"
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id} [put]
|
||||
func (h *Handler) UpdateExamPrepPractice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -251,6 +259,7 @@ func (h *Handler) UpdateExamPrepPractice(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param id path int true "Exam prep practice ID"
|
||||
// @Param body body domain.UpdateExamPrepPracticeParentsInput true "Parent links (replaces all; use empty array to detach)"
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id}/parents [put]
|
||||
func (h *Handler) UpdateExamPrepPracticeParents(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -306,6 +315,7 @@ func (h *Handler) UpdateExamPrepPracticeParents(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Exam prep practice ID"
|
||||
// @Param parentKind path string true "Parent kind (CATALOG_COURSE, UNIT, LESSON)"
|
||||
// @Param parentId path int true "Parent entity ID"
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id}/parents/{parentKind}/{parentId} [delete]
|
||||
func (h *Handler) UnlinkExamPrepPracticeParent(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -359,6 +369,7 @@ func (h *Handler) UnlinkExamPrepPracticeParent(c *fiber.Ctx) error {
|
|||
// @Summary Delete exam-prep practice
|
||||
// @Tags exam-prep
|
||||
// @Param id path int true "Exam prep practice ID"
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id} [delete]
|
||||
func (h *Handler) DeleteExamPrepPractice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -448,6 +459,7 @@ func (h *Handler) listExamPrepPracticesResponse(c *fiber.Ctx, items []domain.Exa
|
|||
// @Tags exam-prep
|
||||
// @Param catalogCourseId path int true "Exam prep catalog course ID"
|
||||
// @Param body body domain.CreateExamPrepPracticeInput true "Practice"
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{catalogCourseId}/practices [post]
|
||||
func (h *Handler) CreateExamPrepPracticeForCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -479,6 +491,8 @@ func (h *Handler) CreateExamPrepPracticeForCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Param catalogCourseId path int true "Exam prep catalog course ID"
|
||||
// @Param limit query int false "Page size. Omit to return all practices for the catalog course."
|
||||
// @Param offset query int false "Offset (used when limit is provided)"
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{catalogCourseId}/practices [get]
|
||||
// @Router /api/v1/exam-prep/catalog-courses/{catalogCourseId}/practices [get]
|
||||
func (h *Handler) ListExamPrepPracticesByCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -507,6 +521,7 @@ func (h *Handler) ListExamPrepPracticesByCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param unitId path int true "Exam prep unit ID"
|
||||
// @Param body body domain.CreateExamPrepPracticeInput true "Practice"
|
||||
// @Router /api/v1/admin/exam-prep/units/{unitId}/practices [post]
|
||||
func (h *Handler) CreateExamPrepPracticeForUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -538,6 +553,8 @@ func (h *Handler) CreateExamPrepPracticeForUnit(c *fiber.Ctx) error {
|
|||
// @Param unitId path int true "Exam prep unit ID"
|
||||
// @Param limit query int false "Page size. Omit to return all practices for the unit."
|
||||
// @Param offset query int false "Offset (used when limit is provided)"
|
||||
// @Router /api/v1/admin/exam-prep/units/{unitId}/practices [get]
|
||||
// @Router /api/v1/exam-prep/units/{unitId}/practices [get]
|
||||
func (h *Handler) ListExamPrepPracticesByUnit(c *fiber.Ctx) error {
|
||||
unitID, err := strconv.ParseInt(c.Params("unitId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
// @Param catalogCourseId path int true "Catalog course ID"
|
||||
// @Param body body domain.CreateExamPrepUnitInput true "Unit"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{catalogCourseId}/units [post]
|
||||
func (h *Handler) CreateExamPrepUnit(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -69,6 +70,8 @@ func (h *Handler) CreateExamPrepUnit(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size" default(20)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{catalogCourseId}/units [get]
|
||||
// @Router /api/v1/exam-prep/catalog-courses/{catalogCourseId}/units [get]
|
||||
func (h *Handler) ListExamPrepUnitsByCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -132,6 +135,7 @@ func (h *Handler) ListExamPrepUnitsByCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param catalogCourseId path int true "Catalog course ID"
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids: every unit id in this catalog course, new order"
|
||||
// @Router /api/v1/admin/exam-prep/catalog-courses/{catalogCourseId}/units/reorder [put]
|
||||
func (h *Handler) ReorderExamPrepUnitsInCatalogCourse(c *fiber.Ctx) error {
|
||||
catalogCourseID, err := strconv.ParseInt(c.Params("catalogCourseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -183,6 +187,8 @@ func (h *Handler) ReorderExamPrepUnitsInCatalogCourse(c *fiber.Ctx) error {
|
|||
// @Summary Get exam-prep unit by ID
|
||||
// @Tags exam-prep
|
||||
// @Param id path int true "Unit ID"
|
||||
// @Router /api/v1/admin/exam-prep/units/{id} [get]
|
||||
// @Router /api/v1/exam-prep/units/{id} [get]
|
||||
func (h *Handler) GetExamPrepUnitByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -234,6 +240,7 @@ func (h *Handler) GetExamPrepUnitByID(c *fiber.Ctx) error {
|
|||
// @Tags exam-prep
|
||||
// @Param id path int true "Unit ID"
|
||||
// @Param body body domain.UpdateExamPrepUnitInput true "Fields to update"
|
||||
// @Router /api/v1/admin/exam-prep/units/{id} [put]
|
||||
func (h *Handler) UpdateExamPrepUnit(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -275,6 +282,7 @@ func (h *Handler) UpdateExamPrepUnit(c *fiber.Ctx) error {
|
|||
// @Summary Delete exam-prep unit
|
||||
// @Tags exam-prep
|
||||
// @Param id path int true "Unit ID"
|
||||
// @Router /api/v1/admin/exam-prep/units/{id} [delete]
|
||||
func (h *Handler) DeleteExamPrepUnit(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ func (h *Handler) resolveFileURL(c *fiber.Ctx, storedPath string) string {
|
|||
// @Tags files
|
||||
// @Param key query string true "MinIO object key (e.g. profile_pictures/uuid.jpg)"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/url [get]
|
||||
// @Router /api/v1/files/url [get]
|
||||
func (h *Handler) GetFileURL(c *fiber.Ctx) error {
|
||||
key := strings.TrimSpace(c.Query("key"))
|
||||
|
|
@ -121,6 +122,7 @@ func (h *Handler) extractObjectKeyFromReference(reference string) (string, error
|
|||
// @Produce json
|
||||
// @Param body body refreshFileURLReq true "reference (object key, minio://..., or existing presigned URL)"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/refresh-url [post]
|
||||
// @Router /api/v1/files/refresh-url [post]
|
||||
func (h *Handler) RefreshFileURL(c *fiber.Ctx) error {
|
||||
if h.minioSvc == nil {
|
||||
|
|
@ -173,6 +175,7 @@ func (h *Handler) RefreshFileURL(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param body body presignedUploadReq true "Presigned upload request"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/presign-upload [post]
|
||||
// @Router /api/v1/files/presign-upload [post]
|
||||
func (h *Handler) CreatePresignedUpload(c *fiber.Ctx) error {
|
||||
if h.minioSvc == nil {
|
||||
|
|
@ -263,6 +266,7 @@ func (h *Handler) CreatePresignedUpload(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param body body completePresignedUploadReq true "Complete upload request"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/complete-upload [post]
|
||||
// @Router /api/v1/files/complete-upload [post]
|
||||
func (h *Handler) CompletePresignedUpload(c *fiber.Ctx) error {
|
||||
if h.minioSvc == nil {
|
||||
|
|
@ -383,6 +387,7 @@ func objectKeyMatchesMediaType(objectKey, mediaType string) bool {
|
|||
// @Param media_type formData string true "Media type: image|audio|video|pdf"
|
||||
// @Param file formData file true "Media file"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/upload [post]
|
||||
// @Router /api/v1/files/upload [post]
|
||||
func (h *Handler) UploadMedia(c *fiber.Ctx) error {
|
||||
mediaType := strings.ToLower(strings.TrimSpace(c.FormValue("media_type")))
|
||||
|
|
@ -626,6 +631,7 @@ func normalizeAndValidateMediaContentType(mediaType, contentType, fileName strin
|
|||
// @Accept multipart/form-data
|
||||
// @Param file formData file true "Audio file (mp3, wav, ogg, m4a, aac, webm)"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/admin/files/audio [post]
|
||||
// @Router /api/v1/files/audio [post]
|
||||
func (h *Handler) UploadAudio(c *fiber.Ctx) error {
|
||||
if h.minioSvc == nil {
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ func (h *Handler) CreateIssue(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response{data=issueRes}
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/issues/{id} [get]
|
||||
// @Router /api/v1/admin/issues/{id} [get]
|
||||
func (h *Handler) GetIssueByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -176,7 +176,7 @@ func (h *Handler) GetIssueByID(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response{data=issueListRes}
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/issues/user/{user_id} [get]
|
||||
// @Router /api/v1/admin/issues/user/{user_id} [get]
|
||||
func (h *Handler) GetUserIssues(c *fiber.Ctx) error {
|
||||
userIDStr := c.Params("user_id")
|
||||
userID, err := strconv.ParseInt(userIDStr, 10, 64)
|
||||
|
|
@ -273,7 +273,7 @@ func (h *Handler) GetMyIssues(c *fiber.Ctx) error {
|
|||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response{data=issueListRes}
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/issues [get]
|
||||
// @Router /api/v1/admin/issues [get]
|
||||
func (h *Handler) GetAllIssues(c *fiber.Ctx) error {
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
|
|
@ -318,7 +318,7 @@ func (h *Handler) GetAllIssues(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/issues/{id}/status [patch]
|
||||
// @Router /api/v1/admin/issues/{id}/status [patch]
|
||||
func (h *Handler) UpdateIssueStatus(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -386,7 +386,7 @@ func (h *Handler) UpdateIssueStatus(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/issues/{id} [delete]
|
||||
// @Router /api/v1/admin/issues/{id} [delete]
|
||||
func (h *Handler) DeleteIssue(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import (
|
|||
// @Produce json
|
||||
// @Param moduleId path int true "Module ID"
|
||||
// @Param body body domain.CreateLessonInput true "Lesson"
|
||||
// @Router /api/v1/modules/{moduleId}/lessons [post]
|
||||
func (h *Handler) CreateLesson(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -75,7 +74,6 @@ func (h *Handler) CreateLesson(c *fiber.Ctx) error {
|
|||
// @Param moduleId path int true "Module ID"
|
||||
// @Param limit query int false "Page size" default(20)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Router /api/v1/modules/{moduleId}/lessons [get]
|
||||
func (h *Handler) ListLessonsByModule(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -132,7 +130,6 @@ func (h *Handler) ListLessonsByModule(c *fiber.Ctx) error {
|
|||
// GetLesson godoc
|
||||
// @Tags lessons
|
||||
// @Param id path int true "Lesson ID"
|
||||
// @Router /api/v1/lessons/{id} [get]
|
||||
func (h *Handler) GetLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -185,7 +182,6 @@ func (h *Handler) GetLesson(c *fiber.Ctx) error {
|
|||
// @Tags lessons
|
||||
// @Param id path int true "Lesson ID"
|
||||
// @Param body body domain.UpdateLessonInput true "Fields to update"
|
||||
// @Router /api/v1/lessons/{id} [put]
|
||||
func (h *Handler) UpdateLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -232,7 +228,6 @@ func (h *Handler) UpdateLesson(c *fiber.Ctx) error {
|
|||
// DeleteLesson godoc
|
||||
// @Tags lessons
|
||||
// @Param id path int true "Lesson ID"
|
||||
// @Router /api/v1/lessons/{id} [delete]
|
||||
func (h *Handler) DeleteLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -273,7 +268,6 @@ func (h *Handler) DeleteLesson(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Lesson ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/lessons/{id}/complete [post]
|
||||
func (h *Handler) CompleteLesson(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ type listPersonasData struct {
|
|||
// @Accept json
|
||||
// @Param body body domain.CreateLmsPersonaInput true "Persona"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Router /api/v1/personas [post]
|
||||
// @Router /api/v1/admin/personas [post]
|
||||
func (h *Handler) CreatePersona(c *fiber.Ctx) error {
|
||||
var req domain.CreateLmsPersonaInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -61,6 +61,7 @@ func (h *Handler) CreatePersona(c *fiber.Ctx) error {
|
|||
// @Param active_only query bool false "When true (default), return only active personas" default(true)
|
||||
// @Param limit query int false "Page size"
|
||||
// @Param offset query int false "Offset"
|
||||
// @Router /api/v1/admin/personas [get]
|
||||
// @Router /api/v1/personas [get]
|
||||
func (h *Handler) ListPersonas(c *fiber.Ctx) error {
|
||||
activeOnlyStr := strings.ToLower(strings.TrimSpace(c.Query("active_only", "true")))
|
||||
|
|
@ -95,6 +96,7 @@ func (h *Handler) ListPersonas(c *fiber.Ctx) error {
|
|||
// @Summary Get LMS persona by ID
|
||||
// @Tags personas
|
||||
// @Param id path int true "Persona ID"
|
||||
// @Router /api/v1/admin/personas/{id} [get]
|
||||
// @Router /api/v1/personas/{id} [get]
|
||||
func (h *Handler) GetPersona(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
|
|
@ -120,7 +122,7 @@ func (h *Handler) GetPersona(c *fiber.Ctx) error {
|
|||
// @Tags personas
|
||||
// @Param id path int true "Persona ID"
|
||||
// @Param body body domain.UpdateLmsPersonaInput true "Fields to update"
|
||||
// @Router /api/v1/personas/{id} [put]
|
||||
// @Router /api/v1/admin/personas/{id} [put]
|
||||
func (h *Handler) UpdatePersona(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -152,7 +154,7 @@ func (h *Handler) UpdatePersona(c *fiber.Ctx) error {
|
|||
// @Summary Delete LMS persona (practices referencing it will have persona_id cleared)
|
||||
// @Tags personas
|
||||
// @Param id path int true "Persona ID"
|
||||
// @Router /api/v1/personas/{id} [delete]
|
||||
// @Router /api/v1/admin/personas/{id} [delete]
|
||||
func (h *Handler) DeletePersona(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ const lmsProgressSummaryPageSize int32 = 200
|
|||
// @Produce json
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/lms/progress [get]
|
||||
func (h *Handler) GetMyLMSProgress(c *fiber.Ctx) error {
|
||||
uid := c.Locals("user_id").(int64)
|
||||
prog, err := h.lmsProgressSvc.GetMyProgress(c.Context(), uid)
|
||||
|
|
@ -75,7 +74,6 @@ func (h *Handler) GetMyLMSProgressSummary(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/users/{user_id}/lms-learning-activity [get]
|
||||
func (h *Handler) AdminGetUserLMSLearningActivity(c *fiber.Ctx) error {
|
||||
targetIDStr := c.Params("user_id")
|
||||
targetID, err := strconv.ParseInt(targetIDStr, 10, 64)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
// @Param body body domain.ReorderIDsRequest true "New order: ordered_ids is the full set of program ids"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/reorder [put]
|
||||
func (h *Handler) ReorderPrograms(c *fiber.Ctx) error {
|
||||
var req domain.ReorderIDsRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -66,7 +65,6 @@ func (h *Handler) ReorderPrograms(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Program ID"
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids: every course id in this program, in the new order"
|
||||
// @Tags courses
|
||||
// @Router /api/v1/programs/{id}/courses/reorder [put]
|
||||
func (h *Handler) ReorderCoursesInProgram(c *fiber.Ctx) error {
|
||||
programID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -125,7 +123,6 @@ func (h *Handler) ReorderCoursesInProgram(c *fiber.Ctx) error {
|
|||
// @Param courseId path int true "Course ID"
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids: every module id in this course, in the new order"
|
||||
// @Tags modules
|
||||
// @Router /api/v1/courses/{courseId}/modules/reorder [put]
|
||||
func (h *Handler) ReorderModulesInCourse(c *fiber.Ctx) error {
|
||||
courseID, err := strconv.ParseInt(c.Params("courseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -183,7 +180,6 @@ func (h *Handler) ReorderModulesInCourse(c *fiber.Ctx) error {
|
|||
// @Param moduleId path int true "Module ID"
|
||||
// @Param body body domain.ReorderIDsRequest true "ordered_ids: every lesson id in this module, in the new order"
|
||||
// @Tags lessons
|
||||
// @Router /api/v1/modules/{moduleId}/lessons/reorder [put]
|
||||
func (h *Handler) ReorderLessonsInModule(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("moduleId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import (
|
|||
// @Param body body domain.CreateModuleInput true "Module"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/courses/{courseId}/modules [post]
|
||||
func (h *Handler) CreateModule(c *fiber.Ctx) error {
|
||||
courseID, err := strconv.ParseInt(c.Params("courseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -80,7 +79,6 @@ func (h *Handler) CreateModule(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size" default(20)
|
||||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/courses/{courseId}/modules [get]
|
||||
func (h *Handler) ListModulesByCourse(c *fiber.Ctx) error {
|
||||
courseID, err := strconv.ParseInt(c.Params("courseId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -148,7 +146,6 @@ func (h *Handler) ListModulesByCourse(c *fiber.Ctx) error {
|
|||
// @Tags modules
|
||||
// @Param id path int true "Module ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/modules/{id} [get]
|
||||
func (h *Handler) GetModule(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -201,7 +198,6 @@ func (h *Handler) GetModule(c *fiber.Ctx) error {
|
|||
// @Tags modules
|
||||
// @Param id path int true "Module ID"
|
||||
// @Param body body domain.UpdateModuleInput true "Fields to update"
|
||||
// @Router /api/v1/modules/{id} [put]
|
||||
func (h *Handler) UpdateModule(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -248,7 +244,6 @@ func (h *Handler) UpdateModule(c *fiber.Ctx) error {
|
|||
// DeleteModule godoc
|
||||
// @Tags modules
|
||||
// @Param id path int true "Module ID"
|
||||
// @Router /api/v1/modules/{id} [delete]
|
||||
func (h *Handler) DeleteModule(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import (
|
|||
// @Success 200 {object} domain.LogResponse "Paginated list of application logs"
|
||||
// @Failure 400 {object} domain.ErrorResponse "Invalid request parameters"
|
||||
// @Failure 500 {object} domain.ErrorResponse "Internal server error"
|
||||
// @Router /api/v1/logs [get]
|
||||
// @Router /api/v1/admin/logs [get]
|
||||
func GetLogsHandler(appCtx context.Context) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
// Get query parameters
|
||||
|
|
|
|||
|
|
@ -24,6 +24,21 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func notificationRequestContext(c *fiber.Ctx) context.Context {
|
||||
receiver := domain.ReceiverTypeUser
|
||||
if c.Locals("api_audience") == "admin" {
|
||||
receiver = domain.ReceiverTypeTeamMember
|
||||
}
|
||||
userID, _ := c.Locals("user_id").(int64)
|
||||
return domain.WithNotificationScope(c.Context(), userID, receiver)
|
||||
}
|
||||
|
||||
// ConnectSocket godoc
|
||||
// @Summary ConnectSocket
|
||||
// @Tags client
|
||||
// @Param token query string true "Access token"
|
||||
// @Router /api/v1/admin/ws/connect [get]
|
||||
// @Router /api/v1/ws/connect [get]
|
||||
func (h *Handler) ConnectSocket(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("userID").(int64)
|
||||
if !ok || userID == 0 {
|
||||
|
|
@ -35,6 +50,11 @@ func (h *Handler) ConnectSocket(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid user identification")
|
||||
}
|
||||
|
||||
receiverType := domain.ReceiverTypeUser
|
||||
if c.Locals("api_audience") == "admin" {
|
||||
receiverType = domain.ReceiverTypeTeamMember
|
||||
}
|
||||
|
||||
// Convert fasthttp request to net/http request for gorilla upgrader
|
||||
stdReq := &http.Request{
|
||||
Method: http.MethodGet,
|
||||
|
|
@ -69,8 +89,9 @@ func (h *Handler) ConnectSocket(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
client := &ws.Client{
|
||||
Conn: wsConn,
|
||||
RecipientID: userID,
|
||||
ReceiverType: receiverType,
|
||||
Conn: wsConn,
|
||||
RecipientID: userID,
|
||||
}
|
||||
|
||||
h.notificationSvc.Hub.Register <- client
|
||||
|
|
@ -133,6 +154,7 @@ func (w *hijackResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/notifications/{id} [get]
|
||||
// @Router /api/v1/notifications/{id} [get]
|
||||
func (h *Handler) GetNotificationByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
|
|
@ -155,7 +177,10 @@ func (h *Handler) GetNotificationByID(c *fiber.Ctx) error {
|
|||
role, _ := c.Locals("role").(domain.Role)
|
||||
allowAll := h.rbacSvc.HasPermission(string(role), "notifications.list_all")
|
||||
|
||||
notification, err := h.notificationSvc.GetNotificationByID(c.Context(), id, userID, allowAll)
|
||||
if c.Locals("api_audience") == "client" {
|
||||
allowAll = false
|
||||
}
|
||||
notification, err := h.notificationSvc.GetNotificationByID(notificationRequestContext(c), id, userID, allowAll)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, notificationservice.ErrNotificationNotFound):
|
||||
|
|
@ -190,6 +215,12 @@ func (h *Handler) GetNotificationByID(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// MarkNotificationAsRead godoc
|
||||
// @Summary MarkNotificationAsRead
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/{id}/read [patch]
|
||||
// @Router /api/v1/notifications/{id}/read [patch]
|
||||
func (h *Handler) MarkNotificationAsRead(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -200,7 +231,7 @@ func (h *Handler) MarkNotificationAsRead(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
notification, err := h.notificationSvc.MarkNotificationAsRead(context.Background(), id)
|
||||
notification, err := h.notificationSvc.MarkNotificationAsRead(notificationRequestContext(c), id)
|
||||
if err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.MarkNotificationAsRead] Failed to mark notification as read",
|
||||
zap.Int64("notificationID", id),
|
||||
|
|
@ -224,6 +255,12 @@ func (h *Handler) MarkNotificationAsRead(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// MarkAllNotificationsAsRead godoc
|
||||
// @Summary MarkAllNotificationsAsRead
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/mark-all-read [post]
|
||||
// @Router /api/v1/notifications/mark-all-read [post]
|
||||
func (h *Handler) MarkAllNotificationsAsRead(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok || userID == 0 {
|
||||
|
|
@ -233,7 +270,7 @@ func (h *Handler) MarkAllNotificationsAsRead(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if err := h.notificationSvc.MarkAllUserNotificationsAsRead(context.Background(), userID); err != nil {
|
||||
if err := h.notificationSvc.MarkAllUserNotificationsAsRead(notificationRequestContext(c), userID); err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.MarkAllNotificationsAsRead] Failed to mark all notifications as read",
|
||||
zap.Int64("userID", userID),
|
||||
zap.Int("status_code", fiber.StatusInternalServerError),
|
||||
|
|
@ -255,6 +292,12 @@ func (h *Handler) MarkAllNotificationsAsRead(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// MarkNotificationAsUnread godoc
|
||||
// @Summary MarkNotificationAsUnread
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/{id}/unread [patch]
|
||||
// @Router /api/v1/notifications/{id}/unread [patch]
|
||||
func (h *Handler) MarkNotificationAsUnread(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -265,7 +308,7 @@ func (h *Handler) MarkNotificationAsUnread(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
notification, err := h.notificationSvc.MarkNotificationAsUnread(context.Background(), id)
|
||||
notification, err := h.notificationSvc.MarkNotificationAsUnread(notificationRequestContext(c), id)
|
||||
if err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.MarkNotificationAsUnread] Failed to mark notification as unread",
|
||||
zap.Int64("notificationID", id),
|
||||
|
|
@ -289,6 +332,12 @@ func (h *Handler) MarkNotificationAsUnread(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// MarkAllNotificationsAsUnread godoc
|
||||
// @Summary MarkAllNotificationsAsUnread
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/mark-all-unread [post]
|
||||
// @Router /api/v1/notifications/mark-all-unread [post]
|
||||
func (h *Handler) MarkAllNotificationsAsUnread(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok || userID == 0 {
|
||||
|
|
@ -298,7 +347,7 @@ func (h *Handler) MarkAllNotificationsAsUnread(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if err := h.notificationSvc.MarkAllUserNotificationsAsUnread(context.Background(), userID); err != nil {
|
||||
if err := h.notificationSvc.MarkAllUserNotificationsAsUnread(notificationRequestContext(c), userID); err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.MarkAllNotificationsAsUnread] Failed to mark all notifications as unread",
|
||||
zap.Int64("userID", userID),
|
||||
zap.Int("status_code", fiber.StatusInternalServerError),
|
||||
|
|
@ -320,6 +369,12 @@ func (h *Handler) MarkAllNotificationsAsUnread(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteUserNotifications godoc
|
||||
// @Summary DeleteUserNotifications
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications [delete]
|
||||
// @Router /api/v1/notifications [delete]
|
||||
func (h *Handler) DeleteUserNotifications(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok || userID == 0 {
|
||||
|
|
@ -329,7 +384,7 @@ func (h *Handler) DeleteUserNotifications(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if err := h.notificationSvc.DeleteUserNotifications(context.Background(), userID); err != nil {
|
||||
if err := h.notificationSvc.DeleteUserNotifications(notificationRequestContext(c), userID); err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.DeleteUserNotifications] Failed to delete notifications",
|
||||
zap.Int64("userID", userID),
|
||||
zap.Int("status_code", fiber.StatusInternalServerError),
|
||||
|
|
@ -361,6 +416,7 @@ func (h *Handler) DeleteUserNotifications(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/notifications/{id} [delete]
|
||||
// @Router /api/v1/notifications/{id} [delete]
|
||||
func (h *Handler) DeleteInAppNotification(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
|
|
@ -380,7 +436,7 @@ func (h *Handler) DeleteInAppNotification(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if err := h.notificationSvc.DeleteUserInAppNotification(c.Context(), id, userID); err != nil {
|
||||
if err := h.notificationSvc.DeleteUserInAppNotification(notificationRequestContext(c), id, userID); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, notificationservice.ErrNotificationNotFound):
|
||||
return c.Status(fiber.StatusNotFound).JSON(domain.ErrorResponse{
|
||||
|
|
@ -420,6 +476,7 @@ func (h *Handler) DeleteInAppNotification(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/notifications/delete-in-app [post]
|
||||
// @Router /api/v1/notifications/delete-in-app [post]
|
||||
func (h *Handler) DeleteInAppNotifications(c *fiber.Ctx) error {
|
||||
type request struct {
|
||||
|
|
@ -448,7 +505,7 @@ func (h *Handler) DeleteInAppNotifications(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
deletedCount, err := h.notificationSvc.DeleteUserInAppNotifications(c.Context(), userID, req.IDs)
|
||||
deletedCount, err := h.notificationSvc.DeleteUserInAppNotifications(notificationRequestContext(c), userID, req.IDs)
|
||||
if err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationHandler.DeleteInAppNotifications] Failed to delete in-app notifications",
|
||||
zap.Int64("userID", userID),
|
||||
|
|
@ -478,6 +535,11 @@ func (h *Handler) DeleteInAppNotifications(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// CreateAndSendNotification godoc
|
||||
// @Summary CreateAndSendNotification
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/create [post]
|
||||
func (h *Handler) CreateAndSendNotification(c *fiber.Ctx) error {
|
||||
type Request struct {
|
||||
RecipientID int64 `json:"recipient_id" validate:"required_if=DeliveryScheme single"`
|
||||
|
|
@ -639,6 +701,12 @@ func (h *Handler) CreateAndSendNotification(c *fiber.Ctx) error {
|
|||
}
|
||||
}
|
||||
|
||||
// GetUserNotification godoc
|
||||
// @Summary GetUserNotification
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications [get]
|
||||
// @Router /api/v1/notifications [get]
|
||||
func (h *Handler) GetUserNotification(c *fiber.Ctx) error {
|
||||
limitStr := c.Query("limit", "10")
|
||||
offsetStr := c.Query("offset", "0")
|
||||
|
|
@ -676,7 +744,7 @@ func (h *Handler) GetUserNotification(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusInternalServerError, "Invalid user identification")
|
||||
}
|
||||
|
||||
notifications, total, err := h.notificationSvc.GetUserNotifications(context.Background(), userID, limit, offset)
|
||||
notifications, total, err := h.notificationSvc.GetUserNotifications(notificationRequestContext(c), userID, limit, offset)
|
||||
if err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationSvc.GetUserNotification] Failed to fetch notifications",
|
||||
zap.Int64("userID", userID),
|
||||
|
|
@ -700,6 +768,12 @@ func (h *Handler) GetUserNotification(c *fiber.Ctx) error {
|
|||
// return h.notificationSvc.ListRecipientIDs(ctx, receiver)
|
||||
// }
|
||||
|
||||
// CountUnreadNotifications godoc
|
||||
// @Summary CountUnreadNotifications
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/unread [get]
|
||||
// @Router /api/v1/notifications/unread [get]
|
||||
func (h *Handler) CountUnreadNotifications(c *fiber.Ctx) error {
|
||||
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
|
|
@ -712,7 +786,7 @@ func (h *Handler) CountUnreadNotifications(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusInternalServerError, "Invalid user identification")
|
||||
}
|
||||
|
||||
total, err := h.notificationSvc.CountUnreadNotifications(c.Context(), userID)
|
||||
total, err := h.notificationSvc.CountUnreadNotifications(notificationRequestContext(c), userID)
|
||||
|
||||
if err != nil {
|
||||
h.mongoLoggerSvc.Error("[NotificationSvc.CountUnreadNotifications] Failed to fetch unread notification count",
|
||||
|
|
@ -729,6 +803,11 @@ func (h *Handler) CountUnreadNotifications(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// GetAllNotifications godoc
|
||||
// @Summary GetAllNotifications
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/notifications/all [get]
|
||||
func (h *Handler) GetAllNotifications(c *fiber.Ctx) error {
|
||||
limitStr := c.Query("limit", "10")
|
||||
pageStr := c.Query("page", "1")
|
||||
|
|
@ -811,7 +890,7 @@ type SendSingleAfroSMSReq struct {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/sendSMS [post]
|
||||
// @Router /api/v1/admin/sendSMS [post]
|
||||
func (h *Handler) SendSingleAfroSMS(c *fiber.Ctx) error {
|
||||
var req SendSingleAfroSMSReq
|
||||
|
||||
|
|
@ -872,6 +951,12 @@ func (h *Handler) SendSingleAfroSMS(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// RegisterDeviceToken godoc
|
||||
// @Summary RegisterDeviceToken
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/devices/register [post]
|
||||
// @Router /api/v1/devices/register [post]
|
||||
func (h *Handler) RegisterDeviceToken(c *fiber.Ctx) error {
|
||||
type Request struct {
|
||||
DeviceToken string `json:"device_token" validate:"required"`
|
||||
|
|
@ -952,7 +1037,7 @@ func (h *Handler) RegisterDeviceToken(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/test-push [post]
|
||||
// @Router /api/v1/admin/notifications/test-push [post]
|
||||
func (h *Handler) SendTestPushNotification(c *fiber.Ctx) error {
|
||||
title := c.FormValue("title", "Test Push Notification")
|
||||
message := c.FormValue("message", "This is a test push notification from Rezina")
|
||||
|
|
@ -1055,7 +1140,7 @@ func (h *Handler) SendTestPushNotification(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/bulk-push [post]
|
||||
// @Router /api/v1/admin/notifications/bulk-push [post]
|
||||
func (h *Handler) SendBulkPushNotification(c *fiber.Ctx) error {
|
||||
title := c.FormValue("title")
|
||||
message := c.FormValue("message")
|
||||
|
|
@ -1128,10 +1213,10 @@ func (h *Handler) SendBulkPushNotification(c *fiber.Ctx) error {
|
|||
|
||||
scheduledID := created.ID
|
||||
scheduleMeta, _ := json.Marshal(map[string]interface{}{
|
||||
"channel": "push",
|
||||
"target_users": len(userIDs),
|
||||
"target_role": role,
|
||||
"scheduled_at": scheduledAtRaw,
|
||||
"channel": "push",
|
||||
"target_users": len(userIDs),
|
||||
"target_role": role,
|
||||
"scheduled_at": scheduledAtRaw,
|
||||
})
|
||||
h.recordActivity(c, domain.ActionNotificationBulkSent, domain.ResourceNotification, &scheduledID, fmt.Sprintf("Scheduled push notification ID: %d", scheduledID), scheduleMeta)
|
||||
|
||||
|
|
@ -1262,7 +1347,7 @@ func (h *Handler) SendBulkPushNotification(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/bulk-sms [post]
|
||||
// @Router /api/v1/admin/notifications/bulk-sms [post]
|
||||
func (h *Handler) SendBulkSMS(c *fiber.Ctx) error {
|
||||
type Request struct {
|
||||
Message string `json:"message" validate:"required"`
|
||||
|
|
@ -1446,18 +1531,18 @@ func (h *Handler) SendBulkSMS(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/bulk-in-app [post]
|
||||
// @Router /api/v1/admin/notifications/bulk-in-app [post]
|
||||
func (h *Handler) SendBulkInAppNotification(c *fiber.Ctx) error {
|
||||
type Request struct {
|
||||
Title string `json:"title" validate:"required"`
|
||||
Message string `json:"message" validate:"required"`
|
||||
UserIDs []int64 `json:"user_ids"`
|
||||
Role string `json:"role"`
|
||||
TeamMemberIDs []int64 `json:"team_member_ids"`
|
||||
TeamRole string `json:"team_role"`
|
||||
ScheduledAt string `json:"scheduled_at"`
|
||||
Type string `json:"type"`
|
||||
Level string `json:"level"`
|
||||
Title string `json:"title" validate:"required"`
|
||||
Message string `json:"message" validate:"required"`
|
||||
UserIDs []int64 `json:"user_ids"`
|
||||
Role string `json:"role"`
|
||||
TeamMemberIDs []int64 `json:"team_member_ids"`
|
||||
TeamRole string `json:"team_role"`
|
||||
ScheduledAt string `json:"scheduled_at"`
|
||||
Type string `json:"type"`
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
var req Request
|
||||
|
|
@ -1533,12 +1618,12 @@ func (h *Handler) SendBulkInAppNotification(c *fiber.Ctx) error {
|
|||
|
||||
scheduledID := created.ID
|
||||
scheduleMeta, _ := json.Marshal(map[string]interface{}{
|
||||
"channel": "in_app",
|
||||
"target_users": len(req.UserIDs),
|
||||
"target_role": req.Role,
|
||||
"channel": "in_app",
|
||||
"target_users": len(req.UserIDs),
|
||||
"target_role": req.Role,
|
||||
"target_team_members": len(req.TeamMemberIDs),
|
||||
"target_team_role": req.TeamRole,
|
||||
"scheduled_at": req.ScheduledAt,
|
||||
"target_team_role": req.TeamRole,
|
||||
"scheduled_at": req.ScheduledAt,
|
||||
})
|
||||
h.recordActivity(c, domain.ActionNotificationBulkSent, domain.ResourceNotification, &scheduledID, fmt.Sprintf("Scheduled in-app notification ID: %d", scheduledID), scheduleMeta)
|
||||
|
||||
|
|
@ -1586,12 +1671,12 @@ func (h *Handler) SendBulkInAppNotification(c *fiber.Ctx) error {
|
|||
)
|
||||
|
||||
bulkInAppMeta, _ := json.Marshal(map[string]interface{}{
|
||||
"channel": "in_app",
|
||||
"total_recipients": totalRecipients,
|
||||
"user_recipients": len(userIDs),
|
||||
"channel": "in_app",
|
||||
"total_recipients": totalRecipients,
|
||||
"user_recipients": len(userIDs),
|
||||
"team_member_recipients": len(teamMemberIDs),
|
||||
"sent": sent,
|
||||
"failed": failed,
|
||||
"sent": sent,
|
||||
"failed": failed,
|
||||
})
|
||||
h.recordActivity(c, domain.ActionNotificationBulkSent, domain.ResourceNotification, nil, fmt.Sprintf("Bulk in-app notification sent to %d recipients", totalRecipients), bulkInAppMeta)
|
||||
|
||||
|
|
@ -1618,7 +1703,7 @@ func (h *Handler) SendBulkInAppNotification(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/scheduled/{id} [get]
|
||||
// @Router /api/v1/admin/notifications/scheduled/{id} [get]
|
||||
func (h *Handler) GetScheduledNotification(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -1658,7 +1743,7 @@ func (h *Handler) GetScheduledNotification(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/scheduled [get]
|
||||
// @Router /api/v1/admin/notifications/scheduled [get]
|
||||
func (h *Handler) ListScheduledNotifications(c *fiber.Ctx) error {
|
||||
limit, err := strconv.Atoi(c.Query("limit", "20"))
|
||||
if err != nil || limit <= 0 {
|
||||
|
|
@ -1727,7 +1812,7 @@ func (h *Handler) ListScheduledNotifications(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/scheduled/{id}/cancel [post]
|
||||
// @Router /api/v1/admin/notifications/scheduled/{id}/cancel [post]
|
||||
func (h *Handler) CancelScheduledNotification(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -1790,7 +1875,7 @@ func (h *Handler) parseEmailAttachment(c *fiber.Ctx) []*resend.Attachment {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/send-email [post]
|
||||
// @Router /api/v1/admin/notifications/send-email [post]
|
||||
func (h *Handler) SendSingleEmail(c *fiber.Ctx) error {
|
||||
recipient := strings.TrimSpace(c.FormValue("recipient"))
|
||||
if recipient == "" {
|
||||
|
|
@ -1845,7 +1930,7 @@ func (h *Handler) SendSingleEmail(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/notifications/bulk-email [post]
|
||||
// @Router /api/v1/admin/notifications/bulk-email [post]
|
||||
func (h *Handler) SendBulkEmail(c *fiber.Ctx) error {
|
||||
role := c.FormValue("role")
|
||||
userIDsRaw := c.FormValue("user_ids")
|
||||
|
|
@ -2033,6 +2118,12 @@ func (h *Handler) SendBulkEmail(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
// UnregisterDeviceToken godoc
|
||||
// @Summary UnregisterDeviceToken
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/devices/unregister [post]
|
||||
// @Router /api/v1/devices/unregister [post]
|
||||
func (h *Handler) UnregisterDeviceToken(c *fiber.Ctx) error {
|
||||
type Request struct {
|
||||
DeviceToken string `json:"device_token" validate:"required"`
|
||||
|
|
|
|||
|
|
@ -170,7 +170,6 @@ func mapPracticeFullError(err error, action string) (int, string) {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/practices/{id}/full [get]
|
||||
func (h *Handler) GetLmsPracticeFull(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -240,6 +239,7 @@ func (h *Handler) GetLmsPracticeFull(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id}/full [get]
|
||||
func (h *Handler) GetExamPrepPracticeFull(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -307,7 +307,6 @@ func (h *Handler) GetExamPrepPracticeFull(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/practices/{id}/full [put]
|
||||
func (h *Handler) UpdateLmsPracticeFull(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -381,6 +380,7 @@ func (h *Handler) UpdateLmsPracticeFull(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/exam-prep/practices/{id}/full [put]
|
||||
func (h *Handler) UpdateExamPrepPracticeFull(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import (
|
|||
// @Tags practices
|
||||
// @Accept json
|
||||
// @Param body body domain.CreatePracticeInput true "Practice (optional parents; link later via PUT /practices/:id/parents)"
|
||||
// @Router /api/v1/practices [post]
|
||||
func (h *Handler) CreatePractice(c *fiber.Ctx) error {
|
||||
var req domain.CreatePracticeInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -76,7 +75,6 @@ func (h *Handler) CreatePractice(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size (default 20, max 200)"
|
||||
// @Param offset query int false "Page offset (default 0)"
|
||||
// @Param unlinked_only query bool false "When true, return only practices with no parent links (admin)"
|
||||
// @Router /api/v1/practices [get]
|
||||
func (h *Handler) ListPractices(c *fiber.Ctx) error {
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
|
|
@ -108,7 +106,6 @@ func (h *Handler) ListPractices(c *fiber.Ctx) error {
|
|||
// ListPracticesByCourse godoc
|
||||
// @Tags practices
|
||||
// @Param id path int true "Course ID"
|
||||
// @Router /api/v1/courses/{id}/practices [get]
|
||||
func (h *Handler) ListPracticesByCourse(c *fiber.Ctx) error {
|
||||
courseID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -143,7 +140,6 @@ func (h *Handler) ListPracticesByCourse(c *fiber.Ctx) error {
|
|||
// ListPracticesByModule godoc
|
||||
// @Tags practices
|
||||
// @Param id path int true "Module ID"
|
||||
// @Router /api/v1/modules/{id}/practices [get]
|
||||
func (h *Handler) ListPracticesByModule(c *fiber.Ctx) error {
|
||||
moduleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -178,7 +174,6 @@ func (h *Handler) ListPracticesByModule(c *fiber.Ctx) error {
|
|||
// ListPracticesByLesson godoc
|
||||
// @Tags practices
|
||||
// @Param id path int true "Lesson ID"
|
||||
// @Router /api/v1/lessons/{id}/practices [get]
|
||||
func (h *Handler) ListPracticesByLesson(c *fiber.Ctx) error {
|
||||
lessonID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -218,7 +213,6 @@ type practiceWithStimulusRes struct {
|
|||
// GetPractice godoc
|
||||
// @Tags practices
|
||||
// @Param id path int true "Practice ID"
|
||||
// @Router /api/v1/practices/{id} [get]
|
||||
func (h *Handler) GetPractice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -296,7 +290,6 @@ func practiceAccessForQuestionSet(set domain.QuestionSet) *domain.PracticeAccess
|
|||
// @Tags practices
|
||||
// @Param id path int true "Practice ID"
|
||||
// @Param body body domain.UpdatePracticeInput true "Practice metadata fields to update"
|
||||
// @Router /api/v1/practices/{id} [put]
|
||||
func (h *Handler) UpdatePractice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -333,7 +326,6 @@ func (h *Handler) UpdatePractice(c *fiber.Ctx) error {
|
|||
// @Accept json
|
||||
// @Param id path int true "Practice ID"
|
||||
// @Param body body domain.UpdatePracticeParentsInput true "Parent links (replaces all; use empty array to detach)"
|
||||
// @Router /api/v1/practices/{id}/parents [put]
|
||||
func (h *Handler) UpdatePracticeParents(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -387,7 +379,6 @@ func (h *Handler) UpdatePracticeParents(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Practice ID"
|
||||
// @Param parentKind path string true "Parent kind (COURSE, MODULE, LESSON)"
|
||||
// @Param parentId path int true "Parent entity ID"
|
||||
// @Router /api/v1/practices/{id}/parents/{parentKind}/{parentId} [delete]
|
||||
func (h *Handler) UnlinkPracticeParent(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -431,7 +422,6 @@ func (h *Handler) UnlinkPracticeParent(c *fiber.Ctx) error {
|
|||
// DeletePractice godoc
|
||||
// @Tags practices
|
||||
// @Param id path int true "Practice ID"
|
||||
// @Router /api/v1/practices/{id} [delete]
|
||||
func (h *Handler) DeletePractice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import (
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs [post]
|
||||
func (h *Handler) CreateProgram(c *fiber.Ctx) error {
|
||||
var req domain.CreateProgramInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -66,7 +65,6 @@ func (h *Handler) CreateProgram(c *fiber.Ctx) error {
|
|||
// @Param offset query int false "Offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs [get]
|
||||
func (h *Handler) ListPrograms(c *fiber.Ctx) error {
|
||||
limit, _ := strconv.Atoi(c.Query("limit", "20"))
|
||||
offset, _ := strconv.Atoi(c.Query("offset", "0"))
|
||||
|
|
@ -114,7 +112,6 @@ func (h *Handler) ListPrograms(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Program ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/{id} [get]
|
||||
func (h *Handler) GetProgram(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -172,7 +169,6 @@ func (h *Handler) GetProgram(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/{id} [put]
|
||||
func (h *Handler) UpdateProgram(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -227,7 +223,6 @@ func (h *Handler) UpdateProgram(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Program ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/programs/{id} [delete]
|
||||
func (h *Handler) DeleteProgram(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ func parseOptionalGroupIDQuery(c *fiber.Ctx) (*int64, error) {
|
|||
// @Tags questions
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/questions/component-catalog [get]
|
||||
// @Router /api/v1/admin/questions/component-catalog [get]
|
||||
func (h *Handler) GetQuestionTypeComponentCatalog(c *fiber.Ctx) error {
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Component catalog",
|
||||
|
|
@ -125,7 +125,7 @@ func (h *Handler) GetQuestionTypeComponentCatalog(c *fiber.Ctx) error {
|
|||
// @Param body body validateQuestionTypeDefinitionReq true "Stimulus and response component kinds"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/validate-question-type-definition [post]
|
||||
// @Router /api/v1/admin/questions/validate-question-type-definition [post]
|
||||
func (h *Handler) ValidateQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||
var req validateQuestionTypeDefinitionReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -158,7 +158,7 @@ func (h *Handler) ValidateQuestionTypeDefinition(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions [post]
|
||||
// @Router /api/v1/admin/questions/type-definitions [post]
|
||||
func (h *Handler) CreateQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||
var req createQuestionTypeDefinitionReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -222,7 +222,7 @@ func (h *Handler) CreateQuestionTypeDefinition(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions [get]
|
||||
// @Router /api/v1/admin/questions/type-definitions [get]
|
||||
func (h *Handler) ListQuestionTypeDefinitions(c *fiber.Ctx) error {
|
||||
status := strings.ToUpper(strings.TrimSpace(c.Query("status")))
|
||||
var statusPtr *string
|
||||
|
|
@ -300,7 +300,7 @@ func (h *Handler) ListQuestionTypeDefinitions(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions/{id} [get]
|
||||
// @Router /api/v1/admin/questions/type-definitions/{id} [get]
|
||||
func (h *Handler) GetQuestionTypeDefinitionByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -335,7 +335,7 @@ func (h *Handler) GetQuestionTypeDefinitionByID(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions/{id}/practices [get]
|
||||
// @Router /api/v1/admin/questions/type-definitions/{id}/practices [get]
|
||||
func (h *Handler) ListPracticesByQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -382,7 +382,7 @@ func (h *Handler) ListPracticesByQuestionTypeDefinition(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions/{id} [put]
|
||||
// @Router /api/v1/admin/questions/type-definitions/{id} [put]
|
||||
func (h *Handler) UpdateQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -455,7 +455,7 @@ func (h *Handler) UpdateQuestionTypeDefinition(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definitions/{id} [delete]
|
||||
// @Router /api/v1/admin/questions/type-definitions/{id} [delete]
|
||||
func (h *Handler) DeleteQuestionTypeDefinition(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -490,7 +490,7 @@ func (h *Handler) DeleteQuestionTypeDefinition(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param body body createQuestionTypeDefinitionGroupReq true "Group payload"
|
||||
// @Success 201 {object} domain.Response
|
||||
// @Router /api/v1/questions/type-definition-groups [post]
|
||||
// @Router /api/v1/admin/questions/type-definition-groups [post]
|
||||
func (h *Handler) CreateQuestionTypeDefinitionGroup(c *fiber.Ctx) error {
|
||||
var req createQuestionTypeDefinitionGroupReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -538,7 +538,7 @@ func (h *Handler) CreateQuestionTypeDefinitionGroup(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Page size (default 20, max 200)" default(20)
|
||||
// @Param offset query int false "Page offset" default(0)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/questions/type-definition-groups [get]
|
||||
// @Router /api/v1/admin/questions/type-definition-groups [get]
|
||||
func (h *Handler) ListQuestionTypeDefinitionGroups(c *fiber.Ctx) error {
|
||||
status := strings.ToUpper(strings.TrimSpace(c.Query("status")))
|
||||
var statusPtr *string
|
||||
|
|
@ -592,7 +592,7 @@ func (h *Handler) ListQuestionTypeDefinitionGroups(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Group id"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/type-definition-groups/{id} [get]
|
||||
// @Router /api/v1/admin/questions/type-definition-groups/{id} [get]
|
||||
func (h *Handler) GetQuestionTypeDefinitionGroupByID(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -630,7 +630,7 @@ func (h *Handler) GetQuestionTypeDefinitionGroupByID(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Group id"
|
||||
// @Param body body updateQuestionTypeDefinitionGroupReq true "Update group payload"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/questions/type-definition-groups/{id} [put]
|
||||
// @Router /api/v1/admin/questions/type-definition-groups/{id} [put]
|
||||
func (h *Handler) UpdateQuestionTypeDefinitionGroup(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
@ -686,7 +686,7 @@ func (h *Handler) UpdateQuestionTypeDefinitionGroup(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param id path int true "Group id"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/questions/type-definition-groups/{id} [delete]
|
||||
// @Router /api/v1/admin/questions/type-definition-groups/{id} [delete]
|
||||
func (h *Handler) DeleteQuestionTypeDefinitionGroup(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || id <= 0 {
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ func activityLogQuestionSummary(questionType string, stored string, payload *dom
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions [post]
|
||||
// @Router /api/v1/admin/questions [post]
|
||||
func (h *Handler) CreateQuestion(c *fiber.Ctx) error {
|
||||
var req createQuestionReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -369,7 +369,7 @@ func (h *Handler) CreateQuestion(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/{id} [get]
|
||||
// @Router /api/v1/admin/questions/{id} [get]
|
||||
func (h *Handler) GetQuestionByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -415,7 +415,7 @@ func (h *Handler) GetQuestionByID(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions [get]
|
||||
// @Router /api/v1/admin/questions [get]
|
||||
func (h *Handler) ListQuestions(c *fiber.Ctx) error {
|
||||
questionType := c.Query("question_type")
|
||||
difficulty := c.Query("difficulty")
|
||||
|
|
@ -478,7 +478,7 @@ func (h *Handler) ListQuestions(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/search [get]
|
||||
// @Router /api/v1/admin/questions/search [get]
|
||||
func (h *Handler) SearchQuestions(c *fiber.Ctx) error {
|
||||
query := c.Query("q")
|
||||
if query == "" {
|
||||
|
|
@ -551,7 +551,7 @@ type updateQuestionReq struct {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/{id} [put]
|
||||
// @Router /api/v1/admin/questions/{id} [put]
|
||||
func (h *Handler) UpdateQuestion(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -721,7 +721,7 @@ func (h *Handler) UpdateQuestion(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/questions/{id} [delete]
|
||||
// @Router /api/v1/admin/questions/{id} [delete]
|
||||
func (h *Handler) DeleteQuestion(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -841,7 +841,7 @@ func (h *Handler) enforcePracticeSequenceForStudent(c *fiber.Ctx, set domain.Que
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets [post]
|
||||
// @Router /api/v1/admin/question-sets [post]
|
||||
func (h *Handler) CreateQuestionSet(c *fiber.Ctx) error {
|
||||
var req createQuestionSetReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -910,7 +910,7 @@ func (h *Handler) CreateQuestionSet(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{id} [get]
|
||||
// @Router /api/v1/admin/question-sets/{id} [get]
|
||||
func (h *Handler) GetQuestionSetByID(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -975,7 +975,7 @@ func (h *Handler) GetQuestionSetByID(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets [get]
|
||||
// @Router /api/v1/admin/question-sets [get]
|
||||
func (h *Handler) GetQuestionSetsByType(c *fiber.Ctx) error {
|
||||
setType := c.Query("set_type")
|
||||
if setType == "" {
|
||||
|
|
@ -1038,7 +1038,7 @@ func (h *Handler) GetQuestionSetsByType(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/by-owner [get]
|
||||
// @Router /api/v1/admin/question-sets/by-owner [get]
|
||||
func (h *Handler) GetQuestionSetsByOwner(c *fiber.Ctx) error {
|
||||
ownerType := c.Query("owner_type")
|
||||
ownerIDStr := c.Query("owner_id")
|
||||
|
|
@ -1116,7 +1116,7 @@ type updateQuestionSetReq struct {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{id} [put]
|
||||
// @Router /api/v1/admin/question-sets/{id} [put]
|
||||
func (h *Handler) UpdateQuestionSet(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -1198,7 +1198,7 @@ func (h *Handler) UpdateQuestionSet(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{id} [delete]
|
||||
// @Router /api/v1/admin/question-sets/{id} [delete]
|
||||
func (h *Handler) DeleteQuestionSet(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||
|
|
@ -1343,7 +1343,7 @@ func questionSetItemsToRes(
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/questions [post]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/questions [post]
|
||||
func (h *Handler) AddQuestionToSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -1415,7 +1415,7 @@ func (h *Handler) AddQuestionToSet(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/question-types [get]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/question-types [get]
|
||||
func (h *Handler) GetQuestionTypesInSet(c *fiber.Ctx) error {
|
||||
setID, err := strconv.ParseInt(c.Params("setId"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -1501,7 +1501,7 @@ func (h *Handler) questionSetStimulusContexts(ctx context.Context, setID int64)
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/questions [get]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/questions [get]
|
||||
func (h *Handler) GetQuestionsInSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -1760,7 +1760,7 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
|
|||
|
||||
// The exam-prep route is authoritative for the rebuilt hierarchy; legacy IDs
|
||||
// may overlap while both schemas exist during migration.
|
||||
isExamPrepRoute := strings.HasPrefix(c.Path(), "/api/v1/exam-prep/")
|
||||
isExamPrepRoute := strings.Contains(c.Route().Path, "/exam-prep/")
|
||||
var (
|
||||
lmsPractice *domain.Practice
|
||||
examPractice *domain.ExamPrepPractice
|
||||
|
|
@ -1902,7 +1902,7 @@ func (h *Handler) CompletePractice(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/questions/{questionId} [delete]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/questions/{questionId} [delete]
|
||||
func (h *Handler) RemoveQuestionFromSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -1962,7 +1962,7 @@ type updateQuestionOrderReq struct {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/questions/{questionId}/order [put]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/questions/{questionId}/order [put]
|
||||
func (h *Handler) UpdateQuestionOrderInSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -2046,7 +2046,7 @@ type addUserPersonaReq struct {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/personas [get]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/personas [get]
|
||||
func (h *Handler) GetUserPersonasByQuestionSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -2095,7 +2095,7 @@ func (h *Handler) GetUserPersonasByQuestionSet(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/personas [post]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/personas [post]
|
||||
func (h *Handler) AddUserPersonaToQuestionSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
@ -2148,7 +2148,7 @@ func (h *Handler) AddUserPersonaToQuestionSet(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/question-sets/{setId}/personas/{userId} [delete]
|
||||
// @Router /api/v1/admin/question-sets/{setId}/personas/{userId} [delete]
|
||||
func (h *Handler) RemoveUserPersonaFromQuestionSet(c *fiber.Ctx) error {
|
||||
setIDStr := c.Params("setId")
|
||||
setID, err := strconv.ParseInt(setIDStr, 10, 64)
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ func (h *Handler) GetMyRating(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/ratings [get]
|
||||
// @Router /api/v1/ratings [get]
|
||||
func (h *Handler) GetRatingsByTarget(c *fiber.Ctx) error {
|
||||
targetType := c.Query("target_type")
|
||||
|
|
@ -228,6 +229,7 @@ func (h *Handler) GetRatingsByTarget(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/ratings/summary [get]
|
||||
// @Router /api/v1/ratings/summary [get]
|
||||
func (h *Handler) GetRatingSummary(c *fiber.Ctx) error {
|
||||
targetType := c.Query("target_type")
|
||||
|
|
@ -305,6 +307,7 @@ func (h *Handler) GetMyRatings(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/ratings/{id} [delete]
|
||||
// @Router /api/v1/ratings/{id} [delete]
|
||||
func (h *Handler) DeleteRating(c *fiber.Ctx) error {
|
||||
userID := c.Locals("user_id").(int64)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
// @Param page_size query int false "Page size (default: 20)"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles [get]
|
||||
// @Router /api/v1/admin/rbac/roles [get]
|
||||
func (h *Handler) ListRoles(c *fiber.Ctx) error {
|
||||
filter := domain.RoleListFilter{
|
||||
Query: c.Query("query"),
|
||||
|
|
@ -76,7 +76,7 @@ func (h *Handler) ListRoles(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles/{id} [get]
|
||||
// @Router /api/v1/admin/rbac/roles/{id} [get]
|
||||
func (h *Handler) GetRoleByID(c *fiber.Ctx) error {
|
||||
roleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || roleID <= 0 {
|
||||
|
|
@ -136,7 +136,7 @@ func (h *Handler) GetRoleByID(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} domain.Response{data=domain.RoleRecord}
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles [post]
|
||||
// @Router /api/v1/admin/rbac/roles [post]
|
||||
func (h *Handler) CreateRole(c *fiber.Ctx) error {
|
||||
var req domain.CreateRoleReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -208,7 +208,7 @@ func (h *Handler) CreateRole(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles/{id} [put]
|
||||
// @Router /api/v1/admin/rbac/roles/{id} [put]
|
||||
func (h *Handler) UpdateRole(c *fiber.Ctx) error {
|
||||
roleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || roleID <= 0 {
|
||||
|
|
@ -285,7 +285,7 @@ func (h *Handler) UpdateRole(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles/{id} [delete]
|
||||
// @Router /api/v1/admin/rbac/roles/{id} [delete]
|
||||
func (h *Handler) DeleteRole(c *fiber.Ctx) error {
|
||||
roleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || roleID <= 0 {
|
||||
|
|
@ -339,7 +339,7 @@ func (h *Handler) DeleteRole(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles/{id}/permissions [put]
|
||||
// @Router /api/v1/admin/rbac/roles/{id}/permissions [put]
|
||||
func (h *Handler) SetRolePermissions(c *fiber.Ctx) error {
|
||||
roleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || roleID <= 0 {
|
||||
|
|
@ -416,7 +416,7 @@ func (h *Handler) SetRolePermissions(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response{data=[]domain.Permission}
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/roles/{id}/permissions [get]
|
||||
// @Router /api/v1/admin/rbac/roles/{id}/permissions [get]
|
||||
func (h *Handler) GetRolePermissions(c *fiber.Ctx) error {
|
||||
roleID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || roleID <= 0 {
|
||||
|
|
@ -457,7 +457,7 @@ func (h *Handler) GetRolePermissions(c *fiber.Ctx) error {
|
|||
// @Security Bearer
|
||||
// @Success 200 {object} domain.Response{data=[]domain.Permission}
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/permissions [get]
|
||||
// @Router /api/v1/admin/rbac/permissions [get]
|
||||
func (h *Handler) ListPermissions(c *fiber.Ctx) error {
|
||||
permissions, err := h.rbacSvc.ListPermissions(c.Context())
|
||||
if err != nil {
|
||||
|
|
@ -494,7 +494,7 @@ func (h *Handler) ListPermissions(c *fiber.Ctx) error {
|
|||
// @Security Bearer
|
||||
// @Success 200 {object} domain.Response{data=[]string}
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/permissions/groups [get]
|
||||
// @Router /api/v1/admin/rbac/permissions/groups [get]
|
||||
func (h *Handler) ListPermissionGroups(c *fiber.Ctx) error {
|
||||
groups, err := h.rbacSvc.ListPermissionGroups(c.Context())
|
||||
if err != nil {
|
||||
|
|
@ -526,7 +526,7 @@ func (h *Handler) ListPermissionGroups(c *fiber.Ctx) error {
|
|||
// @Security Bearer
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/rbac/permissions/sync [post]
|
||||
// @Router /api/v1/admin/rbac/permissions/sync [post]
|
||||
func (h *Handler) SyncPermissions(c *fiber.Ctx) error {
|
||||
if err := h.rbacSvc.SeedPermissions(c.Context()); err != nil {
|
||||
h.mongoLoggerSvc.Error("Failed to seed permissions",
|
||||
|
|
|
|||
|
|
@ -57,6 +57,9 @@ func referralPagination(c *fiber.Ctx) (int32, int32, error) {
|
|||
}
|
||||
|
||||
// CreateReferralCode creates or returns the authenticated learner's stable share code.
|
||||
// @Router /api/v1/referrals/code [post]
|
||||
// @Summary CreateReferralCode
|
||||
// @Tags client
|
||||
func (h *Handler) CreateReferralCode(c *fiber.Ctx) error {
|
||||
id, err := referralLearner(c)
|
||||
if err != nil {
|
||||
|
|
@ -65,7 +68,17 @@ func (h *Handler) CreateReferralCode(c *fiber.Ctx) error {
|
|||
code, err := h.referralSvc.Code(c.Context(), id)
|
||||
return referralResponse(c, fiber.Map{"code": code}, err)
|
||||
}
|
||||
// GetReferralCode godoc
|
||||
// @Summary GetReferralCode
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/referrals/code [get]
|
||||
func (h *Handler) GetReferralCode(c *fiber.Ctx) error { return h.CreateReferralCode(c) }
|
||||
// GetMyReferrals godoc
|
||||
// @Summary GetMyReferrals
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/referrals/me [get]
|
||||
func (h *Handler) GetMyReferrals(c *fiber.Ctx) error {
|
||||
id, err := referralLearner(c)
|
||||
if err != nil {
|
||||
|
|
@ -74,6 +87,11 @@ func (h *Handler) GetMyReferrals(c *fiber.Ctx) error {
|
|||
data, err := h.referralSvc.Overview(c.Context(), id)
|
||||
return referralResponse(c, data, err)
|
||||
}
|
||||
// ApplyReferralCode godoc
|
||||
// @Summary ApplyReferralCode
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/referrals/apply [post]
|
||||
func (h *Handler) ApplyReferralCode(c *fiber.Ctx) error {
|
||||
id, err := referralLearner(c)
|
||||
if err != nil {
|
||||
|
|
@ -87,6 +105,11 @@ func (h *Handler) ApplyReferralCode(c *fiber.Ctx) error {
|
|||
}
|
||||
return referralResponse(c, nil, h.referralSvc.Apply(c.Context(), id, input.Code))
|
||||
}
|
||||
// ListMyReferrals godoc
|
||||
// @Summary ListMyReferrals
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/referrals [get]
|
||||
func (h *Handler) ListMyReferrals(c *fiber.Ctx) error {
|
||||
id, err := referralLearner(c)
|
||||
if err != nil {
|
||||
|
|
@ -99,6 +122,11 @@ func (h *Handler) ListMyReferrals(c *fiber.Ctx) error {
|
|||
data, err := h.referralSvc.List(c.Context(), id, limit, offset)
|
||||
return referralResponse(c, fiber.Map{"items": data, "limit": limit, "offset": offset}, err)
|
||||
}
|
||||
// GetReferralWallet godoc
|
||||
// @Summary GetReferralWallet
|
||||
// @Tags client
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/referrals/wallet [get]
|
||||
func (h *Handler) GetReferralWallet(c *fiber.Ctx) error {
|
||||
id, err := referralLearner(c)
|
||||
if err != nil {
|
||||
|
|
@ -115,6 +143,11 @@ func (h *Handler) GetReferralWallet(c *fiber.Ctx) error {
|
|||
entries, err := h.referralSvc.Commissions(c.Context(), id, limit, offset)
|
||||
return referralResponse(c, fiber.Map{"balances": overview.Wallet, "transactions": entries, "limit": limit, "offset": offset}, err)
|
||||
}
|
||||
// GetReferralSettings godoc
|
||||
// @Summary GetReferralSettings
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/referrals/settings [get]
|
||||
func (h *Handler) GetReferralSettings(c *fiber.Ctx) error {
|
||||
if _, err := referralAdmin(c); err != nil {
|
||||
return err
|
||||
|
|
@ -122,6 +155,11 @@ func (h *Handler) GetReferralSettings(c *fiber.Ctx) error {
|
|||
data, err := h.referralSvc.Settings(c.Context())
|
||||
return referralResponse(c, data, err)
|
||||
}
|
||||
// UpdateReferralSettings godoc
|
||||
// @Summary UpdateReferralSettings
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/referrals/settings [put]
|
||||
func (h *Handler) UpdateReferralSettings(c *fiber.Ctx) error {
|
||||
id, err := referralAdmin(c)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// GetGlobalSettingList godoc
|
||||
// @Summary GetGlobalSettingList
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/settings [get]
|
||||
func (h *Handler) GetGlobalSettingList(c *fiber.Ctx) error {
|
||||
settingsList, err := h.settingSvc.GetGlobalSettingList(c.Context())
|
||||
|
||||
|
|
@ -30,6 +35,11 @@ func (h *Handler) GetGlobalSettingList(c *fiber.Ctx) error {
|
|||
return response.WriteJSON(c, fiber.StatusOK, "All Settings retrieved successfully", res, nil)
|
||||
}
|
||||
|
||||
// GetGlobalSettingByKey godoc
|
||||
// @Summary GetGlobalSettingByKey
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/settings/{key} [get]
|
||||
func (h *Handler) GetGlobalSettingByKey(c *fiber.Ctx) error {
|
||||
settingKey := c.Params("key")
|
||||
if settingKey == "" {
|
||||
|
|
@ -57,6 +67,11 @@ func (h *Handler) GetGlobalSettingByKey(c *fiber.Ctx) error {
|
|||
|
||||
}
|
||||
|
||||
// UpdateGlobalSettingList godoc
|
||||
// @Summary UpdateGlobalSettingList
|
||||
// @Tags admin
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/settings [put]
|
||||
func (h *Handler) UpdateGlobalSettingList(c *fiber.Ctx) error {
|
||||
|
||||
var req domain.SaveSettingListReq
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ type autoRenewReq struct {
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/subscription-plans [post]
|
||||
// @Router /api/v1/admin/subscription-plans [post]
|
||||
func (h *Handler) CreateSubscriptionPlan(c *fiber.Ctx) error {
|
||||
var req createPlanReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -206,9 +206,13 @@ func (h *Handler) CreateSubscriptionPlan(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/subscription-plans [get]
|
||||
// @Router /api/v1/subscription-plans [get]
|
||||
func (h *Handler) ListSubscriptionPlans(c *fiber.Ctx) error {
|
||||
activeOnly := c.Query("active_only", "true") == "true"
|
||||
if c.Locals("api_audience") == "client" {
|
||||
activeOnly = true
|
||||
}
|
||||
|
||||
var categoryFilter *string
|
||||
if raw := strings.TrimSpace(c.Query("category")); raw != "" {
|
||||
|
|
@ -249,6 +253,7 @@ func (h *Handler) ListSubscriptionPlans(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Plan ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/subscription-plans/{id} [get]
|
||||
// @Router /api/v1/subscription-plans/{id} [get]
|
||||
func (h *Handler) GetSubscriptionPlan(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
|
|
@ -265,6 +270,10 @@ func (h *Handler) GetSubscriptionPlan(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if c.Locals("api_audience") == "client" && !plan.IsActive {
|
||||
return fiber.NewError(fiber.StatusNotFound, "Subscription plan not found")
|
||||
}
|
||||
|
||||
return c.JSON(domain.Response{
|
||||
Message: "Subscription plan retrieved successfully",
|
||||
Data: planToRes(plan),
|
||||
|
|
@ -282,7 +291,7 @@ func (h *Handler) GetSubscriptionPlan(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/subscription-plans/{id} [put]
|
||||
// @Router /api/v1/admin/subscription-plans/{id} [put]
|
||||
func (h *Handler) UpdateSubscriptionPlan(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -383,7 +392,7 @@ func (h *Handler) UpdateSubscriptionPlan(c *fiber.Ctx) error {
|
|||
// @Param id path int true "Plan ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/subscription-plans/{id} [delete]
|
||||
// @Router /api/v1/admin/subscription-plans/{id} [delete]
|
||||
func (h *Handler) DeleteSubscriptionPlan(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -438,8 +447,8 @@ func (h *Handler) DeleteSubscriptionPlan(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/subscriptions [post]
|
||||
// @deprecated Use POST /api/v1/payments/subscribe for user subscriptions with payment
|
||||
// @Router /api/v1/subscriptions [post]
|
||||
func (h *Handler) Subscribe(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func mapTeamRoleToRole(teamRole domain.TeamRole) domain.Role {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/login [post]
|
||||
// @Router /api/v1/admin/team/login [post]
|
||||
func (h *Handler) TeamMemberLogin(c *fiber.Ctx) error {
|
||||
var req domain.TeamMemberLoginReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -185,7 +185,7 @@ func (h *Handler) TeamMemberLogin(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/refresh [post]
|
||||
// @Router /api/v1/admin/team/refresh [post]
|
||||
func (h *Handler) TeamMemberRefresh(c *fiber.Ctx) error {
|
||||
var req teamMemberRefreshReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -265,7 +265,7 @@ func (h *Handler) TeamMemberRefresh(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members [post]
|
||||
// @Router /api/v1/admin/team/members [post]
|
||||
func (h *Handler) CreateTeamMember(c *fiber.Ctx) error {
|
||||
var req domain.CreateTeamMemberReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -361,7 +361,7 @@ func (h *Handler) CreateTeamMember(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id} [get]
|
||||
// @Router /api/v1/admin/team/members/{id} [get]
|
||||
func (h *Handler) GetTeamMember(c *fiber.Ctx) error {
|
||||
memberIDStr := c.Params("id")
|
||||
memberID, err := strconv.ParseInt(memberIDStr, 10, 64)
|
||||
|
|
@ -417,7 +417,7 @@ func (h *Handler) GetTeamMember(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members [get]
|
||||
// @Router /api/v1/admin/team/members [get]
|
||||
func (h *Handler) GetAllTeamMembers(c *fiber.Ctx) error {
|
||||
filter := domain.TeamMemberFilter{}
|
||||
|
||||
|
|
@ -505,7 +505,7 @@ func (h *Handler) GetAllTeamMembers(c *fiber.Ctx) error {
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id} [put]
|
||||
// @Router /api/v1/admin/team/members/{id} [put]
|
||||
func (h *Handler) UpdateTeamMember(c *fiber.Ctx) error {
|
||||
memberIDStr := c.Params("id")
|
||||
memberID, err := strconv.ParseInt(memberIDStr, 10, 64)
|
||||
|
|
@ -595,7 +595,7 @@ func (h *Handler) UpdateTeamMember(c *fiber.Ctx) error {
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id}/status [patch]
|
||||
// @Router /api/v1/admin/team/members/{id}/status [patch]
|
||||
func (h *Handler) UpdateTeamMemberStatus(c *fiber.Ctx) error {
|
||||
memberIDStr := c.Params("id")
|
||||
memberID, err := strconv.ParseInt(memberIDStr, 10, 64)
|
||||
|
|
@ -696,7 +696,7 @@ func (h *Handler) UpdateTeamMemberStatus(c *fiber.Ctx) error {
|
|||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id} [delete]
|
||||
// @Router /api/v1/admin/team/members/{id} [delete]
|
||||
func (h *Handler) DeleteTeamMember(c *fiber.Ctx) error {
|
||||
memberIDStr := c.Params("id")
|
||||
memberID, err := strconv.ParseInt(memberIDStr, 10, 64)
|
||||
|
|
@ -756,7 +756,7 @@ func (h *Handler) DeleteTeamMember(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/stats [get]
|
||||
// @Router /api/v1/admin/team/stats [get]
|
||||
func (h *Handler) GetTeamMemberStats(c *fiber.Ctx) error {
|
||||
stats, err := h.teamSvc.GetTeamMemberStats(c.Context())
|
||||
if err != nil {
|
||||
|
|
@ -793,7 +793,7 @@ func (h *Handler) GetTeamMemberStats(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id}/change-password [post]
|
||||
// @Router /api/v1/admin/team/members/{id}/change-password [post]
|
||||
func (h *Handler) ChangeTeamMemberPassword(c *fiber.Ctx) error {
|
||||
memberIDStr := c.Params("id")
|
||||
memberID, err := strconv.ParseInt(memberIDStr, 10, 64)
|
||||
|
|
@ -870,7 +870,7 @@ func (h *Handler) ChangeTeamMemberPassword(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/me [get]
|
||||
// @Router /api/v1/admin/team/me [get]
|
||||
func (h *Handler) GetMyTeamProfile(c *fiber.Ctx) error {
|
||||
memberID, ok := c.Locals("user_id").(int64)
|
||||
if !ok {
|
||||
|
|
@ -921,7 +921,7 @@ func (h *Handler) GetMyTeamProfile(c *fiber.Ctx) error {
|
|||
// @Failure 401 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/me [put]
|
||||
// @Router /api/v1/admin/team/me [put]
|
||||
func (h *Handler) UpdateMyTeamProfile(c *fiber.Ctx) error {
|
||||
memberID, ok := c.Locals("user_id").(int64)
|
||||
if !ok {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func mapTeamInvitationListItem(row domain.TeamInvitationWithMember) teamInvitati
|
|||
// @Success 201 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/invite [post]
|
||||
// @Router /api/v1/admin/team/members/invite [post]
|
||||
func (h *Handler) InviteTeamMember(c *fiber.Ctx) error {
|
||||
if err := requireSuperAdminForTeamInvitation(c); err != nil {
|
||||
return err
|
||||
|
|
@ -115,7 +115,7 @@ func (h *Handler) InviteTeamMember(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} domain.Response
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/members/{id}/resend-invite [post]
|
||||
// @Router /api/v1/admin/team/members/{id}/resend-invite [post]
|
||||
func (h *Handler) ResendTeamInvitation(c *fiber.Ctx) error {
|
||||
if err := requireSuperAdminForTeamInvitation(c); err != nil {
|
||||
return err
|
||||
|
|
@ -158,7 +158,7 @@ func (h *Handler) ResendTeamInvitation(c *fiber.Ctx) error {
|
|||
// @Param limit query int false "Limit (default 20)"
|
||||
// @Param offset query int false "Offset (default 0)"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/team/invitations [get]
|
||||
// @Router /api/v1/admin/team/invitations [get]
|
||||
func (h *Handler) ListTeamInvitations(c *fiber.Ctx) error {
|
||||
status := strings.TrimSpace(c.Query("status"))
|
||||
var statusPtr *string
|
||||
|
|
@ -199,7 +199,7 @@ func (h *Handler) ListTeamInvitations(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param id path int true "Invitation ID"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/team/invitations/{id}/revoke [post]
|
||||
// @Router /api/v1/admin/team/invitations/{id}/revoke [post]
|
||||
func (h *Handler) RevokeTeamInvitation(c *fiber.Ctx) error {
|
||||
invitationID, err := strconv.ParseInt(c.Params("id"), 10, 64)
|
||||
if err != nil || invitationID <= 0 {
|
||||
|
|
@ -229,7 +229,7 @@ func (h *Handler) RevokeTeamInvitation(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param token query string true "Invitation token"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/team/invitations/verify [get]
|
||||
// @Router /api/v1/admin/team/invitations/verify [get]
|
||||
func (h *Handler) VerifyTeamInvitation(c *fiber.Ctx) error {
|
||||
token := strings.TrimSpace(c.Query("token"))
|
||||
if token == "" {
|
||||
|
|
@ -261,7 +261,7 @@ func (h *Handler) VerifyTeamInvitation(c *fiber.Ctx) error {
|
|||
// @Produce json
|
||||
// @Param body body domain.AcceptTeamInvitationReq true "Accept invitation payload"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/team/invitations/accept [post]
|
||||
// @Router /api/v1/admin/team/invitations/accept [post]
|
||||
func (h *Handler) AcceptTeamInvitation(c *fiber.Ctx) error {
|
||||
var req domain.AcceptTeamInvitationReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
// @Param email query string true "Team member email"
|
||||
// @Param otp query string true "Reset OTP from the email link"
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Router /api/v1/team/verifyResetCode [get]
|
||||
// @Router /api/v1/admin/team/verifyResetCode [get]
|
||||
func (h *Handler) VerifyTeamPasswordReset(c *fiber.Ctx) error {
|
||||
email := c.Query("email")
|
||||
otp := c.Query("otp")
|
||||
|
|
@ -39,7 +39,7 @@ func (h *Handler) VerifyTeamPasswordReset(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/sendResetCode [post]
|
||||
// @Router /api/v1/admin/team/sendResetCode [post]
|
||||
func (h *Handler) SendTeamPasswordReset(c *fiber.Ctx) error {
|
||||
var req domain.TeamSendPasswordResetReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -76,7 +76,7 @@ func (h *Handler) SendTeamPasswordReset(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/team/resetPassword [post]
|
||||
// @Router /api/v1/admin/team/resetPassword [post]
|
||||
func (h *Handler) ResetTeamPassword(c *fiber.Ctx) error {
|
||||
var req domain.TeamResetPasswordReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
|
|||
|
|
@ -284,7 +284,6 @@ type TransactionApproverRes struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/t-approver/{id} [get]
|
||||
func (h *Handler) GetTransactionApproverByID(c *fiber.Ctx) error {
|
||||
userIDstr := c.Params("id")
|
||||
userID, err := strconv.ParseInt(userIDstr, 10, 64)
|
||||
|
|
@ -364,7 +363,6 @@ type updateTransactionApproverReq struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/t-approver/{id} [put]
|
||||
func (h *Handler) UpdateTransactionApprover(c *fiber.Ctx) error {
|
||||
var req updateTransactionApproverReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import (
|
|||
// @Security Bearer
|
||||
// @Success 200 {object} domain.Response{data=domain.UserSummary}
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/users/summary [get]
|
||||
// @Router /api/v1/admin/users/summary [get]
|
||||
func (h *Handler) GetUserSummary(c *fiber.Ctx) error {
|
||||
summary, err := h.userSvc.GetUserSummary(c.Context())
|
||||
if err != nil {
|
||||
|
|
@ -246,7 +246,7 @@ func (h *Handler) UpdateUserKnowledgeLevel(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/otp/resend [post]
|
||||
// @Router /api/v1/user/resend-otp [post]
|
||||
func (h *Handler) ResendOtp(c *fiber.Ctx) error {
|
||||
var req domain.ResendOtpReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -386,7 +386,7 @@ func (h *Handler) ResendOtp(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/user/{user_id}/is-pending [get]
|
||||
// @Router /api/v1/user/{user_name}/is-pending [get]
|
||||
func (h *Handler) CheckUserPending(c *fiber.Ctx) error {
|
||||
userID, err := strconv.ParseInt(c.Params("user_id"), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -443,7 +443,7 @@ func (h *Handler) CheckUserPending(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/users [get]
|
||||
// @Router /api/v1/admin/users [get]
|
||||
func (h *Handler) GetAllUsers(c *fiber.Ctx) error {
|
||||
filter, err := parseUserListFilter(c)
|
||||
if err != nil {
|
||||
|
|
@ -674,7 +674,7 @@ func (h *Handler) ListAccountDeletionRequests(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/user/status [patch]
|
||||
// @Router /api/v1/admin/user/status [patch]
|
||||
func (h *Handler) UpdateUserStatus(c *fiber.Ctx) error {
|
||||
var req struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
|
|
@ -846,7 +846,6 @@ type GetTenantSlugByToken struct {
|
|||
// @Success 200 {object} CheckPhoneEmailExistRes
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/tenant [get]
|
||||
func (h *Handler) GetTenantSlugByToken(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok || userID == 0 {
|
||||
|
|
@ -919,7 +918,7 @@ type CheckPhoneEmailExistRes struct {
|
|||
// @Success 200 {object} CheckPhoneEmailExistRes
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user/checkPhoneEmailExist [post]
|
||||
// @Router /api/v1/user/checkPhoneEmailExist [post]
|
||||
func (h *Handler) CheckPhoneEmailExist(c *fiber.Ctx) error {
|
||||
// companyID := c.Locals("company_id").(domain.ValidInt64)
|
||||
// if !companyID.Valid {
|
||||
|
|
@ -977,7 +976,7 @@ type RegisterCodeReq struct {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user/sendRegisterCode [post]
|
||||
// @Router /api/v1/user/sendRegisterCode [post]
|
||||
func (h *Handler) SendRegisterCode(c *fiber.Ctx) error {
|
||||
// companyID := c.Locals("company_id").(domain.ValidInt64)
|
||||
// if !companyID.Valid {
|
||||
|
|
@ -1038,7 +1037,7 @@ func (h *Handler) SendRegisterCode(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user/register [post]
|
||||
// @Router /api/v1/user/register [post]
|
||||
func (h *Handler) RegisterUser(c *fiber.Ctx) error {
|
||||
var req domain.RegisterUserReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -1231,7 +1230,6 @@ func (h *Handler) SendResetCode(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user/sendResetCode [post]
|
||||
func (h *Handler) SendTenantResetCode(c *fiber.Ctx) error {
|
||||
// companyID := c.Locals("company_id").(domain.ValidInt64)
|
||||
// if !companyID.Valid {
|
||||
|
|
@ -1362,7 +1360,6 @@ func (h *Handler) ResetPassword(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/{tenant_slug}/user/resetPassword [post]
|
||||
func (h *Handler) ResetTenantPassword(c *fiber.Ctx) error {
|
||||
// Reuse the main ResetPassword handler
|
||||
return h.ResetPassword(c)
|
||||
|
|
@ -1378,7 +1375,7 @@ func (h *Handler) ResetTenantPassword(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/{tenant_slug}/user/user-profile [get]
|
||||
// @Router /api/v1/user/user-profile [get]
|
||||
func (h *Handler) GetUserProfile(c *fiber.Ctx) error {
|
||||
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
|
|
@ -1500,7 +1497,7 @@ type AdminProfileRes struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/{tenant_slug}/user/admin-profile [get]
|
||||
// @Router /api/v1/admin/user/admin-profile [get]
|
||||
func (h *Handler) AdminProfile(c *fiber.Ctx) error {
|
||||
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
|
|
@ -1631,7 +1628,7 @@ type SearchUserByNameOrPhoneReq struct {
|
|||
// @Success 200 {object} domain.UserProfileResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/user/search [post]
|
||||
// @Router /api/v1/admin/user/search [post]
|
||||
func (h *Handler) SearchUserByNameOrPhone(c *fiber.Ctx) error {
|
||||
var req SearchUserByNameOrPhoneReq
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -1767,7 +1764,7 @@ func (h *Handler) SearchUserByNameOrPhone(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 401 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/user/single/{id} [get]
|
||||
// @Router /api/v1/admin/user/single/{id} [get]
|
||||
func (h *Handler) GetUserByID(c *fiber.Ctx) error {
|
||||
userIDstr := c.Params("id")
|
||||
userID, err := strconv.ParseInt(userIDstr, 10, 64)
|
||||
|
|
@ -1885,7 +1882,7 @@ func (h *Handler) GetUserByID(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} response.APIResponse
|
||||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Router /api/v1/user/delete/{id} [delete]
|
||||
// @Router /api/v1/admin/user/delete/{id} [delete]
|
||||
func (h *Handler) DeleteUser(c *fiber.Ctx) error {
|
||||
userIDstr := c.Params("id")
|
||||
userID, err := strconv.ParseInt(userIDstr, 10, 64)
|
||||
|
|
@ -2047,7 +2044,7 @@ func (h *Handler) CancelMyUserAccountDeletion(c *fiber.Ctx) error {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/internal/users/purge-due-deletions [post]
|
||||
// @Router /api/v1/admin/internal/users/purge-due-deletions [post]
|
||||
func (h *Handler) PurgeDueDeletedUsers(c *fiber.Ctx) error {
|
||||
limit := int32(c.QueryInt("limit", int(defaultDeletePurgeBatchSize)))
|
||||
if limit <= 0 {
|
||||
|
|
@ -2098,6 +2095,7 @@ type UpdateUserSuspendRes struct {
|
|||
// @Failure 400 {object} response.APIResponse
|
||||
// @Failure 500 {object} response.APIResponse
|
||||
// @Security Bearer
|
||||
// @Router /api/v1/admin/user/{id}/profile-picture [post]
|
||||
// @Router /api/v1/user/{id}/profile-picture [post]
|
||||
func (h *Handler) UploadProfilePicture(c *fiber.Ctx) error {
|
||||
idStr := c.Params("id")
|
||||
|
|
@ -2109,6 +2107,10 @@ func (h *Handler) UploadProfilePicture(c *fiber.Ctx) error {
|
|||
})
|
||||
}
|
||||
|
||||
if c.Locals("api_audience") == "client" && c.Locals("user_id") != userID {
|
||||
return fiber.NewError(fiber.StatusForbidden, "You can only change your own profile picture")
|
||||
}
|
||||
|
||||
// JSON mode: accept already uploaded URL and set it directly.
|
||||
if strings.Contains(strings.ToLower(c.Get("Content-Type")), "application/json") {
|
||||
var req struct {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import (
|
|||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 403 {object} domain.ErrorResponse
|
||||
// @Failure 404 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/videos/engagement/heartbeat [post]
|
||||
// @Router /api/v1/exam-prep/videos/engagement/heartbeat [post]
|
||||
func (h *Handler) RecordVideoEngagementHeartbeat(c *fiber.Ctx) error {
|
||||
var req domain.VideoEngagementHeartbeatInput
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
|
|
@ -41,13 +41,13 @@ func (h *Handler) RecordVideoEngagementHeartbeat(c *fiber.Ctx) error {
|
|||
|
||||
uid := c.Locals("user_id").(int64)
|
||||
role := c.Locals("role").(domain.Role)
|
||||
if strings.HasPrefix(c.Path(), "/api/v1/exam-prep/") && req.ContentKind != domain.VideoContentKindExamPrepLesson {
|
||||
if strings.Contains(c.Route().Path, "/exam-prep/") && req.ContentKind != domain.VideoContentKindExamPrepLesson {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
|
||||
Message: "Exam-prep routes accept exam-prep lesson video sessions only",
|
||||
})
|
||||
}
|
||||
|
||||
if req.ContentKind == domain.VideoContentKindLMSLesson && !strings.HasPrefix(c.Path(), "/api/v1/exam-prep/") {
|
||||
if req.ContentKind == domain.VideoContentKindLMSLesson && !strings.Contains(c.Route().Path, "/exam-prep/") {
|
||||
les, err := h.lessonSvc.GetByID(c.Context(), req.ContentID)
|
||||
if err != nil {
|
||||
if errors.Is(err, lessons.ErrLessonNotFound) {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ func vimeoVideoInfoToResponse(info *vimeoservice.VideoInfo) VimeoVideoResponse {
|
|||
// @Success 200 {object} domain.Response{data=[]handlers.VimeoVideoResponse,metadata=handlers.VimeoVideosListMetadata}
|
||||
// @Failure 503 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/videos [get]
|
||||
// @Router /api/v1/admin/vimeo/videos [get]
|
||||
func (h *Handler) ListVimeoVideos(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -192,7 +192,7 @@ func (h *Handler) ListVimeoVideos(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} VimeoVideoResponse
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/videos/{video_id} [get]
|
||||
// @Router /api/v1/admin/vimeo/videos/{video_id} [get]
|
||||
func (h *Handler) GetVimeoVideo(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -235,7 +235,7 @@ func (h *Handler) GetVimeoVideo(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} VimeoUploadResponse
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/uploads/pull [post]
|
||||
// @Router /api/v1/admin/vimeo/uploads/pull [post]
|
||||
func (h *Handler) CreatePullUpload(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -292,7 +292,7 @@ func (h *Handler) CreatePullUpload(c *fiber.Ctx) error {
|
|||
// @Success 201 {object} VimeoUploadResponse
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/uploads/tus [post]
|
||||
// @Router /api/v1/admin/vimeo/uploads/tus [post]
|
||||
func (h *Handler) CreateTusUpload(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -355,7 +355,7 @@ func (h *Handler) CreateTusUpload(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} VimeoEmbedResponse
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/videos/{video_id}/embed [get]
|
||||
// @Router /api/v1/admin/vimeo/videos/{video_id}/embed [get]
|
||||
func (h *Handler) GetEmbedCode(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -421,7 +421,7 @@ func (h *Handler) GetEmbedCode(c *fiber.Ctx) error {
|
|||
// @Success 204
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/videos/{video_id} [delete]
|
||||
// @Router /api/v1/admin/vimeo/videos/{video_id} [delete]
|
||||
func (h *Handler) DeleteVimeoVideo(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -465,7 +465,7 @@ func (h *Handler) DeleteVimeoVideo(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/vimeo/videos/{video_id}/status [get]
|
||||
// @Router /api/v1/admin/vimeo/videos/{video_id}/status [get]
|
||||
func (h *Handler) GetTranscodeStatus(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
return c.Status(fiber.StatusServiceUnavailable).JSON(domain.ErrorResponse{
|
||||
|
|
@ -512,6 +512,7 @@ func (h *Handler) GetTranscodeStatus(c *fiber.Ctx) error {
|
|||
// @Param height query int false "Player height" default(360)
|
||||
// @Success 200 {object} domain.Response
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/vimeo/sample [get]
|
||||
// @Router /api/v1/vimeo/sample [get]
|
||||
func (h *Handler) GetSampleVideo(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
|
|
@ -556,6 +557,7 @@ func (h *Handler) GetSampleVideo(c *fiber.Ctx) error {
|
|||
// @Success 200 {object} vimeo.OEmbedResponse
|
||||
// @Failure 400 {object} domain.ErrorResponse
|
||||
// @Failure 500 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/admin/vimeo/oembed [get]
|
||||
// @Router /api/v1/vimeo/oembed [get]
|
||||
func (h *Handler) GetOEmbed(c *fiber.Ctx) error {
|
||||
if h.vimeoSvc == nil {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,14 @@ func (a *App) authMiddleware(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid access token")
|
||||
}
|
||||
|
||||
audience, _ := c.Locals(apiAudienceKey).(string)
|
||||
if claim.UserId <= 0 {
|
||||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid user ID")
|
||||
}
|
||||
if err := validateAPIAudience(claim.Role, audience); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
refreshToken := c.Get("Refresh-Token")
|
||||
if refreshToken == "" {
|
||||
|
||||
|
|
@ -548,6 +556,19 @@ func (a *App) WebsocketAuthMiddleware(c *fiber.Ctx) error {
|
|||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid token")
|
||||
}
|
||||
|
||||
audience, _ := c.Locals(apiAudienceKey).(string)
|
||||
if err := validateAPIAudience(claim.Role, audience); err != nil {
|
||||
return err
|
||||
}
|
||||
if claim.Role.IsCustomerLearnerRole() {
|
||||
status, err := a.userSvc.GetAuthStatus(c.Context(), claim.UserId)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusUnauthorized, "Unable to validate customer account")
|
||||
}
|
||||
if err := domain.ValidateUserCanAuthenticate(status); err != nil {
|
||||
return fiber.NewError(fiber.StatusForbidden, "Customer account is not active")
|
||||
}
|
||||
}
|
||||
userID := claim.UserId
|
||||
if userID == 0 {
|
||||
a.mongoLoggerSvc.Info("Invalid user ID in token claims",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/domain"
|
||||
"Rezina-Backend/internal/web_server/handlers"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
fiberSwagger "github.com/swaggo/fiber-swagger"
|
||||
|
|
@ -55,419 +51,20 @@ func (a *App) initAppRoutes() {
|
|||
)
|
||||
|
||||
a.fiber.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
"message": "Welcome to Rezina Backend API",
|
||||
"version": a.cfg.APP_VERSION,
|
||||
})
|
||||
return c.JSON(fiber.Map{"message": "Welcome to Rezina Backend API", "version": a.cfg.APP_VERSION})
|
||||
})
|
||||
|
||||
a.fiber.Get("/routes", func(c *fiber.Ctx) error {
|
||||
return c.JSON(a.fiber.Stack()) // prints all registered routes
|
||||
})
|
||||
|
||||
// Groups
|
||||
groupV1 := a.fiber.Group("/api/v1", a.resolveFileURLsMiddleware)
|
||||
|
||||
// Referrals remain available without a subscription so new learners can participate.
|
||||
groupV1.Post("/referrals/code", a.authMiddleware, h.CreateReferralCode)
|
||||
groupV1.Get("/referrals/code", a.authMiddleware, h.GetReferralCode)
|
||||
groupV1.Get("/referrals/me", a.authMiddleware, h.GetMyReferrals)
|
||||
groupV1.Post("/referrals/apply", a.authMiddleware, h.ApplyReferralCode)
|
||||
groupV1.Get("/referrals", a.authMiddleware, h.ListMyReferrals)
|
||||
groupV1.Get("/referrals/wallet", a.authMiddleware, h.GetReferralWallet)
|
||||
groupV1.Get("/admin/referrals/settings", a.authMiddleware, a.OnlyAdminAndAbove, h.GetReferralSettings)
|
||||
groupV1.Put("/admin/referrals/settings", a.authMiddleware, a.OnlyAdminAndAbove, h.UpdateReferralSettings)
|
||||
|
||||
// Serve static files (profile pictures, etc.)
|
||||
a.fiber.Static("/static", "./static")
|
||||
|
||||
// Swagger
|
||||
a.fiber.Get("/swagger/admin/doc.json", audienceSpecification("admin"))
|
||||
a.fiber.Get("/swagger/client/doc.json", audienceSpecification("client"))
|
||||
a.fiber.Get("/swagger/admin/*", fiberSwagger.FiberWrapHandler(fiberSwagger.URL("/swagger/admin/doc.json")))
|
||||
a.fiber.Get("/swagger/client/*", fiberSwagger.FiberWrapHandler(fiberSwagger.URL("/swagger/client/doc.json")))
|
||||
a.fiber.Get("/swagger/*", fiberSwagger.FiberWrapHandler())
|
||||
|
||||
groupV1.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{
|
||||
"message": "Welcome to Rezina Backend API v1",
|
||||
"version": "1.0.1",
|
||||
})
|
||||
api := a.fiber.Group("/api/v1", a.resolveFileURLsMiddleware)
|
||||
api.Get("/", func(c *fiber.Ctx) error {
|
||||
return c.JSON(fiber.Map{"admin_api": "/api/v1/admin", "client_api": "/api/v1"})
|
||||
})
|
||||
|
||||
// Learning content uses the exam-prep catalog hierarchy exclusively:
|
||||
// catalog course -> unit -> module -> lesson.
|
||||
groupV1.Post("/exam-prep/catalog-courses", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.create"), h.CreateExamPrepCatalogCourse)
|
||||
groupV1.Get("/exam-prep/catalog-courses", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.list"), h.ListExamPrepCatalogCourses)
|
||||
groupV1.Put("/exam-prep/catalog-courses/reorder", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.reorder"), h.ReorderExamPrepCatalogCourses)
|
||||
groupV1.Get("/exam-prep/catalog-courses/:id", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.get"), h.GetExamPrepCatalogCourseByID)
|
||||
groupV1.Put("/exam-prep/catalog-courses/:id", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.update"), h.UpdateExamPrepCatalogCourse)
|
||||
groupV1.Delete("/exam-prep/catalog-courses/:id", a.authMiddleware, a.RequirePermission("exam_prep.catalog_courses.delete"), h.DeleteExamPrepCatalogCourse)
|
||||
groupV1.Post("/exam-prep/catalog-courses/:catalogCourseId/units", a.authMiddleware, a.RequirePermission("exam_prep.units.create"), h.CreateExamPrepUnit)
|
||||
groupV1.Get("/exam-prep/catalog-courses/:catalogCourseId/units", a.authMiddleware, a.RequirePermission("exam_prep.units.list"), h.ListExamPrepUnitsByCatalogCourse)
|
||||
groupV1.Put("/exam-prep/catalog-courses/:catalogCourseId/units/reorder", a.authMiddleware, a.RequirePermission("exam_prep.units.reorder"), h.ReorderExamPrepUnitsInCatalogCourse)
|
||||
groupV1.Get("/exam-prep/units/:id", a.authMiddleware, a.RequirePermission("exam_prep.units.get"), h.GetExamPrepUnitByID)
|
||||
groupV1.Put("/exam-prep/units/:id", a.authMiddleware, a.RequirePermission("exam_prep.units.update"), h.UpdateExamPrepUnit)
|
||||
groupV1.Delete("/exam-prep/units/:id", a.authMiddleware, a.RequirePermission("exam_prep.units.delete"), h.DeleteExamPrepUnit)
|
||||
groupV1.Post("/exam-prep/units/:unitId/modules", a.authMiddleware, a.RequirePermission("exam_prep.modules.create"), h.CreateExamPrepModule)
|
||||
groupV1.Get("/exam-prep/units/:unitId/modules", a.authMiddleware, a.RequirePermission("exam_prep.modules.list"), h.ListExamPrepModulesByUnit)
|
||||
groupV1.Put("/exam-prep/units/:unitId/modules/reorder", a.authMiddleware, a.RequirePermission("exam_prep.modules.reorder"), h.ReorderExamPrepModulesInUnit)
|
||||
groupV1.Get("/exam-prep/modules/:id", a.authMiddleware, a.RequirePermission("exam_prep.modules.get"), h.GetExamPrepModuleByID)
|
||||
groupV1.Put("/exam-prep/modules/:id", a.authMiddleware, a.RequirePermission("exam_prep.modules.update"), h.UpdateExamPrepModule)
|
||||
groupV1.Delete("/exam-prep/modules/:id", a.authMiddleware, a.RequirePermission("exam_prep.modules.delete"), h.DeleteExamPrepModule)
|
||||
groupV1.Post("/exam-prep/modules/:moduleId/lessons", a.authMiddleware, a.RequirePermission("exam_prep.lessons.create"), a.RequireExamPrepSubscription(), h.CreateExamPrepLesson)
|
||||
groupV1.Get("/exam-prep/modules/:moduleId/lessons", a.authMiddleware, a.RequirePermission("exam_prep.lessons.list_by_module"), a.RequireExamPrepSubscription(), h.ListExamPrepLessonsByUnitModule)
|
||||
groupV1.Put("/exam-prep/modules/:moduleId/lessons/reorder", a.authMiddleware, a.RequirePermission("exam_prep.lessons.reorder"), a.RequireExamPrepSubscription(), h.ReorderExamPrepLessonsInUnitModule)
|
||||
groupV1.Get("/exam-prep/lessons/:id", a.authMiddleware, a.RequirePermission("exam_prep.lessons.get"), a.RequireExamPrepSubscription(), h.GetExamPrepLessonByID)
|
||||
groupV1.Put("/exam-prep/lessons/:id", a.authMiddleware, a.RequirePermission("exam_prep.lessons.update"), a.RequireExamPrepSubscription(), h.UpdateExamPrepLesson)
|
||||
groupV1.Delete("/exam-prep/lessons/:id", a.authMiddleware, a.RequirePermission("exam_prep.lessons.delete"), a.RequireExamPrepSubscription(), h.DeleteExamPrepLesson)
|
||||
groupV1.Get("/exam-prep/assessments", a.authMiddleware, a.RequirePermission("question_sets.list"), a.RequireExamPrepSubscription(), h.ListExamPrepAssessments)
|
||||
groupV1.Post("/exam-prep/assessments", a.authMiddleware, a.RequirePermission("question_sets.update"), a.RequireExamPrepSubscription(), h.LinkExamPrepAssessment)
|
||||
groupV1.Delete("/exam-prep/assessments/:questionSetId/parents/:parentKind/:parentId", a.authMiddleware, a.RequirePermission("question_sets.update"), a.RequireExamPrepSubscription(), h.UnlinkExamPrepAssessment)
|
||||
groupV1.Post("/exam-prep/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.create"), a.RequireExamPrepSubscription(), h.CreateExamPrepPracticeFromInput)
|
||||
groupV1.Get("/exam-prep/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.list"), a.RequireExamPrepSubscription(), h.ListAllExamPrepPractices)
|
||||
groupV1.Get("/exam-prep/catalog-courses/:catalogCourseId/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.list_by_catalog_course"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByCatalogCourse)
|
||||
groupV1.Post("/exam-prep/catalog-courses/:catalogCourseId/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.create"), a.RequireExamPrepSubscription(), h.CreateExamPrepPracticeForCatalogCourse)
|
||||
groupV1.Get("/exam-prep/units/:unitId/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.list_by_unit"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByUnit)
|
||||
groupV1.Post("/exam-prep/units/:unitId/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.create"), a.RequireExamPrepSubscription(), h.CreateExamPrepPracticeForUnit)
|
||||
groupV1.Get("/exam-prep/lessons/:lessonId/practices", a.authMiddleware, a.RequirePermission("exam_prep.practices.list_by_lesson"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByLesson)
|
||||
groupV1.Get("/exam-prep/practices/:id", a.authMiddleware, a.RequirePermission("exam_prep.practices.get"), a.RequireExamPrepSubscription(), h.GetExamPrepPracticeByID)
|
||||
groupV1.Get("/exam-prep/practices/:id/full", a.authMiddleware, a.RequirePermission("exam_prep.practices.get"), a.RequireExamPrepSubscription(), h.GetExamPrepPracticeFull)
|
||||
groupV1.Put("/exam-prep/practices/:id", a.authMiddleware, a.RequirePermission("exam_prep.practices.update"), a.RequireExamPrepSubscription(), h.UpdateExamPrepPractice)
|
||||
groupV1.Put("/exam-prep/practices/:id/full", a.authMiddleware, a.RequirePermission("exam_prep.practices.update"), a.RequireExamPrepSubscription(), h.UpdateExamPrepPracticeFull)
|
||||
groupV1.Put("/exam-prep/practices/:id/parents", a.authMiddleware, a.RequirePermission("exam_prep.practices.update"), a.RequireExamPrepSubscription(), h.UpdateExamPrepPracticeParents)
|
||||
groupV1.Delete("/exam-prep/practices/:id/parents/:parentKind/:parentId", a.authMiddleware, a.RequirePermission("exam_prep.practices.update"), a.RequireExamPrepSubscription(), h.UnlinkExamPrepPracticeParent)
|
||||
groupV1.Delete("/exam-prep/practices/:id", a.authMiddleware, a.RequirePermission("exam_prep.practices.delete"), a.RequireExamPrepSubscription(), h.DeleteExamPrepPractice)
|
||||
groupV1.Post("/exam-prep/progress/practices/:id/complete", a.authMiddleware, a.RequirePermission("progress.complete"), a.RequireExamPrepSubscription(), h.CompletePractice)
|
||||
groupV1.Post("/exam-prep/videos/engagement/heartbeat", a.authMiddleware, a.RequirePermission("videos.track_engagement"), a.RequireExamPrepSubscription(), h.RecordVideoEngagementHeartbeat)
|
||||
groupV1.Get("/exam-prep/progress-summary", a.authMiddleware, a.RequirePermission("lms.get_my_progress"), h.GetMyLMSProgressSummary)
|
||||
groupV1.Get("/exam-prep/practices/:practiceId/questions", a.authMiddleware, a.RequirePermission("question_set_items.list"), a.RequireExamPrepSubscription(), h.GetQuestionsByPractice)
|
||||
|
||||
// LMS personas (catalog referenced by persona_id on practices)
|
||||
groupV1.Get("/personas", a.authMiddleware, a.RequirePermission("personas.list"), h.ListPersonas)
|
||||
groupV1.Post("/personas", a.authMiddleware, a.RequirePermission("personas.create"), h.CreatePersona)
|
||||
groupV1.Get("/personas/:id", a.authMiddleware, a.RequirePermission("personas.get"), h.GetPersona)
|
||||
groupV1.Put("/personas/:id", a.authMiddleware, a.RequirePermission("personas.update"), h.UpdatePersona)
|
||||
groupV1.Delete("/personas/:id", a.authMiddleware, a.RequirePermission("personas.delete"), h.DeletePersona)
|
||||
|
||||
// File storage (MinIO)
|
||||
groupV1.Get("/files/url", a.authMiddleware, h.GetFileURL)
|
||||
groupV1.Post("/files/refresh-url", a.authMiddleware, h.RefreshFileURL)
|
||||
groupV1.Post("/files/presign-upload", a.authMiddleware, h.CreatePresignedUpload)
|
||||
groupV1.Post("/files/complete-upload", a.authMiddleware, h.CompletePresignedUpload)
|
||||
groupV1.Post("/files/upload", a.authMiddleware, h.UploadMedia)
|
||||
groupV1.Post("/files/audio", a.authMiddleware, h.UploadAudio)
|
||||
groupV1.Post("/questions/audio-answer", a.authMiddleware, h.SubmitAudioAnswer)
|
||||
|
||||
// Assessment questions (public list) + authenticated submit
|
||||
|
||||
// Questions
|
||||
groupV1.Post("/questions", a.authMiddleware, a.RequirePermission("questions.create"), h.CreateQuestion)
|
||||
groupV1.Get("/questions", a.authMiddleware, a.RequirePermission("questions.list"), h.ListQuestions)
|
||||
groupV1.Get("/questions/search", a.authMiddleware, a.RequirePermission("questions.search"), h.SearchQuestions)
|
||||
groupV1.Get("/questions/component-catalog", a.authMiddleware, a.RequirePermission("questions.list"), h.GetQuestionTypeComponentCatalog)
|
||||
groupV1.Post("/questions/validate-question-type-definition", a.authMiddleware, a.RequirePermission("questions.create"), h.ValidateQuestionTypeDefinition)
|
||||
groupV1.Post("/questions/type-definition-groups", a.authMiddleware, a.RequirePermission("questions.create"), h.CreateQuestionTypeDefinitionGroup)
|
||||
groupV1.Get("/questions/type-definition-groups", a.authMiddleware, a.RequirePermission("questions.list"), h.ListQuestionTypeDefinitionGroups)
|
||||
groupV1.Get("/questions/type-definition-groups/:id", a.authMiddleware, a.RequirePermission("questions.get"), h.GetQuestionTypeDefinitionGroupByID)
|
||||
groupV1.Put("/questions/type-definition-groups/:id", a.authMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestionTypeDefinitionGroup)
|
||||
groupV1.Delete("/questions/type-definition-groups/:id", a.authMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestionTypeDefinitionGroup)
|
||||
groupV1.Post("/questions/type-definitions", a.authMiddleware, a.RequirePermission("questions.create"), h.CreateQuestionTypeDefinition)
|
||||
groupV1.Get("/questions/type-definitions", a.authMiddleware, a.RequirePermission("questions.list"), h.ListQuestionTypeDefinitions)
|
||||
groupV1.Get("/questions/type-definitions/:id", a.authMiddleware, a.RequirePermission("questions.get"), h.GetQuestionTypeDefinitionByID)
|
||||
groupV1.Get("/questions/type-definitions/:id/practices", a.authMiddleware, a.RequirePermission("practices.list"), h.ListPracticesByQuestionTypeDefinition)
|
||||
groupV1.Put("/questions/type-definitions/:id", a.authMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestionTypeDefinition)
|
||||
groupV1.Delete("/questions/type-definitions/:id", a.authMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestionTypeDefinition)
|
||||
groupV1.Get("/questions/:id", a.authMiddleware, a.RequirePermission("questions.get"), h.GetQuestionByID)
|
||||
groupV1.Put("/questions/:id", a.authMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestion)
|
||||
groupV1.Delete("/questions/:id", a.authMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestion)
|
||||
|
||||
// FAQs
|
||||
groupV1.Get("/faqs", h.ListPublicFAQs)
|
||||
groupV1.Get("/faqs/:id", h.GetPublicFAQByID)
|
||||
groupV1.Get("/admin/faqs", a.authMiddleware, a.RequirePermission("faqs.list"), h.ListFAQsAdmin)
|
||||
groupV1.Get("/admin/faqs/:id", a.authMiddleware, a.RequirePermission("faqs.get"), h.GetFAQByIDAdmin)
|
||||
groupV1.Post("/admin/faqs", a.authMiddleware, a.RequirePermission("faqs.create"), h.CreateFAQ)
|
||||
groupV1.Put("/admin/faqs/:id", a.authMiddleware, a.RequirePermission("faqs.update"), h.UpdateFAQ)
|
||||
groupV1.Delete("/admin/faqs/:id", a.authMiddleware, a.RequirePermission("faqs.delete"), h.DeleteFAQ)
|
||||
|
||||
// Mobile app versions (Play Store / App Store)
|
||||
groupV1.Get("/app/version/check", h.CheckMobileAppVersion)
|
||||
groupV1.Get("/admin/app-versions", a.authMiddleware, a.RequirePermission("app_versions.list"), h.ListMobileAppVersionsAdmin)
|
||||
groupV1.Get("/admin/app-versions/:id", a.authMiddleware, a.RequirePermission("app_versions.get"), h.GetMobileAppVersionByIDAdmin)
|
||||
groupV1.Post("/admin/app-versions", a.authMiddleware, a.RequirePermission("app_versions.create"), h.CreateMobileAppVersion)
|
||||
groupV1.Put("/admin/app-versions/:id", a.authMiddleware, a.RequirePermission("app_versions.update"), h.UpdateMobileAppVersion)
|
||||
groupV1.Delete("/admin/app-versions/:id", a.authMiddleware, a.RequirePermission("app_versions.delete"), h.DeleteMobileAppVersion)
|
||||
|
||||
// Email templates
|
||||
groupV1.Get("/admin/email-templates", a.authMiddleware, a.RequirePermission("email_templates.list"), h.ListEmailTemplatesAdmin)
|
||||
groupV1.Get("/admin/email-templates/slug/:slug", a.authMiddleware, a.RequirePermission("email_templates.get"), h.GetEmailTemplateBySlugAdmin)
|
||||
groupV1.Post("/admin/email-templates/slug/:slug/preview", a.authMiddleware, a.RequirePermission("email_templates.preview"), h.PreviewEmailTemplateBySlug)
|
||||
groupV1.Get("/admin/email-templates/:id", a.authMiddleware, a.RequirePermission("email_templates.get"), h.GetEmailTemplateByIDAdmin)
|
||||
groupV1.Post("/admin/email-templates/:id/preview", a.authMiddleware, a.RequirePermission("email_templates.preview"), h.PreviewEmailTemplateByID)
|
||||
groupV1.Post("/admin/email-templates", a.authMiddleware, a.RequirePermission("email_templates.create"), h.CreateEmailTemplate)
|
||||
groupV1.Put("/admin/email-templates/:id", a.authMiddleware, a.RequirePermission("email_templates.update"), h.UpdateEmailTemplate)
|
||||
groupV1.Delete("/admin/email-templates/:id", a.authMiddleware, a.RequirePermission("email_templates.delete"), h.DeleteEmailTemplate)
|
||||
|
||||
// Field options (configurable dropdown values: profile fields, countries, etc.)
|
||||
groupV1.Get("/field-options", h.ListPublicFieldOptions)
|
||||
groupV1.Get("/field-options/fields", h.ListFieldKeys)
|
||||
groupV1.Get("/admin/field-options", a.authMiddleware, a.RequirePermission("field_options.list"), h.ListFieldOptionsAdmin)
|
||||
groupV1.Get("/admin/field-options/:id", a.authMiddleware, a.RequirePermission("field_options.get"), h.GetFieldOptionByIDAdmin)
|
||||
groupV1.Post("/admin/field-options", a.authMiddleware, a.RequirePermission("field_options.create"), h.CreateFieldOption)
|
||||
groupV1.Put("/admin/field-options/:id", a.authMiddleware, a.RequirePermission("field_options.update"), h.UpdateFieldOption)
|
||||
groupV1.Delete("/admin/field-options/:id", a.authMiddleware, a.RequirePermission("field_options.delete"), h.DeleteFieldOption)
|
||||
|
||||
// Admin payments (register before /admin/:id<int> so "payments" is not captured as an admin id)
|
||||
groupV1.Get("/admin/payments", a.authMiddleware, a.RequirePermission("payments.list_all"), h.ListAdminPayments)
|
||||
groupV1.Get("/admin/payments/export", a.authMiddleware, a.RequirePermission("payments.export"), h.ExportAdminPaymentsCSV)
|
||||
groupV1.Get("/admin/payments/:id", a.authMiddleware, a.RequirePermission("payments.list_all"), h.GetAdminPayment)
|
||||
|
||||
// Question Sets
|
||||
groupV1.Post("/question-sets", a.authMiddleware, a.RequirePermission("question_sets.create"), h.CreateQuestionSet)
|
||||
groupV1.Get("/question-sets", a.authMiddleware, a.RequirePermission("question_sets.list"), h.GetQuestionSetsByType)
|
||||
groupV1.Get("/question-sets/by-owner", a.authMiddleware, a.RequirePermission("question_sets.list_by_owner"), h.GetQuestionSetsByOwner)
|
||||
groupV1.Get("/question-sets/:id", a.authMiddleware, a.RequirePermission("question_sets.get"), h.GetQuestionSetByID)
|
||||
groupV1.Put("/question-sets/:id", a.authMiddleware, a.RequirePermission("question_sets.update"), h.UpdateQuestionSet)
|
||||
groupV1.Delete("/question-sets/:id", a.authMiddleware, a.RequirePermission("question_sets.delete"), h.DeleteQuestionSet)
|
||||
|
||||
// Question Set Items
|
||||
groupV1.Post("/question-sets/:setId/questions", a.authMiddleware, a.RequirePermission("question_set_items.add"), h.AddQuestionToSet)
|
||||
groupV1.Get("/question-sets/:setId/question-types", a.authMiddleware, a.RequirePermission("question_set_items.list"), h.GetQuestionTypesInSet)
|
||||
groupV1.Get("/question-sets/:setId/questions", a.authMiddleware, a.RequirePermission("question_set_items.list"), h.GetQuestionsInSet)
|
||||
groupV1.Delete("/question-sets/:setId/questions/:questionId", a.authMiddleware, a.RequirePermission("question_set_items.remove"), h.RemoveQuestionFromSet)
|
||||
groupV1.Put("/question-sets/:setId/questions/:questionId/order", a.authMiddleware, a.RequirePermission("question_set_items.update_order"), h.UpdateQuestionOrderInSet)
|
||||
|
||||
// Question Set Personas
|
||||
groupV1.Get("/question-sets/:setId/personas", a.authMiddleware, a.RequirePermission("question_set_personas.list"), h.GetUserPersonasByQuestionSet)
|
||||
groupV1.Post("/question-sets/:setId/personas", a.authMiddleware, a.RequirePermission("question_set_personas.add"), h.AddUserPersonaToQuestionSet)
|
||||
groupV1.Delete("/question-sets/:setId/personas/:userId", a.authMiddleware, a.RequirePermission("question_set_personas.remove"), h.RemoveUserPersonaFromQuestionSet)
|
||||
|
||||
// Subscription Plans
|
||||
groupV1.Post("/subscription-plans", a.authMiddleware, a.RequirePermission("subscription_plans.create"), h.CreateSubscriptionPlan)
|
||||
groupV1.Get("/subscription-plans", h.ListSubscriptionPlans)
|
||||
groupV1.Get("/subscription-plans/:id", h.GetSubscriptionPlan)
|
||||
groupV1.Put("/subscription-plans/:id", a.authMiddleware, a.RequirePermission("subscription_plans.update"), h.UpdateSubscriptionPlan)
|
||||
groupV1.Delete("/subscription-plans/:id", a.authMiddleware, a.RequirePermission("subscription_plans.delete"), h.DeleteSubscriptionPlan)
|
||||
|
||||
// User Subscriptions
|
||||
groupV1.Post("/subscriptions", a.authMiddleware, a.RequirePermission("subscriptions.create"), h.Subscribe)
|
||||
groupV1.Post("/subscriptions/checkout", a.authMiddleware, a.RequirePermission("subscriptions.checkout"), h.SubscribeWithPayment)
|
||||
groupV1.Post("/subscriptions/request-checkout-link", a.authMiddleware, a.RequirePermission("subscriptions.request_checkout_link"), h.RequestSubscriptionCheckoutLink)
|
||||
groupV1.Get("/subscriptions/me", a.authMiddleware, a.RequirePermission("subscriptions.get_mine"), h.GetMySubscription)
|
||||
groupV1.Get("/subscriptions/history", a.authMiddleware, a.RequirePermission("subscriptions.history"), h.GetMySubscriptionHistory)
|
||||
groupV1.Get("/subscriptions/status", a.authMiddleware, a.RequirePermission("subscriptions.status"), h.CheckSubscriptionStatus)
|
||||
groupV1.Post("/subscriptions/:id/cancel", a.authMiddleware, a.RequirePermission("subscriptions.cancel"), h.CancelSubscription)
|
||||
groupV1.Put("/subscriptions/:id/auto-renew", a.authMiddleware, a.RequirePermission("subscriptions.set_auto_renew"), h.SetAutoRenew)
|
||||
|
||||
// Payments (Chapa)
|
||||
groupV1.Post("/payments/subscribe", a.authMiddleware, a.RequirePermission("payments.initiate"), h.InitiateSubscriptionPayment)
|
||||
groupV1.Get("/payments/verify/:session_id", a.authMiddleware, a.RequirePermission("payments.verify"), h.VerifyPayment)
|
||||
groupV1.Get("/payments", a.authMiddleware, a.RequirePermission("payments.list_mine"), h.GetMyPayments)
|
||||
groupV1.Get("/payments/methods", h.GetChapaPaymentMethods)
|
||||
groupV1.Get("/payments/:id", a.authMiddleware, a.RequirePermission("payments.get"), h.GetPaymentByID)
|
||||
groupV1.Post("/payments/:id/cancel", a.authMiddleware, a.RequirePermission("payments.cancel"), h.CancelPayment)
|
||||
groupV1.Post("/payments/webhook", h.HandleChapaWebhook)
|
||||
groupV1.Get("/payments/arifpay/success", h.HandleArifpaySuccessPage)
|
||||
groupV1.Get("/payments/chapa/success", h.HandleChapaSuccessPage)
|
||||
groupV1.Get("/payments/chapa/callback", h.HandleChapaCallback)
|
||||
a.initAdminRoutes(api.Group("/admin", apiAudience("admin")), h)
|
||||
a.initClientRoutes(api, h)
|
||||
a.initIntegrationRoutes(api, h)
|
||||
a.fiber.Get("/payment/success", h.HandleChapaSuccessPage)
|
||||
|
||||
// Chapa Direct Charge (USSD / OTP — separate from hosted checkout and ArifPay direct)
|
||||
groupV1.Post("/payments/chapa/direct", a.authMiddleware, a.RequirePermission("payments.direct_initiate"), h.InitiateChapaDirectPayment)
|
||||
groupV1.Post("/payments/chapa/direct/authorize", a.authMiddleware, a.RequirePermission("payments.direct_verify_otp"), h.AuthorizeChapaDirectPayment)
|
||||
groupV1.Get("/payments/chapa/direct/methods", h.GetChapaDirectPaymentMethods)
|
||||
|
||||
// Direct Payments (ArifPay)
|
||||
groupV1.Post("/payments/direct", a.authMiddleware, a.RequirePermission("payments.direct_initiate"), h.InitiateDirectPayment)
|
||||
groupV1.Post("/payments/direct/verify-otp", a.authMiddleware, a.RequirePermission("payments.direct_verify_otp"), h.VerifyDirectPaymentOTP)
|
||||
groupV1.Get("/payments/direct/methods", h.GetDirectPaymentMethods)
|
||||
|
||||
// Auth Routes (public)
|
||||
groupV1.Post("/auth/google/android", h.GoogleAndroidLogin)
|
||||
groupV1.Get("/auth/google/login", h.GoogleLogin)
|
||||
groupV1.Get("/auth/google/callback", h.GoogleCallback)
|
||||
groupV1.Post("/auth/apple", h.AppleLogin)
|
||||
groupV1.Post("/auth/customer-login", h.LoginUser)
|
||||
groupV1.Post("/auth/admin-login", h.LoginAdmin)
|
||||
groupV1.Post("/auth/super-login", h.LoginSuper)
|
||||
groupV1.Post("/auth/refresh", h.RefreshToken)
|
||||
groupV1.Post("/user/:id/profile-picture", a.authMiddleware, a.RequirePermission("users.upload_profile_picture"), h.UploadProfilePicture)
|
||||
groupV1.Post("/auth/logout", a.authMiddleware, a.RequirePermission("auth.logout"), h.LogOutuser)
|
||||
groupV1.Get("/auth/test", a.authMiddleware, func(c *fiber.Ctx) error {
|
||||
userID, ok := c.Locals("user_id").(int64)
|
||||
if !ok {
|
||||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid user ID")
|
||||
}
|
||||
role, ok := c.Locals("role").(domain.Role)
|
||||
if !ok {
|
||||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid role")
|
||||
}
|
||||
refreshToken, ok := c.Locals("refresh_token").(string)
|
||||
if !ok {
|
||||
return fiber.NewError(fiber.StatusUnauthorized, "Invalid refresh token")
|
||||
}
|
||||
companyID, err := strconv.ParseInt(c.Get("company_id"), 10, 64)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "Invalid company_id")
|
||||
}
|
||||
|
||||
a.logger.Info("User ID: " + strconv.FormatInt(userID, 10))
|
||||
fmt.Printf("User ID: %d\n", userID)
|
||||
a.logger.Info("Role: " + string(role))
|
||||
a.logger.Info("Refresh Token: " + refreshToken)
|
||||
a.logger.Info("Company ID: " + strconv.FormatInt(companyID, 10))
|
||||
return c.SendString("Test endpoint")
|
||||
})
|
||||
|
||||
// User Routes
|
||||
groupV1.Get("/user/:user_id/is-profile-completed", a.authMiddleware, a.RequirePermission("users.profile_completed"), h.CheckProfileCompleted)
|
||||
groupV1.Get("/users", a.authMiddleware, a.RequirePermission("users.list"), h.GetAllUsers)
|
||||
groupV1.Get("/users/export", a.authMiddleware, a.RequirePermission("users.export"), h.ExportUsersCSV)
|
||||
groupV1.Get("/admin/users/deletion-requests", a.authMiddleware, a.RequirePermission("users.deletion_requests.list"), h.ListAccountDeletionRequests)
|
||||
groupV1.Get("/admin/subscriptions/export", a.authMiddleware, a.RequirePermission("subscriptions.export"), h.ExportUserSubscriptionsCSV)
|
||||
groupV1.Post("/admin/subscriptions/:id/cancel", a.authMiddleware, a.RequirePermission("subscriptions.admin_cancel"), h.AdminCancelUserSubscription)
|
||||
groupV1.Get("/admin/users/:user_id/recent-activity", a.authMiddleware, a.RequirePermission("progress.get_any_user"), h.AdminGetUserRecentActivity)
|
||||
groupV1.Get("/admin/users/:user_id/learning-activity", a.authMiddleware, a.RequirePermission("progress.get_any_user"), h.AdminGetUserLearningActivityDetails)
|
||||
groupV1.Get("/admin/users/:user_id/subscriptions", a.authMiddleware, a.RequirePermission("subscriptions.get_by_user"), h.AdminGetUserSubscriptions)
|
||||
groupV1.Post("/admin/users/:user_id/subscriptions/extend", a.authMiddleware, a.RequirePermission("subscriptions.admin_extend"), h.AdminExtendOrGrantUserSubscription)
|
||||
groupV1.Get("/users/summary", a.authMiddleware, a.RequirePermission("users.summary"), h.GetUserSummary)
|
||||
groupV1.Put("/user", a.authMiddleware, a.RequirePermission("users.update_self"), h.UpdateUser)
|
||||
groupV1.Patch("/user/status", a.authMiddleware, a.RequirePermission("users.update_status"), h.UpdateUserStatus)
|
||||
groupV1.Put("/user/knowledge-level", a.authMiddleware, a.RequirePermission("users.update_self"), h.UpdateUserKnowledgeLevel)
|
||||
groupV1.Get("/user/:user_name/is-pending", h.CheckUserPending)
|
||||
groupV1.Post("/user/resetPassword", h.ResetPassword)
|
||||
groupV1.Post("/user/sendResetCode", h.SendResetCode)
|
||||
groupV1.Post("/user/verify-otp", h.VerifyOtp)
|
||||
groupV1.Post("/user/resend-otp", h.ResendOtp)
|
||||
groupV1.Post("/user/register", h.RegisterUser)
|
||||
groupV1.Post("/user/sendRegisterCode", h.SendRegisterCode)
|
||||
groupV1.Post("/user/checkPhoneEmailExist", h.CheckPhoneEmailExist)
|
||||
groupV1.Get("/user/admin-profile", a.authMiddleware, a.RequirePermission("users.admin_profile"), h.AdminProfile)
|
||||
groupV1.Get("/user/user-profile", a.authMiddleware, a.RequirePermission("users.user_profile"), h.GetUserProfile)
|
||||
groupV1.Delete("/user/me", a.authMiddleware, a.RequirePermission("users.delete_self"), h.DeleteMyUserAccount)
|
||||
groupV1.Post("/user/me/deletion/cancel", a.authMiddleware, a.RequirePermission("users.cancel_delete_self"), h.CancelMyUserAccountDeletion)
|
||||
groupV1.Post("/internal/users/purge-due-deletions", a.authMiddleware, a.RequirePermission("users.purge_due_deletions"), h.PurgeDueDeletedUsers)
|
||||
groupV1.Get("/user/single/:id", a.authMiddleware, a.RequirePermission("users.get"), h.GetUserByID)
|
||||
groupV1.Delete("/user/delete/:id", a.authMiddleware, a.RequirePermission("users.delete"), h.DeleteUser)
|
||||
groupV1.Post("/user/search", a.authMiddleware, a.RequirePermission("users.search"), h.SearchUserByNameOrPhone)
|
||||
|
||||
// Admin management
|
||||
groupV1.Get("/admin", a.authMiddleware, a.RequirePermission("admins.list"), h.GetAllAdmins)
|
||||
groupV1.Get("/admin/:id<int>", a.authMiddleware, a.RequirePermission("admins.get"), h.GetAdminByID)
|
||||
groupV1.Post("/admin", a.authMiddleware, a.RequirePermission("admins.create"), h.CreateAdmin)
|
||||
groupV1.Put("/admin/:id<int>", a.authMiddleware, a.RequirePermission("admins.update"), h.UpdateAdmin)
|
||||
groupV1.Post("/admin/roles/:role/bulk-deactivate", a.authMiddleware, h.BulkDeactivateAccountsByRole)
|
||||
groupV1.Post("/admin/roles/:role/bulk-reactivate", a.authMiddleware, h.BulkReactivateAccountsByRole)
|
||||
|
||||
// Logs
|
||||
groupV1.Get("/logs", a.authMiddleware, a.RequirePermission("logs.list"), handlers.GetLogsHandler(context.Background()))
|
||||
groupV1.Get("/activity-logs", a.authMiddleware, a.RequirePermission("activity_logs.list"), h.GetActivityLogs)
|
||||
groupV1.Get("/activity-logs/export", a.authMiddleware, a.RequirePermission("activity_logs.export"), h.ExportActivityLogsCSV)
|
||||
groupV1.Get("/activity-logs/:id", a.authMiddleware, a.RequirePermission("activity_logs.get"), h.GetActivityLogByID)
|
||||
|
||||
// Notifications
|
||||
groupV1.Post("/sendSMS", h.SendSingleAfroSMS)
|
||||
groupV1.Get("/ws/connect", a.WebsocketAuthMiddleware, h.ConnectSocket)
|
||||
groupV1.Get("/notifications", a.authMiddleware, a.RequirePermission("notifications.list_mine"), h.GetUserNotification)
|
||||
groupV1.Get("/notifications/all", a.authMiddleware, a.RequirePermission("notifications.list_all"), h.GetAllNotifications)
|
||||
groupV1.Patch("/notifications/:id/read", a.authMiddleware, a.RequirePermission("notifications.mark_read"), h.MarkNotificationAsRead)
|
||||
groupV1.Post("/notifications/mark-all-read", a.authMiddleware, a.RequirePermission("notifications.mark_all_read"), h.MarkAllNotificationsAsRead)
|
||||
groupV1.Patch("/notifications/:id/unread", a.authMiddleware, a.RequirePermission("notifications.mark_unread"), h.MarkNotificationAsUnread)
|
||||
groupV1.Post("/notifications/mark-all-unread", a.authMiddleware, a.RequirePermission("notifications.mark_all_unread"), h.MarkAllNotificationsAsUnread)
|
||||
groupV1.Delete("/notifications", a.authMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteUserNotifications)
|
||||
groupV1.Post("/notifications/delete-in-app", a.authMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotifications)
|
||||
groupV1.Get("/notifications/unread", a.authMiddleware, a.RequirePermission("notifications.count_unread"), h.CountUnreadNotifications)
|
||||
groupV1.Post("/notifications/create", a.authMiddleware, a.RequirePermission("notifications.create"), h.CreateAndSendNotification)
|
||||
groupV1.Post("/notifications/test-push", a.authMiddleware, a.RequirePermission("notifications.test_push"), h.SendTestPushNotification)
|
||||
|
||||
// Bulk Notifications
|
||||
groupV1.Post("/notifications/bulk-push", a.authMiddleware, a.RequirePermission("notifications.bulk_push"), h.SendBulkPushNotification)
|
||||
groupV1.Post("/notifications/bulk-sms", a.authMiddleware, a.RequirePermission("notifications.bulk_sms"), h.SendBulkSMS)
|
||||
groupV1.Post("/notifications/bulk-in-app", a.authMiddleware, a.RequirePermission("notifications.bulk_in_app"), h.SendBulkInAppNotification)
|
||||
groupV1.Post("/notifications/send-email", a.authMiddleware, a.RequirePermission("notifications.send_email"), h.SendSingleEmail)
|
||||
groupV1.Post("/notifications/bulk-email", a.authMiddleware, a.RequirePermission("notifications.bulk_email"), h.SendBulkEmail)
|
||||
|
||||
// Scheduled Notifications
|
||||
groupV1.Get("/notifications/scheduled", a.authMiddleware, a.RequirePermission("notifications_scheduled.list"), h.ListScheduledNotifications)
|
||||
groupV1.Get("/notifications/scheduled/:id", a.authMiddleware, a.RequirePermission("notifications_scheduled.get"), h.GetScheduledNotification)
|
||||
groupV1.Post("/notifications/scheduled/:id/cancel", a.authMiddleware, a.RequirePermission("notifications_scheduled.cancel"), h.CancelScheduledNotification)
|
||||
groupV1.Delete("/notifications/:id", a.authMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotification)
|
||||
groupV1.Get("/notifications/:id", a.authMiddleware, a.RequirePermission("notifications.list_mine"), h.GetNotificationByID)
|
||||
|
||||
// Issues
|
||||
groupV1.Post("/issues", a.authMiddleware, a.RequirePermission("issues.create"), h.CreateIssue)
|
||||
groupV1.Get("/issues/me", a.authMiddleware, a.RequirePermission("issues.list_mine"), h.GetMyIssues)
|
||||
groupV1.Get("/issues/user/:user_id", a.authMiddleware, a.RequirePermission("issues.list_by_user"), h.GetUserIssues)
|
||||
groupV1.Get("/issues", a.authMiddleware, a.RequirePermission("issues.list_all"), h.GetAllIssues)
|
||||
groupV1.Get("/issues/:id", a.authMiddleware, a.RequirePermission("issues.get"), h.GetIssueByID)
|
||||
groupV1.Patch("/issues/:id/status", a.authMiddleware, a.RequirePermission("issues.update_status"), h.UpdateIssueStatus)
|
||||
groupV1.Delete("/issues/:id", a.authMiddleware, a.RequirePermission("issues.delete"), h.DeleteIssue)
|
||||
|
||||
// Devices
|
||||
groupV1.Post("/devices/register", a.authMiddleware, a.RequirePermission("devices.register"), h.RegisterDeviceToken)
|
||||
groupV1.Post("/devices/unregister", a.authMiddleware, a.RequirePermission("devices.unregister"), h.UnregisterDeviceToken)
|
||||
|
||||
// Settings
|
||||
groupV1.Get("/settings", a.authMiddleware, a.RequirePermission("settings.list"), h.GetGlobalSettingList)
|
||||
groupV1.Get("/settings/:key", a.authMiddleware, a.RequirePermission("settings.get"), h.GetGlobalSettingByKey)
|
||||
groupV1.Put("/settings", a.authMiddleware, a.RequirePermission("settings.update"), h.UpdateGlobalSettingList)
|
||||
|
||||
// Analytics
|
||||
groupV1.Get("/analytics/dashboard", a.authMiddleware, a.RequirePermission("analytics.dashboard"), h.GetAnalyticsDashboard)
|
||||
|
||||
// Vimeo
|
||||
vimeoGroup := groupV1.Group("/vimeo")
|
||||
vimeoGroup.Get("/videos", a.authMiddleware, a.RequirePermission("vimeo.videos.list"), h.ListVimeoVideos)
|
||||
vimeoGroup.Get("/videos/:video_id", a.authMiddleware, a.RequirePermission("vimeo.videos.get"), h.GetVimeoVideo)
|
||||
vimeoGroup.Get("/videos/:video_id/embed", a.authMiddleware, a.RequirePermission("vimeo.videos.embed"), h.GetEmbedCode)
|
||||
vimeoGroup.Get("/videos/:video_id/status", a.authMiddleware, a.RequirePermission("vimeo.videos.status"), h.GetTranscodeStatus)
|
||||
vimeoGroup.Delete("/videos/:video_id", a.authMiddleware, a.RequirePermission("vimeo.videos.delete"), h.DeleteVimeoVideo)
|
||||
vimeoGroup.Post("/uploads/pull", a.authMiddleware, a.RequirePermission("vimeo.uploads.pull"), h.CreatePullUpload)
|
||||
vimeoGroup.Post("/uploads/tus", a.authMiddleware, a.RequirePermission("vimeo.uploads.tus"), h.CreateTusUpload)
|
||||
vimeoGroup.Get("/oembed", h.GetOEmbed)
|
||||
vimeoGroup.Get("/sample", h.GetSampleVideo)
|
||||
|
||||
// Team Management
|
||||
teamGroup := groupV1.Group("/team")
|
||||
teamGroup.Post("/login", h.TeamMemberLogin)
|
||||
teamGroup.Post("/refresh", h.TeamMemberRefresh)
|
||||
teamGroup.Post("/sendResetCode", h.SendTeamPasswordReset)
|
||||
teamGroup.Get("/verifyResetCode", h.VerifyTeamPasswordReset)
|
||||
teamGroup.Post("/resetPassword", h.ResetTeamPassword)
|
||||
teamGroup.Get("/invitations/verify", h.VerifyTeamInvitation)
|
||||
teamGroup.Post("/invitations/accept", h.AcceptTeamInvitation)
|
||||
teamGroup.Get("/me", a.authMiddleware, a.RequirePermission("team.profile.get_mine"), h.GetMyTeamProfile)
|
||||
teamGroup.Put("/me", a.authMiddleware, a.RequirePermission("team.profile.update_mine"), h.UpdateMyTeamProfile)
|
||||
teamGroup.Get("/stats", a.authMiddleware, a.RequirePermission("team.stats"), h.GetTeamMemberStats)
|
||||
teamGroup.Get("/members", a.authMiddleware, a.RequirePermission("team.members.list"), h.GetAllTeamMembers)
|
||||
teamGroup.Get("/members/export", a.authMiddleware, a.RequirePermission("team.members.export"), h.ExportTeamMembersCSV)
|
||||
teamGroup.Post("/members/invite", a.authMiddleware, a.RequirePermission("team.members.invite"), h.InviteTeamMember)
|
||||
teamGroup.Post("/members", a.authMiddleware, a.RequirePermission("team.members.create"), h.CreateTeamMember)
|
||||
teamGroup.Post("/members/:id/resend-invite", a.authMiddleware, a.RequirePermission("team.invitations.resend"), h.ResendTeamInvitation)
|
||||
teamGroup.Get("/members/:id", a.authMiddleware, a.RequirePermission("team.members.get"), h.GetTeamMember)
|
||||
teamGroup.Put("/members/:id", a.authMiddleware, a.RequirePermission("team.members.update"), h.UpdateTeamMember)
|
||||
teamGroup.Patch("/members/:id/status", a.authMiddleware, a.RequirePermission("team.members.update_status"), h.UpdateTeamMemberStatus)
|
||||
teamGroup.Delete("/members/:id", a.authMiddleware, a.RequirePermission("team.members.delete"), h.DeleteTeamMember)
|
||||
teamGroup.Post("/members/:id/change-password", a.authMiddleware, a.RequirePermission("team.members.change_password"), h.ChangeTeamMemberPassword)
|
||||
teamGroup.Get("/invitations", a.authMiddleware, a.RequirePermission("team.invitations.list"), h.ListTeamInvitations)
|
||||
teamGroup.Post("/invitations/:id/revoke", a.authMiddleware, a.RequirePermission("team.invitations.revoke"), h.RevokeTeamInvitation)
|
||||
|
||||
// Ratings
|
||||
groupV1.Post("/ratings", a.authMiddleware, a.RequirePermission("ratings.submit"), h.SubmitRating)
|
||||
groupV1.Get("/ratings", a.authMiddleware, a.RequirePermission("ratings.list_by_target"), h.GetRatingsByTarget)
|
||||
groupV1.Get("/ratings/summary", a.authMiddleware, a.RequirePermission("ratings.summary"), h.GetRatingSummary)
|
||||
groupV1.Get("/ratings/me", a.authMiddleware, a.RequirePermission("ratings.get_mine"), h.GetMyRating)
|
||||
groupV1.Get("/ratings/me/all", a.authMiddleware, a.RequirePermission("ratings.list_mine"), h.GetMyRatings)
|
||||
groupV1.Delete("/ratings/:id", a.authMiddleware, a.RequirePermission("ratings.delete"), h.DeleteRating)
|
||||
|
||||
// RBAC Management
|
||||
rbacGroup := groupV1.Group("/rbac", a.authMiddleware)
|
||||
rbacGroup.Get("/roles", a.RequirePermission("rbac.roles.list"), h.ListRoles)
|
||||
rbacGroup.Get("/roles/:id", a.RequirePermission("rbac.roles.get"), h.GetRoleByID)
|
||||
rbacGroup.Post("/roles", a.RequirePermission("rbac.roles.create"), h.CreateRole)
|
||||
rbacGroup.Put("/roles/:id", a.RequirePermission("rbac.roles.update"), h.UpdateRole)
|
||||
rbacGroup.Delete("/roles/:id", a.RequirePermission("rbac.roles.delete"), h.DeleteRole)
|
||||
rbacGroup.Put("/roles/:id/permissions", a.RequirePermission("rbac.roles.set_permissions"), h.SetRolePermissions)
|
||||
rbacGroup.Get("/roles/:id/permissions", a.RequirePermission("rbac.roles.get_permissions"), h.GetRolePermissions)
|
||||
rbacGroup.Get("/permissions", a.RequirePermission("rbac.permissions.list"), h.ListPermissions)
|
||||
rbacGroup.Get("/permissions/groups", a.RequirePermission("rbac.permissions.groups"), h.ListPermissionGroups)
|
||||
rbacGroup.Post("/permissions/sync", a.RequirePermission("rbac.permissions.sync"), h.SyncPermissions)
|
||||
|
||||
}
|
||||
|
|
|
|||
235
internal/web_server/routes_admin.go
Normal file
235
internal/web_server/routes_admin.go
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/web_server/handlers"
|
||||
"context"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (a *App) initAdminRoutes(api fiber.Router, h *handlers.Handler) {
|
||||
api.Get("/referrals/settings", a.adminAuthMiddleware, a.OnlyAdminAndAbove, h.GetReferralSettings)
|
||||
api.Put("/referrals/settings", a.adminAuthMiddleware, a.OnlyAdminAndAbove, h.UpdateReferralSettings)
|
||||
api.Post("/exam-prep/catalog-courses", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.create"), h.CreateExamPrepCatalogCourse)
|
||||
api.Get("/exam-prep/catalog-courses", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.list"), h.ListExamPrepCatalogCourses)
|
||||
api.Put("/exam-prep/catalog-courses/reorder", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.reorder"), h.ReorderExamPrepCatalogCourses)
|
||||
api.Get("/exam-prep/catalog-courses/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.get"), h.GetExamPrepCatalogCourseByID)
|
||||
api.Put("/exam-prep/catalog-courses/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.update"), h.UpdateExamPrepCatalogCourse)
|
||||
api.Delete("/exam-prep/catalog-courses/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.delete"), h.DeleteExamPrepCatalogCourse)
|
||||
api.Post("/exam-prep/catalog-courses/:catalogCourseId/units", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.create"), h.CreateExamPrepUnit)
|
||||
api.Get("/exam-prep/catalog-courses/:catalogCourseId/units", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.list"), h.ListExamPrepUnitsByCatalogCourse)
|
||||
api.Put("/exam-prep/catalog-courses/:catalogCourseId/units/reorder", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.reorder"), h.ReorderExamPrepUnitsInCatalogCourse)
|
||||
api.Get("/exam-prep/units/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.get"), h.GetExamPrepUnitByID)
|
||||
api.Put("/exam-prep/units/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.update"), h.UpdateExamPrepUnit)
|
||||
api.Delete("/exam-prep/units/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.units.delete"), h.DeleteExamPrepUnit)
|
||||
api.Post("/exam-prep/units/:unitId/modules", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.create"), h.CreateExamPrepModule)
|
||||
api.Get("/exam-prep/units/:unitId/modules", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.list"), h.ListExamPrepModulesByUnit)
|
||||
api.Put("/exam-prep/units/:unitId/modules/reorder", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.reorder"), h.ReorderExamPrepModulesInUnit)
|
||||
api.Get("/exam-prep/modules/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.get"), h.GetExamPrepModuleByID)
|
||||
api.Put("/exam-prep/modules/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.update"), h.UpdateExamPrepModule)
|
||||
api.Delete("/exam-prep/modules/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.modules.delete"), h.DeleteExamPrepModule)
|
||||
api.Post("/exam-prep/modules/:moduleId/lessons", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.create"), h.CreateExamPrepLesson)
|
||||
api.Get("/exam-prep/modules/:moduleId/lessons", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.list_by_module"), h.ListExamPrepLessonsByUnitModule)
|
||||
api.Put("/exam-prep/modules/:moduleId/lessons/reorder", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.reorder"), h.ReorderExamPrepLessonsInUnitModule)
|
||||
api.Get("/exam-prep/lessons/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.get"), h.GetExamPrepLessonByID)
|
||||
api.Put("/exam-prep/lessons/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.update"), h.UpdateExamPrepLesson)
|
||||
api.Delete("/exam-prep/lessons/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.lessons.delete"), h.DeleteExamPrepLesson)
|
||||
api.Get("/exam-prep/assessments", a.adminAuthMiddleware, a.RequirePermission("question_sets.list"), h.ListExamPrepAssessments)
|
||||
api.Post("/exam-prep/assessments", a.adminAuthMiddleware, a.RequirePermission("question_sets.update"), h.LinkExamPrepAssessment)
|
||||
api.Delete("/exam-prep/assessments/:questionSetId/parents/:parentKind/:parentId", a.adminAuthMiddleware, a.RequirePermission("question_sets.update"), h.UnlinkExamPrepAssessment)
|
||||
api.Post("/exam-prep/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.create"), h.CreateExamPrepPracticeFromInput)
|
||||
api.Get("/exam-prep/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.list"), h.ListAllExamPrepPractices)
|
||||
api.Get("/exam-prep/catalog-courses/:catalogCourseId/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_catalog_course"), h.ListExamPrepPracticesByCatalogCourse)
|
||||
api.Post("/exam-prep/catalog-courses/:catalogCourseId/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.create"), h.CreateExamPrepPracticeForCatalogCourse)
|
||||
api.Get("/exam-prep/units/:unitId/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_unit"), h.ListExamPrepPracticesByUnit)
|
||||
api.Post("/exam-prep/units/:unitId/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.create"), h.CreateExamPrepPracticeForUnit)
|
||||
api.Get("/exam-prep/lessons/:lessonId/practices", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_lesson"), h.ListExamPrepPracticesByLesson)
|
||||
api.Get("/exam-prep/practices/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.get"), h.GetExamPrepPracticeByID)
|
||||
api.Get("/exam-prep/practices/:id/full", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.get"), h.GetExamPrepPracticeFull)
|
||||
api.Put("/exam-prep/practices/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.update"), h.UpdateExamPrepPractice)
|
||||
api.Put("/exam-prep/practices/:id/full", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.update"), h.UpdateExamPrepPracticeFull)
|
||||
api.Put("/exam-prep/practices/:id/parents", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.update"), h.UpdateExamPrepPracticeParents)
|
||||
api.Delete("/exam-prep/practices/:id/parents/:parentKind/:parentId", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.update"), h.UnlinkExamPrepPracticeParent)
|
||||
api.Delete("/exam-prep/practices/:id", a.adminAuthMiddleware, a.RequirePermission("exam_prep.practices.delete"), h.DeleteExamPrepPractice)
|
||||
api.Get("/personas", a.adminAuthMiddleware, a.RequirePermission("personas.list"), h.ListPersonas)
|
||||
api.Post("/personas", a.adminAuthMiddleware, a.RequirePermission("personas.create"), h.CreatePersona)
|
||||
api.Get("/personas/:id", a.adminAuthMiddleware, a.RequirePermission("personas.get"), h.GetPersona)
|
||||
api.Put("/personas/:id", a.adminAuthMiddleware, a.RequirePermission("personas.update"), h.UpdatePersona)
|
||||
api.Delete("/personas/:id", a.adminAuthMiddleware, a.RequirePermission("personas.delete"), h.DeletePersona)
|
||||
api.Get("/files/url", a.adminAuthMiddleware, h.GetFileURL)
|
||||
api.Post("/files/refresh-url", a.adminAuthMiddleware, h.RefreshFileURL)
|
||||
api.Post("/files/presign-upload", a.adminAuthMiddleware, h.CreatePresignedUpload)
|
||||
api.Post("/files/complete-upload", a.adminAuthMiddleware, h.CompletePresignedUpload)
|
||||
api.Post("/files/upload", a.adminAuthMiddleware, h.UploadMedia)
|
||||
api.Post("/files/audio", a.adminAuthMiddleware, h.UploadAudio)
|
||||
api.Post("/questions", a.adminAuthMiddleware, a.RequirePermission("questions.create"), h.CreateQuestion)
|
||||
api.Get("/questions", a.adminAuthMiddleware, a.RequirePermission("questions.list"), h.ListQuestions)
|
||||
api.Get("/questions/search", a.adminAuthMiddleware, a.RequirePermission("questions.search"), h.SearchQuestions)
|
||||
api.Get("/questions/component-catalog", a.adminAuthMiddleware, a.RequirePermission("questions.list"), h.GetQuestionTypeComponentCatalog)
|
||||
api.Post("/questions/validate-question-type-definition", a.adminAuthMiddleware, a.RequirePermission("questions.create"), h.ValidateQuestionTypeDefinition)
|
||||
api.Post("/questions/type-definition-groups", a.adminAuthMiddleware, a.RequirePermission("questions.create"), h.CreateQuestionTypeDefinitionGroup)
|
||||
api.Get("/questions/type-definition-groups", a.adminAuthMiddleware, a.RequirePermission("questions.list"), h.ListQuestionTypeDefinitionGroups)
|
||||
api.Get("/questions/type-definition-groups/:id", a.adminAuthMiddleware, a.RequirePermission("questions.get"), h.GetQuestionTypeDefinitionGroupByID)
|
||||
api.Put("/questions/type-definition-groups/:id", a.adminAuthMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestionTypeDefinitionGroup)
|
||||
api.Delete("/questions/type-definition-groups/:id", a.adminAuthMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestionTypeDefinitionGroup)
|
||||
api.Post("/questions/type-definitions", a.adminAuthMiddleware, a.RequirePermission("questions.create"), h.CreateQuestionTypeDefinition)
|
||||
api.Get("/questions/type-definitions", a.adminAuthMiddleware, a.RequirePermission("questions.list"), h.ListQuestionTypeDefinitions)
|
||||
api.Get("/questions/type-definitions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.get"), h.GetQuestionTypeDefinitionByID)
|
||||
api.Get("/questions/type-definitions/:id/practices", a.adminAuthMiddleware, a.RequirePermission("practices.list"), h.ListPracticesByQuestionTypeDefinition)
|
||||
api.Put("/questions/type-definitions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestionTypeDefinition)
|
||||
api.Delete("/questions/type-definitions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestionTypeDefinition)
|
||||
api.Get("/questions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.get"), h.GetQuestionByID)
|
||||
api.Put("/questions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.update"), h.UpdateQuestion)
|
||||
api.Delete("/questions/:id", a.adminAuthMiddleware, a.RequirePermission("questions.delete"), h.DeleteQuestion)
|
||||
api.Get("/faqs", a.adminAuthMiddleware, a.RequirePermission("faqs.list"), h.ListFAQsAdmin)
|
||||
api.Get("/faqs/:id", a.adminAuthMiddleware, a.RequirePermission("faqs.get"), h.GetFAQByIDAdmin)
|
||||
api.Post("/faqs", a.adminAuthMiddleware, a.RequirePermission("faqs.create"), h.CreateFAQ)
|
||||
api.Put("/faqs/:id", a.adminAuthMiddleware, a.RequirePermission("faqs.update"), h.UpdateFAQ)
|
||||
api.Delete("/faqs/:id", a.adminAuthMiddleware, a.RequirePermission("faqs.delete"), h.DeleteFAQ)
|
||||
api.Get("/app-versions", a.adminAuthMiddleware, a.RequirePermission("app_versions.list"), h.ListMobileAppVersionsAdmin)
|
||||
api.Get("/app-versions/:id", a.adminAuthMiddleware, a.RequirePermission("app_versions.get"), h.GetMobileAppVersionByIDAdmin)
|
||||
api.Post("/app-versions", a.adminAuthMiddleware, a.RequirePermission("app_versions.create"), h.CreateMobileAppVersion)
|
||||
api.Put("/app-versions/:id", a.adminAuthMiddleware, a.RequirePermission("app_versions.update"), h.UpdateMobileAppVersion)
|
||||
api.Delete("/app-versions/:id", a.adminAuthMiddleware, a.RequirePermission("app_versions.delete"), h.DeleteMobileAppVersion)
|
||||
api.Get("/email-templates", a.adminAuthMiddleware, a.RequirePermission("email_templates.list"), h.ListEmailTemplatesAdmin)
|
||||
api.Get("/email-templates/slug/:slug", a.adminAuthMiddleware, a.RequirePermission("email_templates.get"), h.GetEmailTemplateBySlugAdmin)
|
||||
api.Post("/email-templates/slug/:slug/preview", a.adminAuthMiddleware, a.RequirePermission("email_templates.preview"), h.PreviewEmailTemplateBySlug)
|
||||
api.Get("/email-templates/:id", a.adminAuthMiddleware, a.RequirePermission("email_templates.get"), h.GetEmailTemplateByIDAdmin)
|
||||
api.Post("/email-templates/:id/preview", a.adminAuthMiddleware, a.RequirePermission("email_templates.preview"), h.PreviewEmailTemplateByID)
|
||||
api.Post("/email-templates", a.adminAuthMiddleware, a.RequirePermission("email_templates.create"), h.CreateEmailTemplate)
|
||||
api.Put("/email-templates/:id", a.adminAuthMiddleware, a.RequirePermission("email_templates.update"), h.UpdateEmailTemplate)
|
||||
api.Delete("/email-templates/:id", a.adminAuthMiddleware, a.RequirePermission("email_templates.delete"), h.DeleteEmailTemplate)
|
||||
api.Get("/field-options", a.adminAuthMiddleware, a.RequirePermission("field_options.list"), h.ListFieldOptionsAdmin)
|
||||
api.Get("/field-options/:id", a.adminAuthMiddleware, a.RequirePermission("field_options.get"), h.GetFieldOptionByIDAdmin)
|
||||
api.Post("/field-options", a.adminAuthMiddleware, a.RequirePermission("field_options.create"), h.CreateFieldOption)
|
||||
api.Put("/field-options/:id", a.adminAuthMiddleware, a.RequirePermission("field_options.update"), h.UpdateFieldOption)
|
||||
api.Delete("/field-options/:id", a.adminAuthMiddleware, a.RequirePermission("field_options.delete"), h.DeleteFieldOption)
|
||||
api.Get("/payments", a.adminAuthMiddleware, a.RequirePermission("payments.list_all"), h.ListAdminPayments)
|
||||
api.Get("/payments/export", a.adminAuthMiddleware, a.RequirePermission("payments.export"), h.ExportAdminPaymentsCSV)
|
||||
api.Get("/payments/:id", a.adminAuthMiddleware, a.RequirePermission("payments.list_all"), h.GetAdminPayment)
|
||||
api.Post("/question-sets", a.adminAuthMiddleware, a.RequirePermission("question_sets.create"), h.CreateQuestionSet)
|
||||
api.Get("/question-sets", a.adminAuthMiddleware, a.RequirePermission("question_sets.list"), h.GetQuestionSetsByType)
|
||||
api.Get("/question-sets/by-owner", a.adminAuthMiddleware, a.RequirePermission("question_sets.list_by_owner"), h.GetQuestionSetsByOwner)
|
||||
api.Get("/question-sets/:id", a.adminAuthMiddleware, a.RequirePermission("question_sets.get"), h.GetQuestionSetByID)
|
||||
api.Put("/question-sets/:id", a.adminAuthMiddleware, a.RequirePermission("question_sets.update"), h.UpdateQuestionSet)
|
||||
api.Delete("/question-sets/:id", a.adminAuthMiddleware, a.RequirePermission("question_sets.delete"), h.DeleteQuestionSet)
|
||||
api.Post("/question-sets/:setId/questions", a.adminAuthMiddleware, a.RequirePermission("question_set_items.add"), h.AddQuestionToSet)
|
||||
api.Get("/question-sets/:setId/question-types", a.adminAuthMiddleware, a.RequirePermission("question_set_items.list"), h.GetQuestionTypesInSet)
|
||||
api.Get("/question-sets/:setId/questions", a.adminAuthMiddleware, a.RequirePermission("question_set_items.list"), h.GetQuestionsInSet)
|
||||
api.Delete("/question-sets/:setId/questions/:questionId", a.adminAuthMiddleware, a.RequirePermission("question_set_items.remove"), h.RemoveQuestionFromSet)
|
||||
api.Put("/question-sets/:setId/questions/:questionId/order", a.adminAuthMiddleware, a.RequirePermission("question_set_items.update_order"), h.UpdateQuestionOrderInSet)
|
||||
api.Get("/question-sets/:setId/personas", a.adminAuthMiddleware, a.RequirePermission("question_set_personas.list"), h.GetUserPersonasByQuestionSet)
|
||||
api.Post("/question-sets/:setId/personas", a.adminAuthMiddleware, a.RequirePermission("question_set_personas.add"), h.AddUserPersonaToQuestionSet)
|
||||
api.Delete("/question-sets/:setId/personas/:userId", a.adminAuthMiddleware, a.RequirePermission("question_set_personas.remove"), h.RemoveUserPersonaFromQuestionSet)
|
||||
api.Post("/subscription-plans", a.adminAuthMiddleware, a.RequirePermission("subscription_plans.create"), h.CreateSubscriptionPlan)
|
||||
api.Get("/subscription-plans", a.adminAuthMiddleware, h.ListSubscriptionPlans)
|
||||
api.Get("/subscription-plans/:id", a.adminAuthMiddleware, h.GetSubscriptionPlan)
|
||||
api.Put("/subscription-plans/:id", a.adminAuthMiddleware, a.RequirePermission("subscription_plans.update"), h.UpdateSubscriptionPlan)
|
||||
api.Delete("/subscription-plans/:id", a.adminAuthMiddleware, a.RequirePermission("subscription_plans.delete"), h.DeleteSubscriptionPlan)
|
||||
api.Post("/auth/admin-login", h.LoginAdmin)
|
||||
api.Post("/auth/super-login", h.LoginSuper)
|
||||
api.Get("/users", a.adminAuthMiddleware, a.RequirePermission("users.list"), h.GetAllUsers)
|
||||
api.Get("/users/export", a.adminAuthMiddleware, a.RequirePermission("users.export"), h.ExportUsersCSV)
|
||||
api.Get("/users/deletion-requests", a.adminAuthMiddleware, a.RequirePermission("users.deletion_requests.list"), h.ListAccountDeletionRequests)
|
||||
api.Get("/subscriptions/export", a.adminAuthMiddleware, a.RequirePermission("subscriptions.export"), h.ExportUserSubscriptionsCSV)
|
||||
api.Post("/subscriptions/:id/cancel", a.adminAuthMiddleware, a.RequirePermission("subscriptions.admin_cancel"), h.AdminCancelUserSubscription)
|
||||
api.Get("/users/:user_id/recent-activity", a.adminAuthMiddleware, a.RequirePermission("progress.get_any_user"), h.AdminGetUserRecentActivity)
|
||||
api.Get("/users/:user_id/learning-activity", a.adminAuthMiddleware, a.RequirePermission("progress.get_any_user"), h.AdminGetUserLearningActivityDetails)
|
||||
api.Get("/users/:user_id/subscriptions", a.adminAuthMiddleware, a.RequirePermission("subscriptions.get_by_user"), h.AdminGetUserSubscriptions)
|
||||
api.Post("/users/:user_id/subscriptions/extend", a.adminAuthMiddleware, a.RequirePermission("subscriptions.admin_extend"), h.AdminExtendOrGrantUserSubscription)
|
||||
api.Get("/users/summary", a.adminAuthMiddleware, a.RequirePermission("users.summary"), h.GetUserSummary)
|
||||
api.Patch("/user/status", a.adminAuthMiddleware, a.RequirePermission("users.update_status"), h.UpdateUserStatus)
|
||||
api.Post("/user/:id/profile-picture", a.adminAuthMiddleware, a.RequirePermission("users.upload_profile_picture"), h.UploadProfilePicture)
|
||||
api.Get("/user/admin-profile", a.adminAuthMiddleware, a.RequirePermission("users.admin_profile"), h.AdminProfile)
|
||||
api.Post("/internal/users/purge-due-deletions", a.adminAuthMiddleware, a.RequirePermission("users.purge_due_deletions"), h.PurgeDueDeletedUsers)
|
||||
api.Get("/user/single/:id", a.adminAuthMiddleware, a.RequirePermission("users.get"), h.GetUserByID)
|
||||
api.Delete("/user/delete/:id", a.adminAuthMiddleware, a.RequirePermission("users.delete"), h.DeleteUser)
|
||||
api.Post("/user/search", a.adminAuthMiddleware, a.RequirePermission("users.search"), h.SearchUserByNameOrPhone)
|
||||
api.Get("/admins", a.adminAuthMiddleware, a.RequirePermission("admins.list"), h.GetAllAdmins)
|
||||
api.Get("/admins/:id<int>", a.adminAuthMiddleware, a.RequirePermission("admins.get"), h.GetAdminByID)
|
||||
api.Post("/admins", a.adminAuthMiddleware, a.RequirePermission("admins.create"), h.CreateAdmin)
|
||||
api.Put("/admins/:id<int>", a.adminAuthMiddleware, a.RequirePermission("admins.update"), h.UpdateAdmin)
|
||||
api.Post("/admins/roles/:role/bulk-deactivate", a.adminAuthMiddleware, h.BulkDeactivateAccountsByRole)
|
||||
api.Post("/admins/roles/:role/bulk-reactivate", a.adminAuthMiddleware, h.BulkReactivateAccountsByRole)
|
||||
api.Get("/logs", a.adminAuthMiddleware, a.RequirePermission("logs.list"), handlers.GetLogsHandler(context.Background()))
|
||||
api.Get("/activity-logs", a.adminAuthMiddleware, a.RequirePermission("activity_logs.list"), h.GetActivityLogs)
|
||||
api.Get("/activity-logs/export", a.adminAuthMiddleware, a.RequirePermission("activity_logs.export"), h.ExportActivityLogsCSV)
|
||||
api.Get("/activity-logs/:id", a.adminAuthMiddleware, a.RequirePermission("activity_logs.get"), h.GetActivityLogByID)
|
||||
api.Post("/sendSMS", a.adminAuthMiddleware, h.SendSingleAfroSMS)
|
||||
api.Get("/ws/connect", a.adminWebsocketAuthMiddleware, h.ConnectSocket)
|
||||
api.Get("/notifications", a.adminAuthMiddleware, a.RequirePermission("notifications.list_mine"), h.GetUserNotification)
|
||||
api.Get("/notifications/all", a.adminAuthMiddleware, a.RequirePermission("notifications.list_all"), h.GetAllNotifications)
|
||||
api.Patch("/notifications/:id/read", a.adminAuthMiddleware, a.RequirePermission("notifications.mark_read"), h.MarkNotificationAsRead)
|
||||
api.Post("/notifications/mark-all-read", a.adminAuthMiddleware, a.RequirePermission("notifications.mark_all_read"), h.MarkAllNotificationsAsRead)
|
||||
api.Patch("/notifications/:id/unread", a.adminAuthMiddleware, a.RequirePermission("notifications.mark_unread"), h.MarkNotificationAsUnread)
|
||||
api.Post("/notifications/mark-all-unread", a.adminAuthMiddleware, a.RequirePermission("notifications.mark_all_unread"), h.MarkAllNotificationsAsUnread)
|
||||
api.Delete("/notifications", a.adminAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteUserNotifications)
|
||||
api.Post("/notifications/delete-in-app", a.adminAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotifications)
|
||||
api.Get("/notifications/unread", a.adminAuthMiddleware, a.RequirePermission("notifications.count_unread"), h.CountUnreadNotifications)
|
||||
api.Post("/notifications/create", a.adminAuthMiddleware, a.RequirePermission("notifications.create"), h.CreateAndSendNotification)
|
||||
api.Post("/notifications/test-push", a.adminAuthMiddleware, a.RequirePermission("notifications.test_push"), h.SendTestPushNotification)
|
||||
api.Post("/notifications/bulk-push", a.adminAuthMiddleware, a.RequirePermission("notifications.bulk_push"), h.SendBulkPushNotification)
|
||||
api.Post("/notifications/bulk-sms", a.adminAuthMiddleware, a.RequirePermission("notifications.bulk_sms"), h.SendBulkSMS)
|
||||
api.Post("/notifications/bulk-in-app", a.adminAuthMiddleware, a.RequirePermission("notifications.bulk_in_app"), h.SendBulkInAppNotification)
|
||||
api.Post("/notifications/send-email", a.adminAuthMiddleware, a.RequirePermission("notifications.send_email"), h.SendSingleEmail)
|
||||
api.Post("/notifications/bulk-email", a.adminAuthMiddleware, a.RequirePermission("notifications.bulk_email"), h.SendBulkEmail)
|
||||
api.Get("/notifications/scheduled", a.adminAuthMiddleware, a.RequirePermission("notifications_scheduled.list"), h.ListScheduledNotifications)
|
||||
api.Get("/notifications/scheduled/:id", a.adminAuthMiddleware, a.RequirePermission("notifications_scheduled.get"), h.GetScheduledNotification)
|
||||
api.Post("/notifications/scheduled/:id/cancel", a.adminAuthMiddleware, a.RequirePermission("notifications_scheduled.cancel"), h.CancelScheduledNotification)
|
||||
api.Delete("/notifications/:id", a.adminAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotification)
|
||||
api.Get("/notifications/:id", a.adminAuthMiddleware, a.RequirePermission("notifications.list_mine"), h.GetNotificationByID)
|
||||
api.Get("/issues/user/:user_id", a.adminAuthMiddleware, a.RequirePermission("issues.list_by_user"), h.GetUserIssues)
|
||||
api.Get("/issues", a.adminAuthMiddleware, a.RequirePermission("issues.list_all"), h.GetAllIssues)
|
||||
api.Get("/issues/:id", a.adminAuthMiddleware, a.RequirePermission("issues.get"), h.GetIssueByID)
|
||||
api.Patch("/issues/:id/status", a.adminAuthMiddleware, a.RequirePermission("issues.update_status"), h.UpdateIssueStatus)
|
||||
api.Delete("/issues/:id", a.adminAuthMiddleware, a.RequirePermission("issues.delete"), h.DeleteIssue)
|
||||
api.Post("/devices/register", a.adminAuthMiddleware, a.RequirePermission("devices.register"), h.RegisterDeviceToken)
|
||||
api.Post("/devices/unregister", a.adminAuthMiddleware, a.RequirePermission("devices.unregister"), h.UnregisterDeviceToken)
|
||||
api.Get("/settings", a.adminAuthMiddleware, a.RequirePermission("settings.list"), h.GetGlobalSettingList)
|
||||
api.Get("/settings/:key", a.adminAuthMiddleware, a.RequirePermission("settings.get"), h.GetGlobalSettingByKey)
|
||||
api.Put("/settings", a.adminAuthMiddleware, a.RequirePermission("settings.update"), h.UpdateGlobalSettingList)
|
||||
api.Get("/analytics/dashboard", a.adminAuthMiddleware, a.RequirePermission("analytics.dashboard"), h.GetAnalyticsDashboard)
|
||||
api.Get("/vimeo/videos", a.adminAuthMiddleware, a.RequirePermission("vimeo.videos.list"), h.ListVimeoVideos)
|
||||
api.Get("/vimeo/videos/:video_id", a.adminAuthMiddleware, a.RequirePermission("vimeo.videos.get"), h.GetVimeoVideo)
|
||||
api.Get("/vimeo/videos/:video_id/embed", a.adminAuthMiddleware, a.RequirePermission("vimeo.videos.embed"), h.GetEmbedCode)
|
||||
api.Get("/vimeo/videos/:video_id/status", a.adminAuthMiddleware, a.RequirePermission("vimeo.videos.status"), h.GetTranscodeStatus)
|
||||
api.Delete("/vimeo/videos/:video_id", a.adminAuthMiddleware, a.RequirePermission("vimeo.videos.delete"), h.DeleteVimeoVideo)
|
||||
api.Post("/vimeo/uploads/pull", a.adminAuthMiddleware, a.RequirePermission("vimeo.uploads.pull"), h.CreatePullUpload)
|
||||
api.Post("/vimeo/uploads/tus", a.adminAuthMiddleware, a.RequirePermission("vimeo.uploads.tus"), h.CreateTusUpload)
|
||||
api.Get("/vimeo/oembed", a.adminAuthMiddleware, h.GetOEmbed)
|
||||
api.Get("/vimeo/sample", a.adminAuthMiddleware, h.GetSampleVideo)
|
||||
api.Post("/team/login", h.TeamMemberLogin)
|
||||
api.Post("/team/refresh", h.TeamMemberRefresh)
|
||||
api.Post("/team/sendResetCode", h.SendTeamPasswordReset)
|
||||
api.Get("/team/verifyResetCode", h.VerifyTeamPasswordReset)
|
||||
api.Post("/team/resetPassword", h.ResetTeamPassword)
|
||||
api.Get("/team/invitations/verify", h.VerifyTeamInvitation)
|
||||
api.Post("/team/invitations/accept", h.AcceptTeamInvitation)
|
||||
api.Get("/team/me", a.adminAuthMiddleware, a.RequirePermission("team.profile.get_mine"), h.GetMyTeamProfile)
|
||||
api.Put("/team/me", a.adminAuthMiddleware, a.RequirePermission("team.profile.update_mine"), h.UpdateMyTeamProfile)
|
||||
api.Get("/team/stats", a.adminAuthMiddleware, a.RequirePermission("team.stats"), h.GetTeamMemberStats)
|
||||
api.Get("/team/members", a.adminAuthMiddleware, a.RequirePermission("team.members.list"), h.GetAllTeamMembers)
|
||||
api.Get("/team/members/export", a.adminAuthMiddleware, a.RequirePermission("team.members.export"), h.ExportTeamMembersCSV)
|
||||
api.Post("/team/members/invite", a.adminAuthMiddleware, a.RequirePermission("team.members.invite"), h.InviteTeamMember)
|
||||
api.Post("/team/members", a.adminAuthMiddleware, a.RequirePermission("team.members.create"), h.CreateTeamMember)
|
||||
api.Post("/team/members/:id/resend-invite", a.adminAuthMiddleware, a.RequirePermission("team.invitations.resend"), h.ResendTeamInvitation)
|
||||
api.Get("/team/members/:id", a.adminAuthMiddleware, a.RequirePermission("team.members.get"), h.GetTeamMember)
|
||||
api.Put("/team/members/:id", a.adminAuthMiddleware, a.RequirePermission("team.members.update"), h.UpdateTeamMember)
|
||||
api.Patch("/team/members/:id/status", a.adminAuthMiddleware, a.RequirePermission("team.members.update_status"), h.UpdateTeamMemberStatus)
|
||||
api.Delete("/team/members/:id", a.adminAuthMiddleware, a.RequirePermission("team.members.delete"), h.DeleteTeamMember)
|
||||
api.Post("/team/members/:id/change-password", a.adminAuthMiddleware, a.RequirePermission("team.members.change_password"), h.ChangeTeamMemberPassword)
|
||||
api.Get("/team/invitations", a.adminAuthMiddleware, a.RequirePermission("team.invitations.list"), h.ListTeamInvitations)
|
||||
api.Post("/team/invitations/:id/revoke", a.adminAuthMiddleware, a.RequirePermission("team.invitations.revoke"), h.RevokeTeamInvitation)
|
||||
api.Get("/ratings", a.adminAuthMiddleware, a.RequirePermission("ratings.list_by_target"), h.GetRatingsByTarget)
|
||||
api.Get("/ratings/summary", a.adminAuthMiddleware, a.RequirePermission("ratings.summary"), h.GetRatingSummary)
|
||||
api.Delete("/ratings/:id", a.adminAuthMiddleware, a.RequirePermission("ratings.delete"), h.DeleteRating)
|
||||
api.Get("/rbac/roles", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.list"), h.ListRoles)
|
||||
api.Get("/rbac/roles/:id", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.get"), h.GetRoleByID)
|
||||
api.Post("/rbac/roles", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.create"), h.CreateRole)
|
||||
api.Put("/rbac/roles/:id", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.update"), h.UpdateRole)
|
||||
api.Delete("/rbac/roles/:id", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.delete"), h.DeleteRole)
|
||||
api.Put("/rbac/roles/:id/permissions", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.set_permissions"), h.SetRolePermissions)
|
||||
api.Get("/rbac/roles/:id/permissions", a.adminAuthMiddleware, a.RequirePermission("rbac.roles.get_permissions"), h.GetRolePermissions)
|
||||
api.Get("/rbac/permissions", a.adminAuthMiddleware, a.RequirePermission("rbac.permissions.list"), h.ListPermissions)
|
||||
api.Get("/rbac/permissions/groups", a.adminAuthMiddleware, a.RequirePermission("rbac.permissions.groups"), h.ListPermissionGroups)
|
||||
api.Post("/rbac/permissions/sync", a.adminAuthMiddleware, a.RequirePermission("rbac.permissions.sync"), h.SyncPermissions)
|
||||
}
|
||||
113
internal/web_server/routes_client.go
Normal file
113
internal/web_server/routes_client.go
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/web_server/handlers"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (a *App) initClientRoutes(api fiber.Router, h *handlers.Handler) {
|
||||
api.Post("/referrals/code", apiAudience("client"), a.clientAuthMiddleware, h.CreateReferralCode)
|
||||
api.Get("/referrals/code", apiAudience("client"), a.clientAuthMiddleware, h.GetReferralCode)
|
||||
api.Get("/referrals/me", apiAudience("client"), a.clientAuthMiddleware, h.GetMyReferrals)
|
||||
api.Post("/referrals/apply", apiAudience("client"), a.clientAuthMiddleware, h.ApplyReferralCode)
|
||||
api.Get("/referrals", apiAudience("client"), a.clientAuthMiddleware, h.ListMyReferrals)
|
||||
api.Get("/referrals/wallet", apiAudience("client"), a.clientAuthMiddleware, h.GetReferralWallet)
|
||||
api.Get("/exam-prep/catalog-courses", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.list"), h.ListExamPrepCatalogCourses)
|
||||
api.Get("/exam-prep/catalog-courses/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.catalog_courses.get"), h.GetExamPrepCatalogCourseByID)
|
||||
api.Get("/exam-prep/catalog-courses/:catalogCourseId/units", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.units.list"), h.ListExamPrepUnitsByCatalogCourse)
|
||||
api.Get("/exam-prep/units/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.units.get"), h.GetExamPrepUnitByID)
|
||||
api.Get("/exam-prep/units/:unitId/modules", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.modules.list"), h.ListExamPrepModulesByUnit)
|
||||
api.Get("/exam-prep/modules/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.modules.get"), h.GetExamPrepModuleByID)
|
||||
api.Get("/exam-prep/modules/:moduleId/lessons", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.lessons.list_by_module"), a.RequireExamPrepSubscription(), h.ListExamPrepLessonsByUnitModule)
|
||||
api.Get("/exam-prep/lessons/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.lessons.get"), a.RequireExamPrepSubscription(), h.GetExamPrepLessonByID)
|
||||
api.Get("/exam-prep/assessments", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("question_sets.list"), a.RequireExamPrepSubscription(), h.ListExamPrepAssessments)
|
||||
api.Get("/exam-prep/practices", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.practices.list"), a.RequireExamPrepSubscription(), h.ListAllExamPrepPractices)
|
||||
api.Get("/exam-prep/catalog-courses/:catalogCourseId/practices", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_catalog_course"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByCatalogCourse)
|
||||
api.Get("/exam-prep/units/:unitId/practices", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_unit"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByUnit)
|
||||
api.Get("/exam-prep/lessons/:lessonId/practices", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.practices.list_by_lesson"), a.RequireExamPrepSubscription(), h.ListExamPrepPracticesByLesson)
|
||||
api.Get("/exam-prep/practices/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("exam_prep.practices.get"), a.RequireExamPrepSubscription(), h.GetExamPrepPracticeByID)
|
||||
api.Post("/exam-prep/progress/practices/:id/complete", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("progress.complete"), a.RequireExamPrepSubscription(), h.CompletePractice)
|
||||
api.Post("/exam-prep/videos/engagement/heartbeat", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("videos.track_engagement"), a.RequireExamPrepSubscription(), h.RecordVideoEngagementHeartbeat)
|
||||
api.Get("/exam-prep/progress-summary", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("lms.get_my_progress"), h.GetMyLMSProgressSummary)
|
||||
api.Get("/exam-prep/practices/:practiceId/questions", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("question_set_items.list"), a.RequireExamPrepSubscription(), h.GetQuestionsByPractice)
|
||||
api.Get("/personas", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("personas.list"), h.ListPersonas)
|
||||
api.Get("/personas/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("personas.get"), h.GetPersona)
|
||||
api.Get("/files/url", apiAudience("client"), a.clientAuthMiddleware, h.GetFileURL)
|
||||
api.Post("/files/refresh-url", apiAudience("client"), a.clientAuthMiddleware, h.RefreshFileURL)
|
||||
api.Post("/files/presign-upload", apiAudience("client"), a.clientAuthMiddleware, h.CreatePresignedUpload)
|
||||
api.Post("/files/complete-upload", apiAudience("client"), a.clientAuthMiddleware, h.CompletePresignedUpload)
|
||||
api.Post("/files/upload", apiAudience("client"), a.clientAuthMiddleware, h.UploadMedia)
|
||||
api.Post("/files/audio", apiAudience("client"), a.clientAuthMiddleware, h.UploadAudio)
|
||||
api.Post("/questions/audio-answer", apiAudience("client"), a.clientAuthMiddleware, h.SubmitAudioAnswer)
|
||||
api.Get("/faqs", apiAudience("client"), h.ListPublicFAQs)
|
||||
api.Get("/faqs/:id", apiAudience("client"), h.GetPublicFAQByID)
|
||||
api.Get("/app/version/check", apiAudience("client"), h.CheckMobileAppVersion)
|
||||
api.Get("/field-options", apiAudience("client"), h.ListPublicFieldOptions)
|
||||
api.Get("/field-options/fields", apiAudience("client"), h.ListFieldKeys)
|
||||
api.Get("/subscription-plans", apiAudience("client"), h.ListSubscriptionPlans)
|
||||
api.Get("/subscription-plans/:id", apiAudience("client"), h.GetSubscriptionPlan)
|
||||
api.Post("/subscriptions", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.create"), h.Subscribe)
|
||||
api.Post("/subscriptions/checkout", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.checkout"), h.SubscribeWithPayment)
|
||||
api.Post("/subscriptions/request-checkout-link", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.request_checkout_link"), h.RequestSubscriptionCheckoutLink)
|
||||
api.Get("/subscriptions/me", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.get_mine"), h.GetMySubscription)
|
||||
api.Get("/subscriptions/history", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.history"), h.GetMySubscriptionHistory)
|
||||
api.Get("/subscriptions/status", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.status"), h.CheckSubscriptionStatus)
|
||||
api.Post("/subscriptions/:id/cancel", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.cancel"), h.CancelSubscription)
|
||||
api.Put("/subscriptions/:id/auto-renew", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("subscriptions.set_auto_renew"), h.SetAutoRenew)
|
||||
api.Post("/payments/subscribe", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.initiate"), h.InitiateSubscriptionPayment)
|
||||
api.Get("/payments/verify/:session_id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.verify"), h.VerifyPayment)
|
||||
api.Get("/payments", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.list_mine"), h.GetMyPayments)
|
||||
api.Get("/payments/methods", apiAudience("client"), h.GetChapaPaymentMethods)
|
||||
api.Get("/payments/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.get"), h.GetPaymentByID)
|
||||
api.Post("/payments/:id/cancel", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.cancel"), h.CancelPayment)
|
||||
api.Post("/payments/chapa/direct", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.direct_initiate"), h.InitiateChapaDirectPayment)
|
||||
api.Post("/payments/chapa/direct/authorize", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.direct_verify_otp"), h.AuthorizeChapaDirectPayment)
|
||||
api.Get("/payments/chapa/direct/methods", apiAudience("client"), h.GetChapaDirectPaymentMethods)
|
||||
api.Post("/payments/direct", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.direct_initiate"), h.InitiateDirectPayment)
|
||||
api.Post("/payments/direct/verify-otp", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("payments.direct_verify_otp"), h.VerifyDirectPaymentOTP)
|
||||
api.Get("/payments/direct/methods", apiAudience("client"), h.GetDirectPaymentMethods)
|
||||
api.Post("/auth/google/android", apiAudience("client"), h.GoogleAndroidLogin)
|
||||
api.Get("/auth/google/login", apiAudience("client"), h.GoogleLogin)
|
||||
api.Post("/auth/apple", apiAudience("client"), h.AppleLogin)
|
||||
api.Post("/auth/customer-login", apiAudience("client"), h.LoginUser)
|
||||
api.Post("/auth/refresh", apiAudience("client"), h.RefreshToken)
|
||||
api.Post("/user/:id/profile-picture", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.upload_profile_picture"), h.UploadProfilePicture)
|
||||
api.Post("/auth/logout", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("auth.logout"), h.LogOutuser)
|
||||
api.Get("/user/:user_id/is-profile-completed", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.profile_completed"), h.CheckProfileCompleted)
|
||||
api.Put("/user", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.update_self"), h.UpdateUser)
|
||||
api.Put("/user/knowledge-level", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.update_self"), h.UpdateUserKnowledgeLevel)
|
||||
api.Get("/user/:user_name/is-pending", apiAudience("client"), h.CheckUserPending)
|
||||
api.Post("/user/resetPassword", apiAudience("client"), h.ResetPassword)
|
||||
api.Post("/user/sendResetCode", apiAudience("client"), h.SendResetCode)
|
||||
api.Post("/user/verify-otp", apiAudience("client"), h.VerifyOtp)
|
||||
api.Post("/user/resend-otp", apiAudience("client"), h.ResendOtp)
|
||||
api.Post("/user/register", apiAudience("client"), h.RegisterUser)
|
||||
api.Post("/user/sendRegisterCode", apiAudience("client"), h.SendRegisterCode)
|
||||
api.Post("/user/checkPhoneEmailExist", apiAudience("client"), h.CheckPhoneEmailExist)
|
||||
api.Get("/user/user-profile", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.user_profile"), h.GetUserProfile)
|
||||
api.Delete("/user/me", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.delete_self"), h.DeleteMyUserAccount)
|
||||
api.Post("/user/me/deletion/cancel", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("users.cancel_delete_self"), h.CancelMyUserAccountDeletion)
|
||||
api.Get("/ws/connect", apiAudience("client"), a.clientWebsocketAuthMiddleware, h.ConnectSocket)
|
||||
api.Get("/notifications", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.list_mine"), h.GetUserNotification)
|
||||
api.Patch("/notifications/:id/read", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.mark_read"), h.MarkNotificationAsRead)
|
||||
api.Post("/notifications/mark-all-read", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.mark_all_read"), h.MarkAllNotificationsAsRead)
|
||||
api.Patch("/notifications/:id/unread", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.mark_unread"), h.MarkNotificationAsUnread)
|
||||
api.Post("/notifications/mark-all-unread", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.mark_all_unread"), h.MarkAllNotificationsAsUnread)
|
||||
api.Delete("/notifications", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteUserNotifications)
|
||||
api.Post("/notifications/delete-in-app", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotifications)
|
||||
api.Get("/notifications/unread", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.count_unread"), h.CountUnreadNotifications)
|
||||
api.Delete("/notifications/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.delete_mine"), h.DeleteInAppNotification)
|
||||
api.Get("/notifications/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("notifications.list_mine"), h.GetNotificationByID)
|
||||
api.Post("/issues", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("issues.create"), h.CreateIssue)
|
||||
api.Get("/issues/me", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("issues.list_mine"), h.GetMyIssues)
|
||||
api.Post("/devices/register", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("devices.register"), h.RegisterDeviceToken)
|
||||
api.Post("/devices/unregister", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("devices.unregister"), h.UnregisterDeviceToken)
|
||||
api.Get("/vimeo/oembed", apiAudience("client"), h.GetOEmbed)
|
||||
api.Get("/vimeo/sample", apiAudience("client"), h.GetSampleVideo)
|
||||
api.Post("/ratings", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.submit"), h.SubmitRating)
|
||||
api.Get("/ratings", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.list_by_target"), h.GetRatingsByTarget)
|
||||
api.Get("/ratings/summary", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.summary"), h.GetRatingSummary)
|
||||
api.Get("/ratings/me", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.get_mine"), h.GetMyRating)
|
||||
api.Get("/ratings/me/all", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.list_mine"), h.GetMyRatings)
|
||||
api.Delete("/ratings/:id", apiAudience("client"), a.clientAuthMiddleware, a.RequirePermission("ratings.delete"), h.DeleteRating)
|
||||
}
|
||||
14
internal/web_server/routes_integration.go
Normal file
14
internal/web_server/routes_integration.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package httpserver
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/web_server/handlers"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func (a *App) initIntegrationRoutes(api fiber.Router, h *handlers.Handler) {
|
||||
api.Post("/payments/webhook", h.HandleChapaWebhook)
|
||||
api.Get("/payments/arifpay/success", h.HandleArifpaySuccessPage)
|
||||
api.Get("/payments/chapa/success", h.HandleChapaSuccessPage)
|
||||
api.Get("/payments/chapa/callback", h.HandleChapaCallback)
|
||||
api.Get("/auth/google/callback", h.GoogleCallback)
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package ws
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/domain"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
|
@ -12,8 +13,24 @@ import (
|
|||
)
|
||||
|
||||
type Client struct {
|
||||
Conn *websocket.Conn
|
||||
RecipientID int64
|
||||
ReceiverType domain.ReceiverType
|
||||
Conn *websocket.Conn
|
||||
RecipientID int64
|
||||
}
|
||||
|
||||
func (client *Client) receives(payload map[string]interface{}) bool {
|
||||
recipient, ok := payload["recipient_id"].(int64)
|
||||
if !ok || recipient != client.RecipientID {
|
||||
return false
|
||||
}
|
||||
var receiver domain.ReceiverType
|
||||
switch value := payload["receiver_type"].(type) {
|
||||
case string:
|
||||
receiver = domain.ReceiverType(value)
|
||||
case domain.ReceiverType:
|
||||
receiver = value
|
||||
}
|
||||
return receiver != "" && receiver == client.ReceiverType
|
||||
}
|
||||
|
||||
type NotificationHub struct {
|
||||
|
|
@ -51,7 +68,7 @@ func (h *NotificationHub) Run() {
|
|||
h.mu.Lock()
|
||||
for client := range h.Clients {
|
||||
if payload, ok := message.(map[string]interface{}); ok {
|
||||
if recipient, ok := payload["recipient_id"].(int64); ok && recipient == client.RecipientID {
|
||||
if client.receives(payload) {
|
||||
err := client.Conn.WriteJSON(payload)
|
||||
if err != nil {
|
||||
delete(h.Clients, client)
|
||||
|
|
|
|||
28
internal/web_server/ws/ws_test.go
Normal file
28
internal/web_server/ws/ws_test.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package ws
|
||||
|
||||
import (
|
||||
"Rezina-Backend/internal/domain"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNotificationRecipientIsolation(t *testing.T) {
|
||||
customer := &Client{RecipientID: 42, ReceiverType: domain.ReceiverTypeUser}
|
||||
staff := &Client{RecipientID: 42, ReceiverType: domain.ReceiverTypeTeamMember}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
payload map[string]interface{}
|
||||
customer, staff bool
|
||||
}{
|
||||
{"customer event", map[string]interface{}{"recipient_id": int64(42), "receiver_type": domain.ReceiverTypeUser}, true, false},
|
||||
{"staff event", map[string]interface{}{"recipient_id": int64(42), "receiver_type": domain.ReceiverTypeTeamMember}, false, true},
|
||||
{"serialized type", map[string]interface{}{"recipient_id": int64(42), "receiver_type": "team_member"}, false, true},
|
||||
{"another recipient", map[string]interface{}{"recipient_id": int64(99), "receiver_type": domain.ReceiverTypeUser}, false, false},
|
||||
{"unscoped event", map[string]interface{}{"recipient_id": int64(42)}, false, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if customer.receives(tc.payload) != tc.customer || staff.receives(tc.payload) != tc.staff {
|
||||
t.Fatal("notification crossed account boundary")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user