__init__.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from fastapi import APIRouter
  4. from schemas.resource import (PeriodList, SubjectList, WorkTypeList, CategoryList, CategoryDetail,
  5. ResourceList, ResourceDetail)
  6. from .category import (get_periods, get_subjects, get_work_types, get_categories, create_category,
  7. update_category, delete_category, import_category)
  8. from .resource import get_resources, create_resource, update_resource, delete_resource, get_resource
  9. router = APIRouter(prefix="/resource", tags=["资源管理"])
  10. # Category
  11. router.add_api_route("/periods",
  12. get_periods,
  13. response_model=PeriodList,
  14. response_model_exclude_none=True,
  15. summary="学段列表")
  16. router.add_api_route("/subjects",
  17. get_subjects,
  18. response_model=SubjectList,
  19. response_model_exclude_none=True,
  20. summary="学科列表")
  21. router.add_api_route("/worktypes",
  22. get_work_types,
  23. response_model=WorkTypeList,
  24. response_model_exclude_none=True,
  25. summary="作业资源分类列表")
  26. router.add_api_route("/categories",
  27. get_categories,
  28. methods=["get"],
  29. response_model=CategoryList,
  30. response_model_exclude_none=True,
  31. summary="资源分类列表")
  32. router.add_api_route("/categories",
  33. create_category,
  34. methods=["post"],
  35. response_model=CategoryDetail,
  36. response_model_exclude_none=True,
  37. summary="创建资源分类")
  38. router.add_api_route("/categories/{cid}",
  39. update_category,
  40. methods=["put"],
  41. response_model=CategoryDetail,
  42. response_model_exclude_none=True,
  43. summary="更新资源分类")
  44. router.add_api_route("/categories/{cid}",
  45. delete_category,
  46. methods=["delete"],
  47. response_model=CategoryDetail,
  48. response_model_exclude_none=True,
  49. summary="删除资源分类")
  50. router.add_api_route("/categories/{ctype}/bulk",
  51. import_category,
  52. methods=["post"],
  53. response_model=CategoryDetail,
  54. response_model_exclude_none=True,
  55. summary="批量导入分类")
  56. # Resource
  57. router.add_api_route("/items",
  58. get_resources,
  59. methods=["get"],
  60. response_model=ResourceList,
  61. response_model_exclude_none=True,
  62. summary="资源列表")
  63. router.add_api_route("/items",
  64. create_resource,
  65. methods=["post"],
  66. response_model=ResourceDetail,
  67. response_model_exclude_none=True,
  68. summary="创建资源")
  69. router.add_api_route("/items/{rid}",
  70. get_resource,
  71. methods=["get"],
  72. response_model=ResourceDetail,
  73. response_model_exclude_none=True,
  74. summary="资源详情")
  75. router.add_api_route("/items/{rid}",
  76. update_resource,
  77. methods=["put"],
  78. response_model=ResourceDetail,
  79. response_model_exclude_none=True,
  80. summary="更新资源")
  81. router.add_api_route("/items/{rid}",
  82. delete_resource,
  83. methods=["delete"],
  84. response_model=ResourceDetail,
  85. response_model_exclude_none=True,
  86. summary="删除资源")
  87. __all__ = [router]