no message

master
DESKTOP-4RNDQIC\29019 2021-06-25 02:05:58 +08:00
parent 13f3369b12
commit 30035b2d45
3 changed files with 31 additions and 2 deletions

View File

@ -705,7 +705,7 @@ func GetMemos(c *gin.Context) {
} }
limit, offset := GetPageParaFromQuery(c) limit, offset := GetPageParaFromQuery(c)
if limit != 0 && offset != 0 { if limit != 0 && offset != 0 {
dat, e := model.GetMemos(req.Title, 10, 0) dat, e := model.GetMemos(req.Title, limit, offset)
if nil != e { if nil != e {
return return
} }
@ -713,7 +713,7 @@ func GetMemos(c *gin.Context) {
rsp.Status = 0 rsp.Status = 0
rsp.Msg = "OK" rsp.Msg = "OK"
} else { } else {
dat, e := model.GetMemos(req.Title, 10, 0) dat, e := model.GetMemos(req.Title, limit, offset)
if nil != e { if nil != e {
return 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) { func GetMemo(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil} rsp := RespBase{"ERR", -1, nil}
defer func() { defer func() {

View File

@ -161,6 +161,7 @@ func main() {
api.POST("/memos", controller.GetMemos) // 备忘录批量 api.POST("/memos", controller.GetMemos) // 备忘录批量
api.POST("/delmemo", controller.DeleteMemos) //删除备忘录 api.POST("/delmemo", controller.DeleteMemos) //删除备忘录
api.GET("/memo", controller.GetMemo) // 单独读取备忘录 api.GET("/memo", controller.GetMemo) // 单独读取备忘录
api.GET("/memocnt", controller.GetMemoCnt) // 单独读取备忘录
api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组 api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组

View File

@ -64,6 +64,20 @@ func ReadMemo(id int32) ([]Memo, error) {
return memo, nil 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) { func GetMemos(title string, limit int, offset int) ([]Memo, error) {
memo := []Memo{} memo := []Memo{}
sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`, sql := fmt.Sprintf(`select * from memo where memo.title like '%s%%' limit %d offset %d`,