From be7a1df7cf42ef9386c7fe7ef3a51c9f6f64dc95 Mon Sep 17 00:00:00 2001
From: yinbangzhong <zhongbangyin@126.com>
Date: 星期二, 18 六月 2024 17:04:24 +0800
Subject: [PATCH] word update delete

---
 controllers/text.go |   64 ++++++++++++
 request/text.go     |    1 
 models/audio.go     |    4 
 docs/swagger.yaml   |   48 +++++++++
 docs/docs.go        |   73 ++++++++++++++
 docs/swagger.json   |   73 ++++++++++++++
 router/router.go    |    6 
 7 files changed, 262 insertions(+), 7 deletions(-)

diff --git a/controllers/text.go b/controllers/text.go
index 1363327..206f663 100644
--- a/controllers/text.go
+++ b/controllers/text.go
@@ -3,6 +3,7 @@
 import (
 	"errors"
 	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
 	"speechAnalysis/extend/code"
 	"speechAnalysis/extend/util"
 	"speechAnalysis/models"
@@ -45,6 +46,69 @@
 	util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛")
 }
 
+// UpdateText
+// @Tags      鏂囧瓧搴�
+// @Summary   淇敼鏂囧瓧
+// @Produce   application/json
+// @Param     object  body request.AddTextReq true  "鍙傛暟"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-sa/v1/text/update [post]
+func (slf TextCtl) UpdateText(c *gin.Context) {
+	var req request.AddTextReq
+	if err := c.BindJSON(&req); err != nil {
+		logx.Errorf("add text params err:%v", err)
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+
+	text := models.Word{
+		Model: gorm.Model{
+			ID: req.Id,
+		},
+		Content:          req.Content,
+		LocomotiveNumber: req.LocomotiveNumber,
+	}
+
+	if err := slf.paramsCheck(text); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+	if req.Id == 0 {
+		util.ResponseFormat(c, code.RequestParamError, errors.New("ID涓嶈兘涓虹┖"))
+		return
+	}
+
+	if err := models.NewWordSearch().Save(&text); err != nil {
+		util.ResponseFormat(c, code.SaveFail, "淇敼澶辫触锛岃妫�鏌ユ槸鍚﹂噸澶�")
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, "淇敼鎴愬姛")
+}
+
+// DeleteText
+// @Tags      鏂囧瓧搴�
+// @Summary   淇敼鏂囧瓧
+// @Produce   application/json
+// @Param    object  body request.AddTextReq true  "鍙傛暟"
+// @Success   200 {object} util.Response "鎴愬姛"
+// @Router    /api-sa/v1/text/delete [delete]
+func (slf TextCtl) DeleteText(c *gin.Context) {
+	var req request.AddTextReq
+	if err := c.BindJSON(&req); err != nil {
+		logx.Errorf("add text params err:%v", err)
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+
+	if err := models.NewWordSearch().SetID(req.Id).Delete(); err != nil {
+		util.ResponseFormat(c, code.SaveFail, "鍒犻櫎澶辫触锛岃妫�鏌ユ槸鍚﹂噸澶�")
+		return
+	}
+
+	util.ResponseFormat(c, code.Success, "鍒犻櫎鎴愬姛")
+}
+
 func (slf TextCtl) paramsCheck(text models.Word) (err error) {
 	if text.Content == "" || text.LocomotiveNumber == "" {
 		return errors.New("鍙傛暟缂哄け")
diff --git a/docs/docs.go b/docs/docs.go
index cad5c53..d60e36c 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -529,6 +529,36 @@
                 }
             }
         },
+        "/api-sa/v1/text/delete": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "鏂囧瓧搴�"
+                ],
+                "summary": "淇敼鏂囧瓧",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddTextReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-sa/v1/text/list": {
             "get": {
                 "produces": [
@@ -578,6 +608,36 @@
                                     }
                                 }
                             ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-sa/v1/text/update": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "鏂囧瓧搴�"
+                ],
+                "summary": "淇敼鏂囧瓧",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddTextReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
                         }
                     }
                 }
@@ -690,6 +750,10 @@
                         }
                     ]
                 },
