feat: 个人记账与预算管理系统 MVP 初始版本
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 账户服务 - Accounts API Service
|
||||
* 功能:封装账户相关的 API 调用,提供账户 CRUD 操作
|
||||
* API 依赖:
|
||||
* - GET /api/accounts - 获取账户列表
|
||||
* - GET /api/accounts/:id - 获取单个账户
|
||||
* - POST /api/accounts - 创建账户
|
||||
* - PUT /api/accounts/:id - 更新账户
|
||||
* - DELETE /api/accounts/:id - 删除账户
|
||||
*/
|
||||
import { apiClient } from './apiClient';
|
||||
import type { Account } from '../types';
|
||||
|
||||
// Mock 用户 ID - 后续应从认证上下文动态获取
|
||||
const USER_ID = 6;
|
||||
|
||||
export const accountsApi = {
|
||||
// API: GET /api/accounts - 获取当前用户的所有账户
|
||||
async getAccounts(): Promise<Account[]> {
|
||||
const response = await apiClient.get<Account[]>('/accounts', { userId: USER_ID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: GET /api/accounts/:id - 获取指定账户详情
|
||||
async getAccount(id: number): Promise<Account> {
|
||||
const response = await apiClient.get<Account>(`/accounts/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: POST /api/accounts - 创建新账户,自动关联当前用户
|
||||
async createAccount(data: Omit<Account, 'id' | 'createdAt' | 'updatedAt'>): Promise<Account> {
|
||||
const response = await apiClient.post<Account>('/accounts', { ...data, userId: USER_ID });
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: PUT /api/accounts/:id - 更新账户信息,禁止修改 userId 和时间字段
|
||||
async updateAccount(id: number, data: Partial<Omit<Account, 'id' | 'userId' | 'createdAt' | 'updatedAt'>>): Promise<Account> {
|
||||
const response = await apiClient.put<Account>(`/accounts/${id}`, data);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
// API: DELETE /api/accounts/:id - 删除指定账户
|
||||
async deleteAccount(id: number): Promise<void> {
|
||||
const response = await apiClient.delete<void>(`/accounts/${id}`);
|
||||
return response.data;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user