Skip to content

Commit

Permalink
feat: 自动更新数据库的拓展参数
Browse files Browse the repository at this point in the history
  • Loading branch information
DokiDoki1103 committed Jun 27, 2024
1 parent 4666b77 commit 51c314c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/controller/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Search(c *gin.Context) {
c.JSON(http.StatusBadRequest, global.ErrorParam)
return
}
req.Extra = c.Query("extra")

var result [][]string // 最后所有的答案的二维数组
var localAnswer [][]string // 本地答案
Expand Down
8 changes: 8 additions & 0 deletions internal/search/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/itihey/tikuAdapter/internal/dao"
"github.com/itihey/tikuAdapter/pkg/model"
"github.com/itihey/tikuAdapter/pkg/util"
"log"
)

// DB mysql 或者sqlite3
Expand Down Expand Up @@ -39,6 +40,13 @@ func (in *dBSearch) SearchAnswer(req model.SearchRequest) (answer [][]string, er
}
find = find2
}
//如果数据库中没有extra那么自动补全他
if len(find) == 1 && find[0].Extra == "" {
_, err1 := tiku.Where(tiku.ID.Eq(find[0].ID)).Update(tiku.Extra, req.Extra)
if err1 != nil {
log.Println("更新extra失败", err1)
}
}
for i := range find {
var answers []string // 最后所有的答案的二维数组
err := json.Unmarshal([]byte(find[i].Answer), &answers)
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type SearchRequest struct {
Question string `json:"question"`
Options []string `json:"options"`
Type uint `json:"type"`

Extra string `json:"extra"`
}

// SearchResponse 搜题响应体
Expand Down

0 comments on commit 51c314c

Please sign in to comment.