Browse Source

fix :Go server :add interface find record by id

zzf 1 year ago
parent
commit
939c42159a

+ 23 - 2
AIT/api/record.go

@@ -53,8 +53,12 @@ func (f *RecordService) SaveRecord(c *gin.Context) {
 	message["msg_type"] = fileType
 	message["Sender"] = "server"
 	message["Recipient"] = "client"
+	//添加记录
+	var record models.Record
 	//文件格式限制
 	fileName := file.Filename
+	record.FileName = fileName
+
 	fileExtendName := common.CheckFile(fileName)
 	if len(fileExtendName) <= 0 {
 		response.Failed(errmsg.FileExtendNameError, c)
@@ -78,8 +82,7 @@ func (f *RecordService) SaveRecord(c *gin.Context) {
 
 	message["content"] = fileAbsolutePath
 	fileURL := fileLocation.AccessUrl + fileName
-	//添加记录
-	var record models.Record
+
 	record.FilePath = fileAbsolutePath
 	record.CreateTime = common.NowTime()
 
@@ -142,5 +145,23 @@ func (f *RecordService) RecordList(c *gin.Context) {
 	}
 	recordList, rows := f.GetRecordList(param)
 	response.SuccessPage(errmsg.FindSuccess, recordList, rows, c)
+}
 
+// GetRecordById
+// @Summary 记录详情查询
+// @Description 记录详情查询
+// @Tags 测试记录
+// @Param r path string true "测试记录Id"
+// @Accept json
+// @Produce json
+// @Success 200 {string} string "ok"
+// @Router /v1/record/:recordId/find [get]
+func (f *RecordService) GetRecordById(c *gin.Context) {
+	recordId := c.Param("recordId")
+	record, count := f.FindById(recordId)
+	if count > 0 {
+		response.Success(errmsg.FindSuccess, record, c)
+	} else {
+		response.Failed(errmsg.RecordNotFoundError, c)
+	}
 }

+ 32 - 0
AIT/docs/docs.go

@@ -20,6 +20,38 @@ const docTemplate = `{
     "host": "{{.Host}}",
     "basePath": "{{.BasePath}}",
     "paths": {
+        "/v1/record/:recordId/find": {
+            "get": {
+                "description": "记录详情查询",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "测试记录"
+                ],
+                "summary": "记录详情查询",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "测试记录Id",
+                        "name": "r",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
         "/v1/record/create": {
             "post": {
                 "security": [

+ 32 - 0
AIT/docs/swagger.json

@@ -11,6 +11,38 @@
         "version": "1.0"
     },
     "paths": {
+        "/v1/record/:recordId/find": {
+            "get": {
+                "description": "记录详情查询",
+                "consumes": [
+                    "application/json"
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "测试记录"
+                ],
+                "summary": "记录详情查询",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "测试记录Id",
+                        "name": "r",
+                        "in": "path",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "ok",
+                        "schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        },
         "/v1/record/create": {
             "post": {
                 "security": [

+ 21 - 0
AIT/docs/swagger.yaml

@@ -7,6 +7,27 @@ info:
   title: AIT-go AI测试
   version: "1.0"
 paths:
+  /v1/record/:recordId/find:
+    get:
+      consumes:
+      - application/json
+      description: 记录详情查询
+      parameters:
+      - description: 测试记录Id
+        in: path
+        name: r
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: ok
+          schema:
+            type: string
+      summary: 记录详情查询
+      tags:
+      - 测试记录
   /v1/record/create:
     post:
       consumes:

+ 1 - 0
AIT/exception/errmsg/errMsg.go

@@ -21,4 +21,5 @@ const (
 	SendMessageError          = "消息发送失败"
 	SocketCloseError          = "Socket关闭异常"
 	RecordSaveError           = "记录保存失败"
+	RecordNotFoundError       = "未找到记录"
 )

+ 1 - 0
AIT/initialize/router.go

@@ -41,6 +41,7 @@ func Router() {
 	record := v1.Group("/record")
 	record.POST("/create", api.GetRecord().SaveRecord)
 	record.GET("/find", api.GetRecord().RecordList)
+	record.GET("/:recordId/find", api.GetRecord().GetRecordById)
 	err := engine.Run(fmt.Sprintf(":%s", global.Config.Server.Port))
 	if err != nil {
 		fmt.Printf("%s", err.Error())

+ 1 - 0
AIT/models/record.go

@@ -13,6 +13,7 @@ type Record struct {
 	UserName   string `gorm:"user_name"`
 	FileType   string `gorm:"file_type"`
 	FilePath   string `gorm:"file_path"`
+	FileName   string `gorm:"file_name"`
 	FileUrl    string `gorm:"file_url"`
 	CreateTime string `gorm:"create_time"`
 	Result     string `gorm:"result"`

+ 6 - 0
AIT/service/recordService.go

@@ -37,3 +37,9 @@ func (f *RecordService) GetRecordList(param models.RecordListParam) ([]models.Re
 	rows := common.RestPage(page, "record", query, "", &recordList, &[]models.User{})
 	return recordList, rows
 }
+
+func (f *RecordService) FindById(recordId string) (models.Record, int64) {
+	var record models.Record
+	count := global.Db.Where("id = ?", recordId).First(&record).RowsAffected
+	return record, count
+}