+                "kilometerMarker": {
+                    "description": "鍏噷鏍�",
+                    "type": "string"
+                },
                 "locomotiveNumber": {
                     "description": "鏈鸿溅鍙�",
                     "type": "string"
@@ -701,6 +765,10 @@
                 "occurrenceTime": {
                     "type": "string"
                 },
+                "routeNumber": {
+                    "description": "浜よ矾鍙�",
+                    "type": "string"
+                },
                 "score": {
                     "description": "缃俊搴�",
                     "type": "number"
@@ -710,7 +778,7 @@
                     "type": "integer"
                 },
                 "station": {
-                    "description": "鍏噷鏍�",
+                    "description": "杞︾珯",
                     "type": "string"
                 },
                 "trainNumber": {
@@ -798,6 +866,9 @@
                     "description": "闊抽鍚嶇О",
                     "type": "string"
                 },
+                "id": {
+                    "type": "integer"
+                },
                 "locomotiveNumber": {
                     "description": "鏈鸿溅鍙�",
                     "type": "string"
diff --git a/docs/swagger.json b/docs/swagger.json
index 11b18d9..9f1dd40 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -518,6 +518,36 @@
                 }
             }
         },
+        "/api-sa/v1/text/delete": {
+            "delete": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "鏂囧瓧搴�"
+                ],
+                "summary": "淇敼鏂囧瓧",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddTextReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/api-sa/v1/text/list": {
             "get": {
                 "produces": [
@@ -567,6 +597,36 @@
                                     }
                                 }
                             ]
+                        }
+                    }
+                }
+            }
+        },
+        "/api-sa/v1/text/update": {
+            "post": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "鏂囧瓧搴�"
+                ],
+                "summary": "淇敼鏂囧瓧",
+                "parameters": [
+                    {
+                        "description": "鍙傛暟",
+                        "name": "object",
+                        "in": "body",
+                        "required": true,
+                        "schema": {
+                            "$ref": "#/definitions/request.AddTextReq"
+                        }
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "$ref": "#/definitions/util.Response"
                         }
                     }
                 }
@@ -679,6 +739,10 @@
                         }
                     ]
                 },
