Selaa lähdekoodia

训练语料(查询意图类型详细信息接口)

liangxunge 2 kuukautta sitten
vanhempi
commit
c656fed0a9
3 muutettua tiedostoa jossa 35 lisäystä ja 5 poistoa
  1. 11 5
      api/controllers/console/intention.py
  2. 16 0
      api/fields/intention_fields.py
  3. 8 0
      api/models/intention.py

+ 11 - 5
api/controllers/console/intention.py

@@ -13,7 +13,7 @@ from fields.intention_fields import (
     intention_keyword_detail_fields,
     intention_keyword_fields,
     intention_page_fields,
-    intention_type_fields,
+    intention_type_detail_fields, intention_type_page_fields,
 )
 from libs.login import login_required
 from services.intention_service import (
@@ -110,7 +110,7 @@ class IntentionTypeListApi(Resource):
         limit = request.args.get("limit", default=20, type=int)
         search = request.args.get("search", default=None, type=str)
         intention_types, total = IntentionTypeService.get_intention_types(page, limit, search)
-        data = marshal(intention_types, intention_type_fields)
+        data = marshal(intention_types, intention_type_page_fields)
         response = {"data": data, "has_more": len(intention_types) == limit, "limit": limit,
                     "total": total, "page": page}
         return response, 200
@@ -128,13 +128,20 @@ class IntentionTypeListApi(Resource):
         )
         args = parser.parse_args()
         intention_type = IntentionTypeService.save_intention_type(args)
-        response = marshal(intention_type, intention_type_fields)
+        response = marshal(intention_type, intention_type_detail_fields)
         return response, 200
 
 class IntentionTypeApi(Resource):
     @setup_required
     @login_required
     @account_initialization_required
+    def get(self, intention_type_id):
+        intention_type = IntentionTypeService.get_intention_type(intention_type_id)
+        return marshal(intention_type, intention_type_detail_fields)
+
+    @setup_required
+    @login_required
+    @account_initialization_required
     def patch(self, intention_type_id):
         parser = reqparse.RequestParser()
         parser.add_argument(
@@ -145,8 +152,7 @@ class IntentionTypeApi(Resource):
         )
         args = parser.parse_args()
         intention_type = IntentionTypeService.update_intention_type(intention_type_id, args)
-        response = {"id": intention_type.id, "name": intention_type.name}
-        return response, 200
+        return marshal(intention_type, intention_type_detail_fields), 200
 
     @setup_required
     @login_required

+ 16 - 0
api/fields/intention_fields.py

@@ -2,6 +2,11 @@ from flask_restful import fields  # type: ignore
 
 from libs.helper import TimestampField
 
+intention_base_fields = {
+    "id": fields.String,
+    "name": fields.String,
+}
+
 intention_fields = {
     "id": fields.String,
     "name": fields.String,
@@ -12,9 +17,20 @@ intention_fields = {
 intention_type_fields = {
     "id": fields.String,
     "name": fields.String,
+}
+
+intention_type_page_fields = {
+    "id": fields.String,
+    "name": fields.String,
     "intention_count": fields.Integer,
 }
 
+intention_type_detail_fields = {
+    "id": fields.String,
+    "name": fields.String,
+    "intentions": fields.List(fields.Nested(intention_base_fields)),
+}
+
 intention_keyword_fields = {
     "id": fields.String,
     "name": fields.String,

+ 8 - 0
api/models/intention.py

@@ -25,6 +25,14 @@ class IntentionType(db.Model):
             .scalar()
         )
 
+    @property
+    def intentions(self):
+        return (
+            db.session.query(Intention)
+            .filter(Intention.type_id == self.id)
+            .all()
+        )
+
 class Intention(db.Model):
     __tablename__ = "intentions"
     __table_args__ = (