주식 실 계좌 정보 가져오기 추가

This commit is contained in:
2026-02-26 00:17:41 +09:00
parent ba30de718f
commit 9380bf331f
3 changed files with 794 additions and 26 deletions

View File

@@ -8,12 +8,12 @@ const toApiUrl = (path) => {
const base = new URL(API_BASE, window.location.origin);
// Ensure base pathname ends with '/' if it's not the root or if likely intended as a directory
if (!base.pathname.endsWith('/')) {
base.pathname += '/';
base.pathname += '/';
}
// Remove leading slash from path to avoid double slashes when joining
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
return new URL(cleanPath, base).toString();
} catch (error) {
console.error("Invalid VITE_API_BASE configuration:", error);
@@ -57,6 +57,22 @@ export async function apiPost(path, body) {
return res.json();
}
export async function apiPut(path, body) {
const res = await fetch(toApiUrl(path), {
method: "PUT",
headers: {
"Accept": "application/json",
...(body ? { "Content-Type": "application/json" } : {}),
},
body: body ? JSON.stringify(body) : undefined,
});
if (!res.ok) {
const text = await res.text().catch(() => "");
throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`);
}
return res.json();
}
export function getLatest() {
return apiGet("/api/lotto/latest");
}
@@ -120,3 +136,21 @@ export function getTradeBalance() {
export function createTradeOrder(payload) {
return apiPost("/api/trade/order", payload);
}
// ── 포트폴리오 (수동 입력) API ──────────────────────────────────────────────
export function getPortfolio() {
return apiGet("/api/portfolio");
}
export function addPortfolio(item) {
return apiPost("/api/portfolio", item);
}
export function updatePortfolio(id, fields) {
return apiPut(`/api/portfolio/${id}`, fields);
}
export function deletePortfolio(id) {
return apiDelete(`/api/portfolio/${id}`);
}