阶段六:完成生成契约迁移并永久关闭旁路
This commit is contained in:
1 parent
5675f60e52
commit
76f4e2e87d
117 files changed
+5833
-2204
No files matched your search
@@ -3,11 +3,11 @@ Card,
|
||||
CardAppendResponse,
|
||||
CardBatchResponse,
|
||||
MutationIDResponse,OperationResponse
|
||||
} from '../../../shared/api-contract/cards';
|
||||
} from './models';
|
||||
import { type RequestControlOptions } from '../../../shared/http/client';
|
||||
import { contractClient, runContractRequest } from '../../../shared/api-contract/client';
|
||||
import { contractClient, contractMultipartBody, runContractRequest } from '../../../shared/api-contract/client';
|
||||
import { collectionFrom } from '../../../shared/http/contract';
|
||||
export type * from '../../../shared/api-contract/cards';
|
||||
export type * from './models';
|
||||
// Cards
|
||||
// normalizeCard 归一化卡密数据。
|
||||
const normalizeCard = (item: any): Card => {
|
||||
@@ -24,9 +24,19 @@ const normalizeCard = (item: any): Card => {
|
||||
};
|
||||
|
||||
// cardPayload 卡密请求载荷,用于当前 API 处理流程。
|
||||
const cardPayload = (data: Partial<Card>): Record<string, unknown> => ({
|
||||
...data,
|
||||
const cardPayload = (data: Partial<Card>) => ({
|
||||
name: data.name,
|
||||
type: data.type,
|
||||
api_config: data.api_config ? JSON.stringify(data.api_config) : '',
|
||||
text_content: data.text_content,
|
||||
data_content: data.data_content,
|
||||
image_url: data.image_url,
|
||||
description: data.description,
|
||||
enabled: data.enabled,
|
||||
delay_seconds: data.delay_seconds,
|
||||
is_multi_spec: data.is_multi_spec,
|
||||
spec_name: data.spec_name,
|
||||
spec_value: data.spec_value,
|
||||
});
|
||||
|
||||
// getCards 读取卡密列表。
|
||||
@@ -40,12 +50,12 @@ export const getCards = async (options?: RequestControlOptions): Promise<Card[]>
|
||||
|
||||
// createCard 创建卡密组。
|
||||
export const createCard = async (data: Partial<Card>): Promise<MutationIDResponse> => {
|
||||
return runContractRequest(/* signal 控制卡券创建请求的取消和超时。 */ signal => contractClient.POST('/api/v1/cards', { body: cardPayload(data) as never, signal })) as unknown as Promise<MutationIDResponse>;
|
||||
return runContractRequest(/* signal 控制卡券创建请求的取消和超时。 */ signal => contractClient.POST('/api/v1/cards', { body: cardPayload(data), signal }));
|
||||
};
|
||||
|
||||
// updateCard 更新卡密组。
|
||||
export const updateCard = async (cardId: string | number, data: Partial<Card>): Promise<OperationResponse> => {
|
||||
return runContractRequest(/* signal 控制卡券更新请求的取消和超时。 */ signal => contractClient.PUT('/api/v1/cards/{card_id}', { params: { path: { card_id: String(cardId) } }, body: cardPayload(data) as never, signal }));
|
||||
return runContractRequest(/* signal 控制卡券更新请求的取消和超时。 */ signal => contractClient.PUT('/api/v1/cards/{card_id}', { params: { path: { card_id: String(cardId) } }, body: cardPayload(data), signal }));
|
||||
};
|
||||
|
||||
// deleteCard 删除卡密组。
|
||||
@@ -56,7 +66,7 @@ export const deleteCard = async (cardId: string | number): Promise<OperationResp
|
||||
// getCardDetails 读取卡密组详情。
|
||||
export const getCardDetails = async (cardId: string | number): Promise<Card> => {
|
||||
// card 卡密详情,用于当前 API 处理流程。
|
||||
const card = await runContractRequest(/* signal 控制卡券详情请求的取消和超时。 */ signal => contractClient.GET('/api/v1/cards/{card_id}/details', { params: { path: { card_id: String(cardId) } }, signal })) as unknown as Card;
|
||||
const card = await runContractRequest(/* signal 控制卡券详情请求的取消和超时。 */ signal => contractClient.GET('/api/v1/cards/{card_id}/details', { params: { path: { card_id: String(cardId) } }, signal }));
|
||||
return normalizeCard(card);
|
||||
};
|
||||
|
||||
@@ -70,10 +80,10 @@ export const batchCreateCards = async (file: File, options?: RequestControlOptio
|
||||
// 此处只收紧 TypeScript 响应契约。
|
||||
const body = new FormData();
|
||||
body.append('file', file);
|
||||
return runContractRequest(/* signal 控制卡券批量上传的取消和超时。 */ signal => contractClient.POST('/api/v1/cards/batch', { body: body as never, signal }), options) as Promise<CardBatchResponse>;
|
||||
return runContractRequest(/* signal 控制卡券批量上传的取消和超时。 */ signal => contractClient.POST('/api/v1/cards/batch', { body: contractMultipartBody(body), signal }), options);
|
||||
};
|
||||
|
||||
// 往 data 类型卡密组批量追加卡密号
|
||||
export const appendCardData = async (cardId: string | number, content: string, options?: RequestControlOptions): Promise<CardAppendResponse> => {
|
||||
return runContractRequest(/* signal 控制卡券追加数据请求的取消和超时。 */ signal => contractClient.POST('/api/v1/cards/{card_id}/append-data', { params: { path: { card_id: String(cardId) } }, body: { content } as never, signal }), options) as Promise<CardAppendResponse>;
|
||||
return runContractRequest(/* signal 控制卡券追加数据请求的取消和超时。 */ signal => contractClient.POST('/api/v1/cards/{card_id}/append-data', { params: { path: { card_id: String(cardId) } }, body: { content }, signal }), options);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect,test } from 'vitest';
|
||||
import type { Card } from '../../../shared/api-contract/cards';
|
||||
import type { Card } from './api';
|
||||
import { canSubmitAppend,filterCards,isCurrentCardRequest,previewAppendContent } from './batchState';
|
||||
|
||||
// cards 是卡密筛选测试使用的最小卡密组列表。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
import { act,renderHook } from '@testing-library/react';
|
||||
import { afterEach,beforeEach,describe,expect,test,vi } from 'vitest';
|
||||
import type { Card } from '../../../shared/api-contract/cards';
|
||||
import type { Card } from './api';
|
||||
import { useCardActions } from './cardActions';
|
||||
|
||||
// cardActionMocks 保存卡密动作 Hook 测试使用的 API 替身。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
import { act,renderHook,waitFor } from '@testing-library/react';
|
||||
import { beforeEach,describe,expect,test,vi } from 'vitest';
|
||||
import type { Card } from '../../../shared/api-contract/cards';
|
||||
import type { Card } from './api';
|
||||
import { appendCardData,batchCreateCards,getCards } from './api';
|
||||
import { useCardBatchActions,useCardsData } from './hooks';
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// models 保存本 feature adapter 输出的 UI 模型;这些模型不直接代表 HTTP DTO。
|
||||
/** 由当前 feature adapter 归一后的 Card UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface Card {
|
||||
/** 卡券组数值主键。 */
|
||||
id: number;
|
||||
/** 卡券组名称。 */
|
||||
name: string;
|
||||
/** 卡券组类型。 */
|
||||
type: 'api' | 'text' | 'data' | 'image';
|
||||
/** 卡券组说明。 */
|
||||
description?: string;
|
||||
/** 卡券组是否启用。 */
|
||||
enabled: boolean;
|
||||
// 文本类型
|
||||
text_content?: string;
|
||||
// 批量数据类型
|
||||
data_content?: string;
|
||||
// API 类型配置
|
||||
api_config?: {
|
||||
/** API 卡券请求地址。 */
|
||||
url: string;
|
||||
/** API 卡券请求方法。 */
|
||||
method: 'GET' | 'POST';
|
||||
/** API 请求超时时间。 */
|
||||
timeout?: number;
|
||||
/** API 请求头 JSON。 */
|
||||
headers?: string;
|
||||
/** API 请求参数 JSON。 */
|
||||
params?: string;
|
||||
};
|
||||
// 图片类型
|
||||
/** 图片卡券地址。 */
|
||||
image_url?: string;
|
||||
// 通用配置
|
||||
/** 卡券发送延迟秒数。 */
|
||||
delay_seconds?: number;
|
||||
// 多规格配置
|
||||
/** 是否支持多规格。 */
|
||||
is_multi_spec?: boolean;
|
||||
/** 规格名称。 */
|
||||
spec_name?: string;
|
||||
/** 规格值。 */
|
||||
spec_value?: string;
|
||||
}
|
||||
|
||||
/** 卡券批量创建接口的逐行结果。 */
|
||||
/** 由当前 feature adapter 归一后的 CardBatchResult UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface CardBatchResult {
|
||||
/** 表格中的原始行号。 */
|
||||
row_no: number;
|
||||
/** 当前行是否创建成功。 */
|
||||
success: boolean;
|
||||
/** 新建卡券组主键。 */
|
||||
id?: number;
|
||||
/** 卡券组名称。 */
|
||||
name: string;
|
||||
/** 卡券类型。 */
|
||||
type?: string;
|
||||
/** 当前行失败原因。 */
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/** 卡券批量创建接口的具名响应。 */
|
||||
/** 由当前 feature adapter 归一后的 CardBatchResponse UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface CardBatchResponse {
|
||||
/** 批量处理流程是否完成。 */
|
||||
success: boolean;
|
||||
/** 解析出的总行数。 */
|
||||
total: number;
|
||||
/** 创建成功行数。 */
|
||||
created: number;
|
||||
/** 创建失败行数。 */
|
||||
failed: number;
|
||||
/** 逐行处理结果。 */
|
||||
rows: CardBatchResult[];
|
||||
}
|
||||
|
||||
/** 卡券追加数据接口的具名响应。 */
|
||||
/** 由当前 feature adapter 归一后的 CardAppendResponse UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface CardAppendResponse {
|
||||
/** 追加操作是否完成。 */
|
||||
success: boolean;
|
||||
/** 实际追加数量。 */
|
||||
added: number;
|
||||
}
|
||||
|
||||
/** 简单资源创建接口的数值主键响应。 */
|
||||
/** 由当前 feature adapter 归一后的 MutationIDResponse UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface MutationIDResponse {
|
||||
/** 资源创建是否完成。 */
|
||||
success: boolean;
|
||||
/** 新资源数值主键。 */
|
||||
id: number;
|
||||
}
|
||||
|
||||
/** 简单变更接口的统一成功响应。 */
|
||||
/** 由当前 feature adapter 归一后的 OperationResponse UI 模型;不直接暴露 HTTP DTO。 */
|
||||
export interface OperationResponse {
|
||||
/** 操作是否完成。 */
|
||||
success: boolean;
|
||||
/** 可选的操作说明。 */
|
||||
message?: string;
|
||||
/** 操作完成后是否需要重新登录。 */
|
||||
requires_relogin?: boolean;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
import { cleanup,fireEvent,render,screen,waitFor } from '@testing-library/react';
|
||||
import { afterEach,beforeEach,describe,expect,test,vi } from 'vitest';
|
||||
import type { Card } from '../../../../shared/api-contract/cards';
|
||||
import type { Card } from '../api';
|
||||
|
||||
// cardListMocks 保存卡密页面测试使用的 Hook、API 和批量弹窗替身。
|
||||
const cardListMocks = vi.hoisted(/* cardListMockFactory 创建卡密页面共享替身。 */ () => ({
|
||||
|
||||
Reference in new issue
Block a user