فهرست منبع

关注和取消关注接口

zhangqian 2 سال پیش
والد
کامیت
7f91ff9dfa
12فایلهای تغییر یافته به همراه262 افزوده شده و 22 حذف شده
  1. 8 0
      constvar/const.go
  2. 30 5
      controllers/audio.go
  3. 69 4
      docs/docs.go
  4. 69 4
      docs/swagger.json
  5. 43 4
      docs/swagger.yaml
  6. 1 0
      models/audio.go
  7. 2 3
      models/audio_text.go
  8. 4 0
      request/audio.go
  9. 7 0
      response/audio.go
  10. 1 0
      router/router.go
  11. 24 0
      service/audio.go
  12. 4 2
      service/process.go

+ 8 - 0
constvar/const.go

@@ -17,3 +17,11 @@ const (
 	BoolTypeTrue  BoolType = 1 // true
 	BoolTypeFalse BoolType = 2 // false
 )
+
+func (slf BoolType) IsValid() bool {
+	return slf == BoolTypeTrue || slf == BoolTypeFalse
+}
+
+func (slf BoolType) Bool() bool {
+	return slf == BoolTypeTrue
+}

+ 30 - 5
controllers/audio.go

@@ -11,6 +11,7 @@ import (
 	"speechAnalysis/models"
 	"speechAnalysis/pkg/logx"
 	"speechAnalysis/request"
+	"speechAnalysis/response"
 	"speechAnalysis/service"
 	"speechAnalysis/utils/upload"
 	"strings"
@@ -97,7 +98,7 @@ func (slf AudioCtl) ParamsCheck(filename string) (err error) {
 // @Tags      音频
 // @Summary   音频分析检索
 // @Produce   application/json
-// @Param     object  query    request.GetAudioList true  "查询参数"
+// @Param     object  query    request.GetAudioList true  "参数"
 // @Success   200   {object}  util.ResponseList{data=[]models.Audio}  "成功"
 // @Router    /api-sa/v1/audio/list [get]
 func (slf AudioCtl) List(c *gin.Context) {
@@ -133,7 +134,7 @@ func (slf AudioCtl) List(c *gin.Context) {
 // @Tags      音频
 // @Summary   处理音频
 // @Produce   application/json
-// @Param     object  body request.ProcessAudio true  "音频信息"
+// @Param     object  body request.ProcessAudio true  "参数"
 // @Success   200 {object} util.Response "成功"
 // @Router    /api-sa/v1/audio/process [post]
 func (slf AudioCtl) Process(c *gin.Context) {
@@ -156,7 +157,7 @@ func (slf AudioCtl) Process(c *gin.Context) {
 // @Tags      音频
 // @Summary   批量处理音频
 // @Produce   application/json
-// @Param     object  body request.BatchProcessAudio true  "音频信息"
+// @Param     object  body request.BatchProcessAudio true  "参数"
 // @Success   200 {object} util.Response "成功"
 // @Router    /api-sa/v1/audio/batchProcess [post]
 func (slf AudioCtl) BatchProcess(c *gin.Context) {
@@ -192,7 +193,7 @@ func (slf AudioCtl) BatchProcess(c *gin.Context) {
 // @Tags      音频
 // @Summary   删除音频
 // @Produce   application/json
-// @Param     object  body request.ProcessAudio true  "音频信息"
+// @Param     object  body request.ProcessAudio true  "参数"
 // @Success   200 {object} util.Response "成功"
 // @Router    /api-sa/v1/audio/delete [post]
 func (slf AudioCtl) Delete(c *gin.Context) {
@@ -215,7 +216,7 @@ func (slf AudioCtl) Delete(c *gin.Context) {
 // @Tags      音频
 // @Summary   批量删除音频
 // @Produce   application/json
-// @Param     object  body request.BatchProcessAudio true  "音频信息"
+// @Param     object  body request.BatchProcessAudio true  "参数"
 // @Success   200 {object} util.Response "成功"
 // @Router    /api-sa/v1/audio/batchDelete [post]
 func (slf AudioCtl) BatchDelete(c *gin.Context) {
@@ -233,3 +234,27 @@ func (slf AudioCtl) BatchDelete(c *gin.Context) {
 
 	util.ResponseFormat(c, code.DeleteSuccess, "成功")
 }
+
+// Follow
+// @Tags      音频
+// @Summary   关注/取消关注
+// @Produce   application/json
+// @Param     object  body request.FollowReq true  "参数"
+// @Success   200 {object} util.Response{data=response.FollowResp} "成功"
+// @Router    /api-sa/v1/audio/follow [post]
+func (slf AudioCtl) Follow(c *gin.Context) {
+	var params request.ProcessAudio
+	if err := c.ShouldBind(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+
+	followStatus, err := service.Follow(params.ID)
+	if err != nil {
+		util.ResponseFormat(c, code.InternalError, err.Error())
+		return
+	}
+	resp := response.FollowResp{FollowStatus: followStatus}
+
+	util.ResponseFormat(c, code.UpdateSuccess, resp)
+}

+ 69 - 4
docs/docs.go

@@ -27,7 +27,7 @@ const docTemplate = `{
                 "summary": "批量删除音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -57,7 +57,7 @@ const docTemplate = `{
                 "summary": "批量处理音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -87,7 +87,7 @@ const docTemplate = `{
                 "summary": "删除音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -106,6 +106,48 @@ const docTemplate = `{
                 }
             }
         },
+        "/api-sa/v1/audio/follow": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "音频"
+                ],
+                "summary": "关注/取消关注",
+                "parameters": [
+                    {
+                        "description": "参数",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.FollowReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.FollowResp"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/api-sa/v1/audio/list": {
             "get": {
                 "produces": [
@@ -195,7 +237,7 @@ const docTemplate = `{
                 "summary": "处理音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -338,6 +380,10 @@ const docTemplate = `{
                 "occurrenceTime": {
                     "type": "string"
                 },
+                "score": {
+                    "description": "置信度",
+                    "type": "number"
+                },
                 "size": {
                     "description": "音频大小",
                     "type": "integer"
@@ -369,6 +415,17 @@ const docTemplate = `{
                 }
             }
         },
+        "request.FollowReq": {
+            "type": "object",
+            "required": [
+                "id"
+            ],
+            "properties": {
+                "id": {
+                    "type": "integer"
+                }
+            }
+        },
         "request.ProcessAudio": {
             "type": "object",
             "required": [
@@ -380,6 +437,14 @@ const docTemplate = `{
                 }
             }
         },
+        "response.FollowResp": {
+            "type": "object",
+            "properties": {
+                "followStatus": {
+                    "$ref": "#/definitions/constvar.BoolType"
+                }
+            }
+        },
         "util.Response": {
             "type": "object",
             "properties": {

+ 69 - 4
docs/swagger.json

@@ -15,7 +15,7 @@
                 "summary": "批量删除音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -45,7 +45,7 @@
                 "summary": "批量处理音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -75,7 +75,7 @@
                 "summary": "删除音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -94,6 +94,48 @@
                 }
             }
         },
+        "/api-sa/v1/audio/follow": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "音频"
+                ],
+                "summary": "关注/取消关注",
+                "parameters": [
+                    {
+                        "description": "参数",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.FollowReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "成功",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/util.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/response.FollowResp"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/api-sa/v1/audio/list": {
             "get": {
                 "produces": [
@@ -183,7 +225,7 @@
                 "summary": "处理音频",
                 "parameters": [
                     {
-                        "description": "音频信息",
+                        "description": "参数",
                         "name": "object",
                         "in": "body",
                         "required": true,
@@ -326,6 +368,10 @@
                 "occurrenceTime": {
                     "type": "string"
                 },
+                "score": {
+                    "description": "置信度",
+                    "type": "number"
+                },
                 "size": {
                     "description": "音频大小",
                     "type": "integer"
@@ -357,6 +403,17 @@
                 }
             }
         },
+        "request.FollowReq": {
+            "type": "object",
+            "required": [
+                "id"
+            ],
+            "properties": {
+                "id": {
+                    "type": "integer"
+                }
+            }
+        },
         "request.ProcessAudio": {
             "type": "object",
             "required": [
@@ -368,6 +425,14 @@
                 }
             }
         },
+        "response.FollowResp": {
+            "type": "object",
+            "properties": {
+                "followStatus": {
+                    "$ref": "#/definitions/constvar.BoolType"
+                }
+            }
+        },
         "util.Response": {
             "type": "object",
             "properties": {

+ 43 - 4
docs/swagger.yaml

@@ -65,6 +65,9 @@ definitions:
         type: string
       occurrenceTime:
         type: string
+      score:
+        description: 置信度
+        type: number
       size:
         description: 音频大小
         type: integer
@@ -86,6 +89,13 @@ definitions:
     required:
     - ids
     type: object
+  request.FollowReq:
+    properties:
+      id:
+        type: integer
+    required:
+    - id
+    type: object
   request.ProcessAudio:
     properties:
       id:
@@ -93,6 +103,11 @@ definitions:
     required:
     - id
     type: object
+  response.FollowResp:
+    properties:
+      followStatus:
+        $ref: '#/definitions/constvar.BoolType'
+    type: object
   util.Response:
     properties:
       code:
@@ -121,7 +136,7 @@ paths:
   /api-sa/v1/audio/batchDelete:
     post:
       parameters:
-      - description: 音频信息
+      - description: 参数
         in: body
         name: object
         required: true
@@ -140,7 +155,7 @@ paths:
   /api-sa/v1/audio/batchProcess:
     post:
       parameters:
-      - description: 音频信息
+      - description: 参数
         in: body
         name: object
         required: true
@@ -159,7 +174,7 @@ paths:
   /api-sa/v1/audio/delete:
     post:
       parameters:
-      - description: 音频信息
+      - description: 参数
         in: body
         name: object
         required: true
@@ -175,6 +190,30 @@ paths:
       summary: 删除音频
       tags:
       - 音频
+  /api-sa/v1/audio/follow:
+    post:
+      parameters:
+      - description: 参数
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.FollowReq'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 成功
+          schema:
+            allOf:
+            - $ref: '#/definitions/util.Response'
+            - properties:
+                data:
+                  $ref: '#/definitions/response.FollowResp'
+              type: object
+      summary: 关注/取消关注
+      tags:
+      - 音频
   /api-sa/v1/audio/list:
     get:
       parameters:
@@ -226,7 +265,7 @@ paths:
   /api-sa/v1/audio/process:
     post:
       parameters:
-      - description: 音频信息
+      - description: 参数
         in: body
         name: object
         required: true

+ 1 - 0
models/audio.go

@@ -23,6 +23,7 @@ type (
 		OccurrenceAt     time.Time            `json:"-"`
 		OccurrenceTime   string               `json:"occurrenceTime" gorm:"-"`
 		IsFollowed       constvar.BoolType    `gorm:"type:tinyint;not null;default:2;comment:是否关注"` //是否关注 1关注 2未关注
+		Score            float64              `json:"score"`                                        // 置信度
 	}
 
 	AudioSearch struct {

+ 2 - 3
models/audio_text.go

@@ -10,9 +10,8 @@ type (
 	// AudioText 音频文本
 	AudioText struct {
 		gorm.Model
-		AudioID   uint    `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id
-		AudioText string  `json:"audioText"`                                                      // 音频文本
-		Score     float64 `json:"score"`                                                          // 置信度
+		AudioID   uint   `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id
+		AudioText string `json:"audioText"`                                                      // 音频文本
 	}
 
 	AudioTextSearch struct {

+ 4 - 0
request/audio.go

@@ -16,3 +16,7 @@ type ProcessAudio struct {
 type BatchProcessAudio struct {
 	IDs []uint `json:"ids" binding:"required"`
 }
+
+type FollowReq struct {
+	ID uint `json:"id" binding:"required"`
+}

+ 7 - 0
response/audio.go

@@ -0,0 +1,7 @@
+package response
+
+import "speechAnalysis/constvar"
+
+type FollowResp struct {
+	FollowStatus constvar.BoolType `json:"followStatus"`
+}

+ 1 - 0
router/router.go

@@ -31,6 +31,7 @@ func NewRouter() *gin.Engine {
 		organizeAPI.POST("batchProcess", AudioCtl.BatchProcess) // 音频批量处理
 		organizeAPI.POST("delete", AudioCtl.Delete)             // 音频删除
 		organizeAPI.POST("batchDelete", AudioCtl.BatchDelete)   // 音频批量删除
+		organizeAPI.POST("follow", AudioCtl.Follow)             // 关注/取消关注
 	}
 
 	return r

+ 24 - 0
service/audio.go

@@ -3,6 +3,7 @@ package service
 import (
 	"errors"
 	"gorm.io/gorm"
+	"speechAnalysis/constvar"
 	"speechAnalysis/models"
 	"speechAnalysis/pkg/logx"
 )
@@ -37,3 +38,26 @@ func BatchDeleteAudio(audioIds []uint) (err error) {
 	}
 	return nil
 }
+
+func Follow(audioId uint) (followStatus constvar.BoolType, err error) {
+	if audioId == 0 {
+		return
+	}
+	audio, err := models.NewAudioSearch().SetID(audioId).First()
+	if err != nil {
+		return followStatus, errors.New("DB错误")
+	}
+	if audio.IsFollowed.Bool() {
+		followStatus = constvar.BoolTypeFalse
+	} else {
+		followStatus = constvar.BoolTypeTrue
+	}
+	err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{
+		"is_followed": followStatus,
+	})
+	if err != nil {
+		logx.Errorf("follow audio err: %v", err)
+		return followStatus, errors.New("DB错误")
+	}
+	return followStatus, nil
+}

+ 4 - 2
service/process.go

@@ -111,14 +111,16 @@ func Process(audioId uint) (err error) {
 		}
 		logx.Infof("AnalysisAudio result: %v", resp)
 		err = models.WithTransaction(func(db *gorm.DB) error {
-			err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{"audio_status": constvar.AudioStatusFinish})
+			err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{
+				"audio_status": constvar.AudioStatusFinish,
+				"score":        resp.Score,
+			})
 			if err != nil {
 				return err
 			}
 			err = models.NewAudioTextSearch().Save(&models.AudioText{
 				AudioID:   audio.ID,
 				AudioText: resp.Result,
-				Score:     resp.Score,
 			})
 			return err
 		})