All files / services/api/core types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92                                                                                                                                                                                       
/**
 * API 服务核心类型定义
 * 统一的响应格式、错误类型、分页类型等
 */
 
/**
 * API 错误详情
 */
export interface ApiErrorDetail {
  message: string;
  code?: string;
  details?: unknown;
}
 
/**
 * 统一的 API 响应格式
 */
export interface ApiResponse<T> {
  data: T | null;
  error: ApiErrorDetail | null;
  success: boolean;
}
 
/**
 * 分页参数
 */
export interface PaginationParams {
  page?: number;
  pageSize?: number;
}
 
/**
 * 分页响应
 */
export interface PaginatedResponse<T> {
  results: T[];
  count: number;
  page: number;
  pageSize: number;
  totalPages: number;
  next: string | null;
  previous: string | null;
}
 
/**
 * 列表响应(简化版)
 */
export interface ListResponse<T> {
  items: T[];
  total: number;
}
 
/**
 * 删除响应
 */
export interface DeleteResponse {
  message: string;
  success?: boolean;
}
 
/**
 * 切换状态响应(点赞、收藏等)
 */
export interface ToggleResponse {
  toggled: boolean;
  message: string;
  count?: number;
}
 
/**
 * ID 类型(支持 number 和 string/UUID)
 */
export type EntityId = number | string;
 
/**
 * 基础实体接口
 */
export interface BaseEntity {
  id: EntityId;
  createdAt?: string;
  updatedAt?: string;
}
 
/**
 * 搜索参数
 */
export interface SearchParams extends PaginationParams {
  query?: string;
  orderBy?: string;
  ascending?: boolean;
}