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";
|
||||
|
|
@ -25,7 +25,6 @@ import {
|
|||
const { slotDurationMinutes, maxAdvanceDays, minAdvanceDays } = constants.exchange;
|
||||
|
||||
type _AvailabilityDay = components["schemas"]["AvailabilityDay"];
|
||||
type AvailabilityResponse = components["schemas"]["AvailabilityResponse"];
|
||||
type TimeSlot = components["schemas"]["TimeSlot"];
|
||||
|
||||
// Generate time options for dropdowns (15-min intervals)
|
||||
|
|
@ -73,9 +72,7 @@ export default function AdminAvailabilityPage() {
|
|||
try {
|
||||
const fromDate = formatDate(dateRange[0]);
|
||||
const toDate = formatDate(dateRange[dateRange.length - 1]);
|
||||
const data = await api.get<AvailabilityResponse>(
|
||||
`/api/admin/availability?from=${fromDate}&to=${toDate}`
|
||||
);
|
||||
const data = await adminApi.getAvailability(fromDate, toDate);
|
||||
|
||||
const map = new Map<string, TimeSlot[]>();
|
||||
for (const day of data.days) {
|
||||
|
|
@ -140,7 +137,7 @@ export default function AdminAvailabilityPage() {
|
|||
end_time: s.end_time + ":00",
|
||||
}));
|
||||
|
||||
await api.put("/api/admin/availability", {
|
||||
await adminApi.updateAvailability({
|
||||
date: formatDate(selectedDate),
|
||||
slots,
|
||||
});
|
||||
|
|
@ -161,7 +158,7 @@ export default function AdminAvailabilityPage() {
|
|||
setError(null);
|
||||
|
||||
try {
|
||||
await api.put("/api/admin/availability", {
|
||||
await adminApi.updateAvailability({
|
||||
date: formatDate(selectedDate),
|
||||
slots: [],
|
||||
});
|
||||
|
|
@ -203,7 +200,7 @@ export default function AdminAvailabilityPage() {
|
|||
setError(null);
|
||||
|
||||
try {
|
||||
await api.post("/api/admin/availability/copy", {
|
||||
await adminApi.copyAvailability({
|
||||
source_date: copySource,
|
||||
target_dates: Array.from(copyTargets),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue