주식 실 계좌 정보 가져오기 추가
This commit is contained in:
40
src/api.js
40
src/api.js
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user