+                "kilometerMarker": {
+                    "description": "鍏噷鏍�",
+                    "type": "string"
+                },
                 "locomotiveNumber": {
                     "description": "鏈鸿溅鍙�",
                     "type": "string"
@@ -690,6 +754,10 @@
                 "occurrenceTime": {
                     "type": "string"
                 },
+                "routeNumber": {
+                    "description": "浜よ矾鍙�",
+                    "type": "string"
+                },
                 "score": {
                     "description": "缃俊搴�",
                     "type": "number"
@@ -699,7 +767,7 @@
                     "type": "integer"
                 },
                 "station": {
-                    "description": "鍏噷鏍�",
+                    "description": "杞︾珯",
                     "type": "string"
                 },
                 "trainNumber": {
@@ -787,6 +855,9 @@
                     "description": "闊抽鍚嶇О",
                     "type": "string"
                 },
+                "id": {
+                    "type": "integer"
+                },
                 "locomotiveNumber": {
                     "description": "鏈鸿溅鍙�",
                     "type": "string"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 3d2642c..7bce983 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -74,6 +74,9 @@
         allOf:
         - $ref: '#/definitions/constvar.BoolType'
         description: 鏄惁鍏虫敞 1鍏虫敞 2鏈叧娉�
+      kilometerMarker:
+        description: 鍏噷鏍�
+        type: string
       locomotiveNumber:
         description: 鏈鸿溅鍙�
         type: string
@@ -82,6 +85,9 @@
         type: string
       occurrenceTime:
         type: string
+      routeNumber:
+        description: 浜よ矾鍙�
+        type: string
       score:
         description: 缃俊搴�
         type: number
@@ -89,7 +95,7 @@
         description: 闊抽澶у皬
         type: integer
       station:
-        description: 鍏噷鏍�
+        description: 杞︾珯
         type: string
       trainNumber:
         description: 杞︽
@@ -145,6 +151,8 @@
       content:
         description: 闊抽鍚嶇О
         type: string
+      id:
+        type: integer
       locomotiveNumber:
         description: 鏈鸿溅鍙�
         type: string
@@ -530,6 +538,25 @@
       summary: 鏂板鏂囧瓧
       tags:
       - 鏂囧瓧搴�
+  /api-sa/v1/text/delete:
+    delete:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.AddTextReq'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 淇敼鏂囧瓧
+      tags:
+      - 鏂囧瓧搴�
   /api-sa/v1/text/list:
     get:
       parameters:
@@ -562,4 +589,23 @@
       summary: 鏂囧瓧搴撳垪琛�
       tags:
       - 鏂囧瓧搴�
+  /api-sa/v1/text/update:
+    post:
+      parameters:
+      - description: 鍙傛暟
+        in: body
+        name: object
+        required: true
+        schema:
+          $ref: '#/definitions/request.AddTextReq'
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            $ref: '#/definitions/util.Response'
+      summary: 淇敼鏂囧瓧
+      tags:
+      - 鏂囧瓧搴�
 swagger: "2.0"
diff --git a/models/audio.go b/models/audio.go
index 6bbb698..4ef34a6 100644
--- a/models/audio.go
+++ b/models/audio.go
@@ -22,8 +22,8 @@
 		TrainNumber      string               `gorm:"index;type:varchar(255);not null;default:'';comment:杞︽" json:"trainNumber"`       // 杞︽
 		DriverNumber     string               `gorm:"index;type:varchar(255);not null;default:'';comment:鍙告満鍙�" json:"driverNumber"`     // 鍙告満鍙�
 		Station          string               `gorm:"index;type:varchar(255);not null;default:'';comment:杞︾珯鍙�" json:"station"`          // 杞︾珯
-		RouteNumber      string               `gorm:"index;type:varchar(255);not null;default:'';comment:浜よ矾鍙�" json:"station"`          // 浜よ矾鍙�
-		KilometerMarker  string               `gorm:"index;type:varchar(255);not null;default:'';comment:鍏噷鏍�" json:"station"`          // 鍏噷鏍�
+		RouteNumber      string               `gorm:"index;type:varchar(255);not null;default:'';comment:浜よ矾鍙�" json:"routeNumber"`      // 浜よ矾鍙�
+		KilometerMarker  string               `gorm:"index;type:varchar(255);not null;default:'';comment:鍏噷鏍�" json:"kilometerMarker"`  // 鍏噷鏍�
 		OccurrenceAt     time.Time            `json:"-"`
 		OccurrenceTime   string               `json:"occurrenceTime" gorm:"-"`
 		IsFollowed       constvar.BoolType    `gorm:"type:tinyint;not null;default:2;comment:鏄惁鍏虫敞"`                        //鏄惁鍏虫敞 1鍏虫敞 2鏈叧娉�
diff --git a/request/text.go b/request/text.go
index 6759eab..2702c3b 100644
--- a/request/text.go
+++ b/request/text.go
@@ -1,6 +1,7 @@
 package request
 
 type AddTextReq struct {
+	Id               uint   `gorm:"primaryKey;autoIncrement:true" json:"id"`
 	Content          string `gorm:"type:varchar(255);not null;default:'';comment:闊抽鍚嶇О" json:"content" binding:"required"`                // 闊抽鍚嶇О
 	LocomotiveNumber string `gorm:"index;type:varchar(255);not null;default:'';comment:鏈鸿溅鍙�" json:"locomotiveNumber"  binding:"required"` // 鏈鸿溅鍙�
 }
diff --git a/router/router.go b/router/router.go
index 421162d..4cc3f67 100644
--- a/router/router.go
+++ b/router/router.go
@@ -42,8 +42,10 @@
 	textCtl := new(controllers.TextCtl)
 	textApi := r.Group(urlPrefix + "/text")
 	{
-		textApi.POST("add", textCtl.AddText) // 娣诲姞鏂囧瓧
-		textApi.GET("list", textCtl.List)    // 鏂囧瓧鍒楄〃
+		textApi.POST("add", textCtl.AddText)         // 娣诲姞鏂囧瓧
+		textApi.POST("update", textCtl.UpdateText)   // 娣诲姞鏂囧瓧
+		textApi.GET("list", textCtl.List)            // 鏂囧瓧鍒楄〃
+		textApi.DELETE("delete", textCtl.DeleteText) // 鍒犻櫎鏂囧瓧
 
 	}
 

--
Gitblit v1.8.0