__init__.py 3.6 KB

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