From 30035b2d45357cc5a83963f84524bf51a13f9363 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Fri, 25 Jun 2021 02:05:58 +0800 Subject: [PATCH] no message --- controller/blog.go | 18 ++++++++++++++++-- main.go | 1 + model/memo.go | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 613a2cf..079816b 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -705,7 +705,7 @@ func GetMemos(c *gin.Context) { } limit, offset := GetPageParaFromQuery(c) if limit != 0 && offset != 0 { - dat, e := model.GetMemos(req.Title, 10, 0) + dat, e := model.GetMemos(req.Title, limit, offset) if nil != e { return } @@ -713,7 +713,7 @@ func GetMemos(c *gin.Context) { rsp.Status = 0 rsp.Msg = "OK" } else { - dat, e := model.GetMemos(req.Title, 10, 0) + dat, e := model.GetMemos(req.Title, limit, offset) if nil != e { return } @@ -725,6 +725,20 @@ func GetMemos(c *gin.Context) { } +func GetMemoCnt(c *gin.Context) { + rsp := RespBase{"ERR", -1, nil} + defer func() { + c.JSON(200, rsp) + }() + count := model.MemoCnt() + + rsp.Msg = "OK" + rsp.Status = 0 + rsp.Data = count + +} + + func GetMemo(c *gin.Context) { rsp := RespBase{"ERR", -1, nil} defer func() { diff --git a/main.go b/main.go index 60f31bc..eeb0a7d 100644 --- a/main.go +++ b/main.go @@ -161,6 +161,7 @@ func main() { api.POST("/memos", controller.GetMemos) // 备忘录批量 api.POST("/delmemo", controller.DeleteMemos) //删除备忘录 api.GET("/memo", controller.GetMemo) // 单独读取备忘录 + api.GET("/memocnt", controller.GetMemoCnt) // 单独读取备忘录 api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组 diff --git a/model/memo.go b/model/memo.go index d4b55ca..28f9a2c 100644 --- a/model/memo.go +++ b/model/memo.go @@ -64,6 +64,20 @@ func ReadMemo(id int32) ([]Memo, error) { return memo, nil } +func MemoCnt() int { + sql := fmt.Sprintf(`select count(*) from memo`) + type Count struct { + Count int32 `sql:"count(*)"` + } + cnts := []Count{} + e := db.GetMysqlClient().Query2(sql, &cnts) + if nil != e { + logs.Error(e.Error()) + return 0 + } + return int(cnts[0].Count) +} + func GetMemos(title string, limit int, offset int) ([]Memo, error) { memo := []Memo{} sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`,