random.schema.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { z } from '@hono/zod-openapi';
  2. import { GoodsSchema } from '@/server/modules/goods/goods.schema';
  3. // 随机商品列表查询参数Schema
  4. export const RandomGoodsQuerySchema = z.object({
  5. limit: z.coerce.number().int().positive().min(1).max(50).default(10).openapi({
  6. description: '返回商品数量限制',
  7. example: 10
  8. }),
  9. categoryId: z.coerce.number().int().positive().optional().openapi({
  10. description: '指定商品分类ID',
  11. example: 1
  12. }),
  13. includeImages: z.coerce.boolean().default(true).openapi({
  14. description: '是否包含商品图片',
  15. example: true
  16. })
  17. });
  18. // 随机商品列表响应Schema
  19. export const RandomGoodsResponseSchema = z.object({
  20. data: z.array(GoodsSchema).openapi({
  21. description: '随机商品列表',
  22. example: [{
  23. id: 1,
  24. name: 'iPhone 15',
  25. price: 5999.99,
  26. costPrice: 4999.99,
  27. salesNum: 100,
  28. clickNum: 1000,
  29. categoryId1: 1,
  30. categoryId2: 2,
  31. categoryId3: 3,
  32. goodsType: 1,
  33. supplierId: 1,
  34. imageFileId: 1,
  35. detail: null,
  36. instructions: '高品质智能手机',
  37. sort: 0,
  38. state: 1,
  39. stock: 100,
  40. spuId: 0,
  41. spuName: null,
  42. lowestBuy: 1,
  43. createdAt: new Date('2024-01-01T12:00:00Z'),
  44. updatedAt: new Date('2024-01-01T12:00:00Z'),
  45. createdBy: 1,
  46. updatedBy: 1
  47. }]
  48. }),
  49. total: z.number().int().nonnegative().openapi({
  50. description: '符合条件的商品总数',
  51. example: 100
  52. })
  53. });
  54. // 类型定义
  55. export type RandomGoodsQuery = z.infer<typeof RandomGoodsQuerySchema>;
  56. export type RandomGoodsResponse = z.infer<typeof RandomGoodsResponseSchema>;