feat(topup): Admin-wide topup listing and route reorganization

Allow administrators to view all platform topup orders and streamline admin-only routes.

Frontend
- TopupHistoryModal: dynamically switch endpoint by role
  - Admin → GET /api/user/topup (all orders)
  - Non-admin → GET /api/user/topup/self (own orders)
- Use shared utils `isAdmin()`; keep logic centralized and DRY
- Minor UI: set admin action button theme to outline for clarity

Backend
- model/topup.go: add GetAllTopUps(pageInfo) with pagination (ordered by id desc)
- controller/topup.go: add GetAllTopUps handler returning PageInfo response
- router/api-router.go:
  - Add admin route GET /api/user/topup (AdminAuth)
  - Move POST /api/user/topup/complete to adminRoute (keeps path stable, consolidates admin endpoints)

Security/Behavior
- Admin-only endpoints now reside under the admin route group with AdminAuth
- No behavior change for regular users; no schema changes

Affected files
- model/topup.go
- controller/topup.go
- router/api-router.go
- web/src/components/topup/modals/TopupHistoryModal.jsx
This commit is contained in:
Apple\Apple
2025-10-07 00:46:47 +08:00
parent 6ef95c97cc
commit 2389dbafc5
4 changed files with 50 additions and 4 deletions

View File

@@ -63,9 +63,10 @@ const TopupHistoryModal = ({ visible, onCancel, t }) => {
const loadTopups = async (currentPage, currentPageSize) => {
setLoading(true);
try {
const res = await API.get(
`/api/user/topup/self?p=${currentPage}&page_size=${currentPageSize}`,
);
const endpoint = isAdmin()
? `/api/user/topup?p=${currentPage}&page_size=${currentPageSize}`
: `/api/user/topup/self?p=${currentPage}&page_size=${currentPageSize}`;
const res = await API.get(endpoint);
const { success, message, data } = res.data;
if (success) {
setTopups(data.items || []);