resource.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from typing import List, Optional
  4. from pydantic import Field
  5. from pydantic.main import BaseModel
  6. from schemas.base import ListMixin, Datetime2Str, DetailMixin
  7. class Operator(BaseModel):
  8. creator_id: int = Field(None, description="创建人ID,前端忽略,后端处理")
  9. creator_name: str = Field(None, description="创建人姓名,前端忽略,后端处理")
  10. editor_id: int = Field(None, description="最后编辑人ID,前端忽略,后端处理")
  11. editor_name: str = Field(None, description="最后编辑人姓名,前端忽略,后端处理")
  12. class ResourceBase(BaseModel):
  13. category_id: int = Field(None, alias="ctgid", description="资源分类ID")
  14. name: str = Field(None, description="资源名称")
  15. area: str = Field(None, description="省份")
  16. year: int = Field(None, description="年份")
  17. visit: int = Field(None, description="浏览量")
  18. collect: int = Field(None, description="收藏量")
  19. download: int = Field(None, description="下载量")
  20. attach_url: List[str] = Field(None, description="资源文件URL")
  21. class Config:
  22. orm_mode = True
  23. anystr_strip_whitespace = True
  24. class ResourceItem(ResourceBase):
  25. id: int = Field(..., description="资源ID")
  26. ctgid: Optional[int] = Field(None,
  27. alias="category_id",
  28. description="资源分类ID")
  29. rtype: Optional[str] = Field(None, description="作业资源类型")
  30. sid: Optional[int] = Field(None, alias="school_id", description="学校ID")
  31. sname: Optional[str] = Field(None, alias="school_name", description="学校名称")
  32. hot: Optional[bool] = Field(None, description="是否热点资源")
  33. isnew: Optional[bool] = Field(None, description="是否最新,客户端专用")
  34. created_at: Optional[Datetime2Str] = None
  35. class ResourceList(ListMixin):
  36. data: List[ResourceItem] = []
  37. class ResourceDetail(DetailMixin):
  38. data: Optional[ResourceItem] = None
  39. class NewResource(ResourceBase, Operator):
  40. ctype: str = Field(..., description="分类类型")
  41. school_id: Optional[int] = Field(None,
  42. alias="sid",
  43. description="学校ID,创建考试资源时传此参数")
  44. school_name: Optional[str] = Field(None, description="学校名称,后端处理,前端忽略")
  45. hot: Optional[bool] = Field(None, description="热点资源,创建考试资源时传此参数")
  46. class UpdateResource(BaseModel):
  47. ctype: str = Field(..., description="分类类型")
  48. category_id: Optional[int] = Field(None,
  49. alias="ctgid",
  50. description="资源分类ID")
  51. name: Optional[str] = Field(None, description="资源名称")
  52. area: Optional[str] = Field(None, description="省份")
  53. year: Optional[int] = Field(None, description="年份")
  54. visit: Optional[int] = Field(None, description="浏览量")
  55. collect: Optional[int] = Field(None, description="收藏量")
  56. download: Optional[int] = Field(None, description="下载量")
  57. attach_url: Optional[List[str]] = Field(None, description="资源文件URL")
  58. editor_id: int = Field(None, description="最后编辑人ID,后端处理,前端忽略")
  59. editor_name: str = Field(None, description="最后编辑人姓名,后端处理,前端忽略")
  60. rtype: Optional[str] = Field(None, description="作业资源类型,创建作业资源时传此参数")
  61. school_id: Optional[int] = Field(None,
  62. alias="sid",
  63. description="学校ID,创建考试资源时传此参数")
  64. school_name: Optional[str] = Field(None, description="学校名称,后端处理,前端忽略")
  65. hot: Optional[bool] = Field(None, description="热点资源,创建考试资源时传此参数")
  66. class Config:
  67. anystr_strip_whitespace = True