2026-05-31 15:42:52 +09:00
|
|
|
import http from './http'
|
2026-06-28 07:49:37 +09:00
|
|
|
import { demo, demoApi } from '@/demo'
|
2026-05-31 15:42:52 +09:00
|
|
|
|
|
|
|
|
// 백엔드 /api/account 엔드포인트와 매핑 (본인 데이터만)
|
2026-06-28 07:49:37 +09:00
|
|
|
const realApi = {
|
2026-05-31 15:42:52 +09:00
|
|
|
list({ year, month, type, category, walletId, keyword, tagId } = {}) {
|
|
|
|
|
return http.get('/account/entries', { params: { year, month, type, category, walletId, keyword, tagId } })
|
|
|
|
|
},
|
|
|
|
|
summary({ year, month } = {}) {
|
|
|
|
|
return http.get('/account/summary', { params: { year, month } })
|
|
|
|
|
},
|
|
|
|
|
stats({ unit, year, month } = {}) {
|
|
|
|
|
return http.get('/account/stats', { params: { unit, year, month } })
|
|
|
|
|
},
|
|
|
|
|
categoryStats({ type, year, month } = {}) {
|
|
|
|
|
return http.get('/account/category-stats', { params: { type, year, month } })
|
|
|
|
|
},
|
2026-06-22 22:38:22 +09:00
|
|
|
netWorthTrend({ months, weeks, unit } = {}) {
|
|
|
|
|
return http.get('/account/networth/trend', { params: { months, weeks, unit } })
|
2026-05-31 15:42:52 +09:00
|
|
|
},
|
|
|
|
|
create(payload) {
|
|
|
|
|
return http.post('/account/entries', payload)
|
|
|
|
|
},
|
|
|
|
|
update(id, payload) {
|
|
|
|
|
return http.put(`/account/entries/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
remove(id) {
|
|
|
|
|
return http.delete(`/account/entries/${id}`)
|
|
|
|
|
},
|
2026-06-27 14:50:10 +09:00
|
|
|
// 문자/푸시 텍스트 파싱(저장 안 함) → 추가 폼 자동채움
|
|
|
|
|
parseText({ title, text } = {}) {
|
|
|
|
|
return http.post('/account/entries/parse', { title, text })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 자주 쓰는 내역(빠른 등록 템플릿)
|
|
|
|
|
quickEntries() {
|
|
|
|
|
return http.get('/account/quick-entries')
|
|
|
|
|
},
|
|
|
|
|
createQuickEntry(payload) {
|
|
|
|
|
return http.post('/account/quick-entries', payload)
|
|
|
|
|
},
|
|
|
|
|
removeQuickEntry(id) {
|
|
|
|
|
return http.delete(`/account/quick-entries/${id}`)
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
|
|
|
|
|
// 계좌/카드 (사용자별)
|
|
|
|
|
wallets() {
|
|
|
|
|
return http.get('/account/wallets')
|
|
|
|
|
},
|
|
|
|
|
netWorth() {
|
|
|
|
|
return http.get('/account/networth')
|
|
|
|
|
},
|
|
|
|
|
repayment(payload) {
|
|
|
|
|
return http.post('/account/repayment', payload)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 정기/반복 거래
|
|
|
|
|
recurrings() {
|
|
|
|
|
return http.get('/account/recurrings')
|
|
|
|
|
},
|
|
|
|
|
createRecurring(payload) {
|
|
|
|
|
return http.post('/account/recurrings', payload)
|
|
|
|
|
},
|
|
|
|
|
updateRecurring(id, payload) {
|
|
|
|
|
return http.put(`/account/recurrings/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeRecurring(id) {
|
|
|
|
|
return http.delete(`/account/recurrings/${id}`)
|
|
|
|
|
},
|
|
|
|
|
runRecurrings() {
|
|
|
|
|
return http.post('/account/recurrings/run')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 예산 (사용자별)
|
|
|
|
|
budgets() {
|
|
|
|
|
return http.get('/account/budgets')
|
|
|
|
|
},
|
|
|
|
|
budgetStatus({ year, month }) {
|
|
|
|
|
return http.get('/account/budgets/status', { params: { year, month } })
|
|
|
|
|
},
|
|
|
|
|
budgetPeriod({ unit, year, month }) {
|
|
|
|
|
return http.get('/account/budgets/period', { params: { unit, year, month } })
|
|
|
|
|
},
|
2026-06-01 22:54:41 +09:00
|
|
|
expectedIncome({ year, month }) {
|
|
|
|
|
return http.get('/account/budgets/income', { params: { year, month } })
|
2026-06-01 22:37:56 +09:00
|
|
|
},
|
2026-06-01 22:54:41 +09:00
|
|
|
setExpectedIncome({ year, month, expectedIncome }) {
|
|
|
|
|
return http.put('/account/budgets/income', { expectedIncome }, { params: { year, month } })
|
2026-06-01 22:37:56 +09:00
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
createBudget(payload) {
|
|
|
|
|
return http.post('/account/budgets', payload)
|
|
|
|
|
},
|
|
|
|
|
updateBudget(id, payload) {
|
|
|
|
|
return http.put(`/account/budgets/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeBudget(id) {
|
|
|
|
|
return http.delete(`/account/budgets/${id}`)
|
|
|
|
|
},
|
|
|
|
|
createWallet(payload) {
|
|
|
|
|
return http.post('/account/wallets', payload)
|
|
|
|
|
},
|
|
|
|
|
updateWallet(id, payload) {
|
|
|
|
|
return http.put(`/account/wallets/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeWallet(id) {
|
|
|
|
|
return http.delete(`/account/wallets/${id}`)
|
|
|
|
|
},
|
2026-06-01 22:54:41 +09:00
|
|
|
reorderWallets(type, ids) {
|
|
|
|
|
return http.put('/account/wallets/reorder', { type, ids })
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
walletEntries(id) {
|
|
|
|
|
return http.get(`/account/wallets/${id}/entries`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 투자 포트폴리오 (C) — 종목/매매
|
|
|
|
|
investHoldings(walletId) {
|
|
|
|
|
return http.get('/account/invest/holdings', { params: { walletId } })
|
|
|
|
|
},
|
|
|
|
|
createHolding(payload) {
|
|
|
|
|
return http.post('/account/invest/holdings', payload)
|
|
|
|
|
},
|
|
|
|
|
updateHolding(id, payload) {
|
|
|
|
|
return http.put(`/account/invest/holdings/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeHolding(id) {
|
|
|
|
|
return http.delete(`/account/invest/holdings/${id}`)
|
|
|
|
|
},
|
2026-06-04 05:01:33 +09:00
|
|
|
refreshPrices(walletId) {
|
|
|
|
|
return http.post('/account/invest/holdings/refresh-prices', null, { params: { walletId } })
|
|
|
|
|
},
|
|
|
|
|
refreshAllPrices() {
|
|
|
|
|
return http.post('/account/invest/refresh-prices')
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
holdingTrades(holdingId) {
|
|
|
|
|
return http.get(`/account/invest/holdings/${holdingId}/trades`)
|
|
|
|
|
},
|
|
|
|
|
addTrade(holdingId, payload) {
|
|
|
|
|
return http.post(`/account/invest/holdings/${holdingId}/trades`, payload)
|
|
|
|
|
},
|
2026-06-06 16:42:47 +09:00
|
|
|
updateTrade(id, payload) {
|
|
|
|
|
return http.put(`/account/invest/trades/${id}`, payload)
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
removeTrade(id) {
|
|
|
|
|
return http.delete(`/account/invest/trades/${id}`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 분류(카테고리) — 사용자별
|
|
|
|
|
categories() {
|
|
|
|
|
return http.get('/account/categories')
|
|
|
|
|
},
|
|
|
|
|
createCategory(payload) {
|
|
|
|
|
return http.post('/account/categories', payload)
|
|
|
|
|
},
|
|
|
|
|
updateCategory(id, payload) {
|
|
|
|
|
return http.put(`/account/categories/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeCategory(id) {
|
|
|
|
|
return http.delete(`/account/categories/${id}`)
|
|
|
|
|
},
|
2026-06-01 22:37:56 +09:00
|
|
|
reorderCategories(type, ids) {
|
|
|
|
|
return http.put('/account/categories/reorder', { type, ids })
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
importCategories() {
|
|
|
|
|
return http.post('/account/categories/import')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 사용자별 가계부 태그
|
|
|
|
|
tags() {
|
|
|
|
|
return http.get('/account/tags')
|
|
|
|
|
},
|
|
|
|
|
createTag(payload) {
|
|
|
|
|
return http.post('/account/tags', payload)
|
|
|
|
|
},
|
|
|
|
|
updateTag(id, payload) {
|
|
|
|
|
return http.put(`/account/tags/${id}`, payload)
|
|
|
|
|
},
|
|
|
|
|
removeTag(id) {
|
|
|
|
|
return http.delete(`/account/tags/${id}`)
|
|
|
|
|
},
|
2026-06-04 05:01:33 +09:00
|
|
|
reorderTags(ids) {
|
|
|
|
|
return http.put('/account/tags/reorder', { ids })
|
|
|
|
|
},
|
2026-06-03 17:37:35 +09:00
|
|
|
|
2026-06-03 18:51:43 +09:00
|
|
|
// 카드 결제 알림 자동인식 (미확인 내역)
|
|
|
|
|
pendingCount() {
|
|
|
|
|
return http.get('/account/entries/pending/count')
|
|
|
|
|
},
|
|
|
|
|
confirmEntry(id, payload) {
|
|
|
|
|
return http.post(`/account/entries/${id}/confirm`, payload || {})
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-28 08:38:38 +09:00
|
|
|
// 데이터 복구(가져오기) — 전체 데이터 덮어쓰기
|
|
|
|
|
restore(payload) {
|
|
|
|
|
return http.post('/account/restore', payload)
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-03 17:37:35 +09:00
|
|
|
// 영수증 OCR (백엔드가 Google Vision 호출 → 전체 텍스트 반환)
|
|
|
|
|
ocrReceipt(blob) {
|
|
|
|
|
const fd = new FormData()
|
|
|
|
|
fd.append('image', blob, 'receipt.jpg')
|
|
|
|
|
return http.post('/account/ocr/receipt', fd, {
|
|
|
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
|
|
|
timeout: 30000,
|
|
|
|
|
})
|
|
|
|
|
},
|
2026-05-31 15:42:52 +09:00
|
|
|
}
|
2026-06-28 07:49:37 +09:00
|
|
|
|
|
|
|
|
// ===== 둘러보기(데모) 모드 =====
|
|
|
|
|
// demo.on 이면 읽기는 더미 데이터, 쓰기는 차단(안내 메시지)으로 응답한다.
|
|
|
|
|
const DEMO_READS = {
|
|
|
|
|
list: demoApi.list,
|
|
|
|
|
summary: demoApi.summary,
|
|
|
|
|
wallets: demoApi.wallets,
|
|
|
|
|
netWorth: demoApi.netWorth,
|
|
|
|
|
categories: demoApi.categories,
|
|
|
|
|
recurrings: demoApi.recurrings,
|
|
|
|
|
quickEntries: demoApi.quickEntries,
|
|
|
|
|
pendingCount: demoApi.pendingCount,
|
|
|
|
|
tags: demoApi.tags,
|
|
|
|
|
walletEntries: demoApi.walletEntries,
|
|
|
|
|
}
|
|
|
|
|
const DEMO_WRITES = new Set([
|
|
|
|
|
'create', 'update', 'remove', 'parseText', 'createQuickEntry', 'removeQuickEntry', 'repayment',
|
|
|
|
|
'createRecurring', 'updateRecurring', 'removeRecurring', 'runRecurrings',
|
|
|
|
|
'createWallet', 'updateWallet', 'removeWallet', 'reorderWallets',
|
|
|
|
|
'createCategory', 'updateCategory', 'removeCategory', 'reorderCategories', 'importCategories',
|
2026-06-28 08:38:38 +09:00
|
|
|
'createTag', 'updateTag', 'removeTag', 'reorderTags', 'confirmEntry', 'ocrReceipt', 'restore',
|
2026-06-28 07:49:37 +09:00
|
|
|
'createBudget', 'updateBudget', 'removeBudget', 'setExpectedIncome',
|
|
|
|
|
'createHolding', 'updateHolding', 'removeHolding', 'addTrade', 'updateTrade', 'removeTrade',
|
|
|
|
|
'refreshPrices', 'refreshAllPrices',
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
export const accountApi = new Proxy(realApi, {
|
|
|
|
|
get(target, prop) {
|
|
|
|
|
if (demo.on) {
|
|
|
|
|
if (DEMO_READS[prop]) return DEMO_READS[prop]
|
|
|
|
|
if (DEMO_WRITES.has(prop)) return () => demoApi.block()
|
|
|
|
|
}
|
|
|
|
|
return target[prop]
|
|
|
|
|
},
|
|
|
|
|
})
|