Refactor API layer into structured domain-specific modules
- Created new api/ directory with domain-specific API modules: - api/client.ts: Base API client with error handling - api/auth.ts: Authentication endpoints - api/exchange.ts: Exchange/price endpoints - api/trades.ts: User trade endpoints - api/profile.ts: Profile management endpoints - api/invites.ts: Invite endpoints - api/admin.ts: Admin endpoints - api/index.ts: Centralized exports - Migrated all API calls from ad-hoc api.get/post/put to typed domain APIs - Updated all imports across codebase - Fixed test mocks to use new API structure - Fixed type issues in validation utilities - Removed old api.ts file Benefits: - Type-safe endpoints (no more string typos) - Centralized API surface (easy to discover endpoints) - Better organization (domain-specific modules) - Uses generated OpenAPI types automatically
This commit is contained in:
parent
6d0f125536
commit
a6fa6a8012
24 changed files with 529 additions and 255 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { Permission } from "../../auth-context";
|
||||
import { api } from "../../api";
|
||||
import { adminApi } from "../../api";
|
||||
import { Header } from "../../components/Header";
|
||||
import { useRequireAuth } from "../../hooks/useRequireAuth";
|
||||
import { components } from "../../generated/api";
|
||||
|
|
@ -41,7 +41,7 @@ export default function AdminInvitesPage() {
|
|||
|
||||
const fetchUsers = useCallback(async () => {
|
||||
try {
|
||||
const data = await api.get<UserOption[]>("/api/admin/users");
|
||||
const data = await adminApi.getUsers();
|
||||
setUsers(data);
|
||||
} catch (err) {
|
||||
console.error("Failed to fetch users:", err);
|
||||
|
|
@ -51,11 +51,7 @@ export default function AdminInvitesPage() {
|
|||
const fetchInvites = useCallback(async (page: number, status: string) => {
|
||||
setError(null);
|
||||
try {
|
||||
let url = `/api/admin/invites?page=${page}&per_page=10`;
|
||||
if (status) {
|
||||
url += `&status=${status}`;
|
||||
}
|
||||
const data = await api.get<PaginatedInvites>(url);
|
||||
const data = await adminApi.getInvites(page, 10, status || undefined);
|
||||
setData(data);
|
||||
} catch (err) {
|
||||
setData(null);
|
||||
|
|
@ -80,7 +76,7 @@ export default function AdminInvitesPage() {
|
|||
setCreateError(null);
|
||||
|
||||
try {
|
||||
await api.post("/api/admin/invites", {
|
||||
await adminApi.createInvite({
|
||||
godfather_id: parseInt(newGodfatherId),
|
||||
});
|
||||
setNewGodfatherId("");
|
||||
|
|
@ -95,7 +91,7 @@ export default function AdminInvitesPage() {
|
|||
|
||||
const handleRevoke = async (inviteId: number) => {
|
||||
try {
|
||||
await api.post(`/api/admin/invites/${inviteId}/revoke`);
|
||||
await adminApi.revokeInvite(inviteId);
|
||||
setError(null);
|
||||
fetchInvites(page, statusFilter);
|
||||
} catch (err) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue