problem.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. from django.utils.translation import gettext_lazy as _
  2. from drf_spectacular.types import OpenApiTypes
  3. from drf_spectacular.utils import OpenApiParameter
  4. from rest_framework import serializers
  5. from common.mixins.api_mixin import APIMixin
  6. from common.result import DefaultResultSerializer
  7. from knowledge.serializers.problem import BatchAssociation, ProblemEditSerializer
  8. class ProblemReadAPI(APIMixin):
  9. @staticmethod
  10. def get_parameters():
  11. return [
  12. OpenApiParameter(
  13. name="workspace_id",
  14. description="工作空间id",
  15. type=OpenApiTypes.STR,
  16. location='path',
  17. required=True,
  18. ),
  19. OpenApiParameter(
  20. name="knowledge_id",
  21. description="知识库id",
  22. type=OpenApiTypes.STR,
  23. location='path',
  24. required=True,
  25. ),
  26. ]
  27. @staticmethod
  28. def get_response():
  29. return DefaultResultSerializer
  30. class ProblemBatchCreateAPI(ProblemReadAPI):
  31. @staticmethod
  32. def get_request():
  33. return serializers.ListField(required=True, label=_('problem list'),
  34. child=serializers.UUIDField(required=True, label=_('problem')))
  35. class BatchAssociationAPI(ProblemReadAPI):
  36. @staticmethod
  37. def get_request():
  38. return BatchAssociation
  39. class BatchDeleteAPI(ProblemReadAPI):
  40. @staticmethod
  41. def get_request():
  42. return serializers.ListField(required=True, label=_('problem list'),
  43. child=serializers.UUIDField(required=True, label=_('problem')))
  44. class ProblemPageAPI(APIMixin):
  45. @staticmethod
  46. def get_parameters():
  47. return [
  48. OpenApiParameter(
  49. name="workspace_id",
  50. description="工作空间id",
  51. type=OpenApiTypes.STR,
  52. location='path',
  53. required=True,
  54. ),
  55. OpenApiParameter(
  56. name="knowledge_id",
  57. description="知识库id",
  58. type=OpenApiTypes.STR,
  59. location='path',
  60. required=True,
  61. ),
  62. OpenApiParameter(
  63. name="current_page",
  64. description="当前页码",
  65. type=OpenApiTypes.INT,
  66. location='path',
  67. required=True,
  68. ),
  69. OpenApiParameter(
  70. name="page_size",
  71. description="每页条数",
  72. type=OpenApiTypes.INT,
  73. location='path',
  74. required=True,
  75. ),
  76. ]
  77. @staticmethod
  78. def get_response():
  79. return DefaultResultSerializer
  80. class ProblemDeleteAPI(APIMixin):
  81. @staticmethod
  82. def get_parameters():
  83. return [
  84. OpenApiParameter(
  85. name="workspace_id",
  86. description="工作空间id",
  87. type=OpenApiTypes.STR,
  88. location='path',
  89. required=True,
  90. ),
  91. OpenApiParameter(
  92. name="knowledge_id",
  93. description="知识库id",
  94. type=OpenApiTypes.STR,
  95. location='path',
  96. required=True,
  97. ),
  98. OpenApiParameter(
  99. name="problem_id",
  100. description="问题id",
  101. type=OpenApiTypes.STR,
  102. location='path',
  103. required=True,
  104. )
  105. ]
  106. @staticmethod
  107. def get_response():
  108. return DefaultResultSerializer
  109. class ProblemEditAPI(ProblemDeleteAPI):
  110. @staticmethod
  111. def get_request():
  112. return ProblemEditSerializer
  113. class ProblemParagraphAPI(ProblemDeleteAPI):
  114. pass