feat: bootstrap auto virtual tryon admin frontend
This commit is contained in:
36
app/api/orders/[orderId]/assets/route.ts
Normal file
36
app/api/orders/[orderId]/assets/route.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { adaptAsset } from "@/lib/adapters/orders";
|
||||
import { backendRequest } from "@/lib/http/backend-client";
|
||||
import {
|
||||
jsonSuccess,
|
||||
parsePositiveIntegerParam,
|
||||
withErrorHandling,
|
||||
} from "@/lib/http/response";
|
||||
import type { AssetDto } from "@/lib/types/backend";
|
||||
import { businessEmptyState, READY_STATE } from "@/lib/types/view-models";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{
|
||||
orderId: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext) {
|
||||
return withErrorHandling(async () => {
|
||||
const { orderId: rawOrderId } = await context.params;
|
||||
const orderId = parsePositiveIntegerParam(rawOrderId, "orderId");
|
||||
const response = await backendRequest<AssetDto[]>(`/orders/${orderId}/assets`);
|
||||
const items = response.data.map(adaptAsset);
|
||||
|
||||
return jsonSuccess(
|
||||
{
|
||||
items,
|
||||
state: items.length
|
||||
? READY_STATE
|
||||
: businessEmptyState("暂无资产", "当前订单还没有生成可查看的资产列表。"),
|
||||
},
|
||||
{
|
||||
mode: "proxy",
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
54
app/api/orders/[orderId]/revisions/route.ts
Normal file
54
app/api/orders/[orderId]/revisions/route.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { adaptRevisionChain, adaptRevisionRegistration } from "@/lib/adapters/revisions";
|
||||
import { backendRequest } from "@/lib/http/backend-client";
|
||||
import {
|
||||
jsonSuccess,
|
||||
parseJsonBody,
|
||||
parsePositiveIntegerParam,
|
||||
withErrorHandling,
|
||||
} from "@/lib/http/response";
|
||||
import type {
|
||||
RegisterRevisionResponseDto,
|
||||
RevisionChainResponseDto,
|
||||
} from "@/lib/types/backend";
|
||||
import { parseRegisterRevisionPayload } from "@/lib/validation/revision";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{
|
||||
orderId: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext) {
|
||||
return withErrorHandling(async () => {
|
||||
const { orderId: rawOrderId } = await context.params;
|
||||
const orderId = parsePositiveIntegerParam(rawOrderId, "orderId");
|
||||
const response = await backendRequest<RevisionChainResponseDto>(
|
||||
`/orders/${orderId}/revisions`,
|
||||
);
|
||||
|
||||
return jsonSuccess(adaptRevisionChain(response.data), {
|
||||
mode: "proxy",
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function POST(request: Request, context: RouteContext) {
|
||||
return withErrorHandling(async () => {
|
||||
const { orderId: rawOrderId } = await context.params;
|
||||
const orderId = parsePositiveIntegerParam(rawOrderId, "orderId");
|
||||
const rawPayload = await parseJsonBody(request);
|
||||
const payload = parseRegisterRevisionPayload(rawPayload);
|
||||
const response = await backendRequest<RegisterRevisionResponseDto>(
|
||||
`/orders/${orderId}/revisions`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
},
|
||||
);
|
||||
|
||||
return jsonSuccess(adaptRevisionRegistration(response.data), {
|
||||
status: response.status,
|
||||
mode: "proxy",
|
||||
});
|
||||
});
|
||||
}
|
||||
32
app/api/orders/[orderId]/route.ts
Normal file
32
app/api/orders/[orderId]/route.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { adaptOrderDetail } from "@/lib/adapters/orders";
|
||||
import { backendRequest } from "@/lib/http/backend-client";
|
||||
import {
|
||||
jsonSuccess,
|
||||
parsePositiveIntegerParam,
|
||||
withErrorHandling,
|
||||
} from "@/lib/http/response";
|
||||
import type { AssetDto, OrderDetailResponseDto } from "@/lib/types/backend";
|
||||
|
||||
type RouteContext = {
|
||||
params: Promise<{
|
||||
orderId: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, context: RouteContext) {
|
||||
return withErrorHandling(async () => {
|
||||
const { orderId: rawOrderId } = await context.params;
|
||||
const orderId = parsePositiveIntegerParam(rawOrderId, "orderId");
|
||||
const [orderResponse, assetsResponse] = await Promise.all([
|
||||
backendRequest<OrderDetailResponseDto>(`/orders/${orderId}`),
|
||||
backendRequest<AssetDto[]>(`/orders/${orderId}/assets`),
|
||||
]);
|
||||
|
||||
return jsonSuccess(
|
||||
adaptOrderDetail(orderResponse.data, assetsResponse.data),
|
||||
{
|
||||
mode: "proxy",
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user