协议数据模拟测试
This commit is contained in:
@@ -1,46 +1,41 @@
|
||||
import { ApiClient } from "../client/ApiClient";
|
||||
import type { Endpoint } from "../client/endpoints";
|
||||
import type { IGirlService } from "./IGirlService";
|
||||
import { HttpGirlService } from "./HttpGirlService";
|
||||
import { MockGirlService } from "./MockGirlService";
|
||||
import type { ApiResponse } from "../client/types";
|
||||
import proto from 'db://assets/Scripts/proto/proto.pb.js';
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
|
||||
export class GirlService {
|
||||
// 模拟开关
|
||||
const USE_MOCK = false;
|
||||
|
||||
export class GirlService implements IGirlService {
|
||||
private static _I: GirlService | null = null;
|
||||
public static get I(): GirlService {
|
||||
if (!GirlService._I) GirlService._I = new GirlService();
|
||||
return GirlService._I;
|
||||
}
|
||||
private constructor(private api = ApiClient.I) {}
|
||||
|
||||
private impl: IGirlService;
|
||||
private constructor() {
|
||||
this.impl = USE_MOCK ? new MockGirlService() : new HttpGirlService();
|
||||
}
|
||||
|
||||
/** 可运行期切换 */
|
||||
public switch(useMock: boolean) {
|
||||
this.impl = useMock ? new MockGirlService() : new HttpGirlService();
|
||||
}
|
||||
|
||||
// 每日推荐
|
||||
public async reqDailyRecommend(req: proto.cs.ICSDailyRecommendReq): Promise<ApiResponse<proto.cs.ICSDailyRecommendRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSDailyRecommendReq, proto.cs.ICSDailyRecommendRes> = {
|
||||
path: "api/logic/dailyRecommend",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
return this.impl.reqDailyRecommend(req);
|
||||
}
|
||||
|
||||
// 获取技师列表
|
||||
public async reqGetGirlList(req: proto.cs.ICSGetGirlListReq): Promise<ApiResponse<proto.cs.ICSGetGirlListRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSGetGirlListReq, proto.cs.ICSGetGirlListRes> = {
|
||||
path: "api/logic/getGirls",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
return this.impl.reqGetGirlList(req);
|
||||
}
|
||||
|
||||
// 获取技师详细信息
|
||||
public async reqGetGirlDetail(req: proto.cs.ICSGetGirlDetailReq): Promise<ApiResponse<proto.cs.ICSGetGirlDetailRes>> {
|
||||
let epData: Endpoint<proto.cs.ICSGetGirlDetailReq, proto.cs.ICSGetGirlDetailRes> = {
|
||||
path: "api/logic/girlDetail",
|
||||
method: "POST",
|
||||
codec: "json",
|
||||
needsAuth: true
|
||||
};
|
||||
return this.api.call(epData, req);
|
||||
}
|
||||
return this.impl.reqGetGirlDetail(req);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user