Преглед на файлове

📝 docs(commands): add API检查命令文档

- 创建检查API一致性的命令文档,说明如何验证前后端API定义匹配

♻️ refactor(client): 优化API客户端基础路径配置

- 移除所有客户端基础路径中的/api/v1前缀,统一使用根路径
- 调整导入格式,优化代码可读性
- 删除未使用的模板相关类型定义,减少冗余代码
yourname преди 5 месеца
родител
ревизия
9c160842d5
променени са 2 файла, в които са добавени 21 реда и са изтрити 21 реда
  1. 7 0
      .roo/commands/check-api-客户端API与服务端路由对应检查.md
  2. 14 21
      src/client/api.ts

+ 7 - 0
.roo/commands/check-api-客户端API与服务端路由对应检查.md

@@ -0,0 +1,7 @@
+---
+description: "检查客户端API与服务端路由注册是否对应"
+---
+
+按通用curd开发规范进行路由注册检查
+检查 src/client/api.ts、 mini/src/api.ts与src/server/api.ts是否对应
+没对应时修改客户端api定义以跟src/server/api.ts对齐

+ 14 - 21
src/client/api.ts

@@ -1,47 +1,40 @@
-import { hc } from 'hono/client';
-import type { AuthRoutes, UserRoutes, RoleRoutes, FileRoutes, MembershipPlanRoutes, PaymentRoutes } from '@/server/api';
+import { hc } from 'hono/client'
+import type {
+  AuthRoutes, UserRoutes, RoleRoutes,
+  FileRoutes, MembershipPlanRoutes, PaymentRoutes
+} from '@/server/api';
 import { axiosFetch } from './utils/axios-fetch';
 
-// 管理后台客户端
-export const authClient = hc<AuthRoutes>('/api/v1', {
+export const authClient = hc<AuthRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1.auth;
 
-export const userClient = hc<UserRoutes>('/api/v1', {
+export const userClient = hc<UserRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1.users;
 
-export const roleClient = hc<RoleRoutes>('/api/v1', {
+export const roleClient = hc<RoleRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1.roles;
 
-export const fileClient = hc<FileRoutes>('/api/v1', {
+export const fileClient = hc<FileRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1.files;
 
-export const membershipPlanClient = hc<MembershipPlanRoutes>('/api/v1', {
+export const membershipPlanClient = hc<MembershipPlanRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1['membership-plans'];
 
-export const paymentClient = hc<PaymentRoutes>('/api/v1', {
+export const paymentClient = hc<PaymentRoutes>('/', {
   fetch: axiosFetch,
 }).api.v1.payments;
 
 // 模板管理客户端(需要认证)
-export const templateClient = hc<any>('/api/v1', {
+export const templateClient = hc<any>('/', {
   fetch: axiosFetch,
 }).api.v1.templates;
 
 // 公共模板客户端(无需认证)
-export const publicTemplateClient = hc<any>('/api/v1/public', {
+export const publicTemplateClient = hc<any>('/', {
   fetch: axiosFetch,
-}).templates;
-
-// 类型定义
-import type { InferRequestType, InferResponseType } from 'hono/client';
-
-// 模板相关类型
-export type TemplateResponse = InferResponseType<typeof publicTemplateClient.$get, 200>['data'][0];
-export type TemplateListResponse = InferResponseType<typeof publicTemplateClient.$get, 200>;
-export type TemplatePreviewResponse = InferResponseType<typeof publicTemplateClient[':id']['preview']['$get'], 200>;
-export type TemplateDownloadResponse = InferResponseType<typeof publicTemplateClient[':id']['download']['$post'], 200>;
+}).templates;