feat: add watchlist dashboard workflow

This commit is contained in:
2026-06-23 10:00:09 +08:00
parent fcc68c9eb8
commit c2604c65c1
2 changed files with 246 additions and 7 deletions

View File

@@ -44,6 +44,22 @@ export type MarketOverview = {
highest_supply_risk_area: AreaScoreSummary | null;
};
export type WatchlistItem = {
watchlist_item_id: number;
neighborhood_id: string | null;
area_id: string | null;
target_price_psm: number | null;
status: string;
notes: string;
};
export type CreateWatchlistItem = {
area_id?: string;
neighborhood_id?: string;
target_price_psm?: number;
notes?: string;
};
const API_BASE_URL =
process.env.NEXT_PUBLIC_API_BASE_URL?.replace(/\/$/, "") ?? "http://127.0.0.1:8080";
@@ -55,8 +71,33 @@ export async function fetchAreaScores(month: string): Promise<AreaScore[]> {
return fetchJson(`/api/v1/areas/scores?month=${encodeURIComponent(month)}`);
}
async function fetchJson<T>(path: string): Promise<T> {
const response = await fetch(`${API_BASE_URL}${path}`);
export async function fetchWatchlistItems(): Promise<WatchlistItem[]> {
return fetchJson("/api/v1/watchlist");
}
export async function createWatchlistItem(
payload: CreateWatchlistItem,
): Promise<WatchlistItem> {
return fetchJson("/api/v1/watchlist", {
method: "POST",
body: JSON.stringify(payload),
});
}
export async function archiveWatchlistItem(id: number): Promise<WatchlistItem> {
return fetchJson(`/api/v1/watchlist/${id}`, {
method: "DELETE",
});
}
async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> {
const response = await fetch(`${API_BASE_URL}${path}`, {
...init,
headers: {
"Content-Type": "application/json",
...init?.headers,
},
});
if (!response.ok) {
throw new Error(`API request failed with ${response.status}`);
}