refactor(data): split models into separate dto and schema modules
Reorganize the data layer by separating DTOs (Data Transfer Objects) from Zod validation schemas into distinct directory structures. Previously, all model types were imported from a single `@/data/models` barrel file, mixing request/response classes with validation schemas. Changes: - Update API files (auth, chat, metrics, user) to import DTOs from specific paths under `@/data/dto/*` instead of the models barrel - Move user schema to `@/data/schemas/user/user` for type-only imports - Create dedicated Zod schema files under `@/data/schemas/*` for auth and chat domain models (e.g., AppleLoginRequestSchema, SendMessageRequestSchema, SyncMessageSchema, SttDataSchema) - Improve discoverability and tree-shaking by co-locating schemas with their respective domain areas This is a non-functional refactor that lays the groundwork for clearer separation between transport-layer types and runtime validation.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 图片上传响应 DTO
|
||||
*/
|
||||
import {
|
||||
ImageUploadResponseSchema,
|
||||
type ImageUploadResponseInput,
|
||||
type ImageUploadResponseData,
|
||||
} from "@/data/schemas/chat/image_upload_response";
|
||||
|
||||
export class ImageUploadResponse {
|
||||
declare readonly success: boolean;
|
||||
declare readonly imageId: string;
|
||||
declare readonly thumbUrl: string;
|
||||
declare readonly mediumUrl: string;
|
||||
declare readonly originalUrl: string;
|
||||
declare readonly width: number;
|
||||
declare readonly height: number;
|
||||
declare readonly bytes: number;
|
||||
|
||||
private constructor(input: ImageUploadResponseInput) {
|
||||
const data = ImageUploadResponseSchema.parse(input);
|
||||
Object.assign(this, data);
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
static from(input: ImageUploadResponseInput): ImageUploadResponse {
|
||||
return new ImageUploadResponse(input);
|
||||
}
|
||||
|
||||
static fromJson(json: unknown): ImageUploadResponse {
|
||||
return ImageUploadResponse.from(json as ImageUploadResponseInput);
|
||||
}
|
||||
|
||||
toJson(): ImageUploadResponseData {
|
||||
return ImageUploadResponseSchema.parse(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user