mirror of
https://github.com/arkorty/B.Tech-Project-III.git
synced 2026-04-19 20:51:49 +00:00
init
This commit is contained in:
19
negot8/dashboard/lib/api.ts
Normal file
19
negot8/dashboard/lib/api.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// Thin API client for the negoT8 FastAPI backend
|
||||
import type { Negotiation, Stats } from "./types";
|
||||
|
||||
const BASE = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
||||
|
||||
async function get<T>(path: string): Promise<T> {
|
||||
const res = await fetch(`${BASE}${path}`, { cache: "no-store" });
|
||||
if (!res.ok) throw new Error(`GET ${path} → ${res.status}`);
|
||||
return res.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export const api = {
|
||||
stats: () => get<Stats>("/api/stats"),
|
||||
negotiations: () =>
|
||||
get<{ negotiations: Negotiation[]; total: number }>("/api/negotiations"),
|
||||
negotiation: (id: string) => get<Negotiation>(`/api/negotiations/${id}`),
|
||||
analytics: (id: string) =>
|
||||
get<Negotiation["analytics"]>(`/api/negotiations/${id}/analytics`),
|
||||
};
|
||||
Reference in New Issue
Block a user