From 37dd7d8b6f7c5201021971e2f5782f5a66e2f4aa Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Mon, 25 Jan 2021 17:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A6=E7=B1=8D=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++ db/sqlManager.go | 1 - main.go | 16 ++++++------ 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 4fe1de9..a0a5464 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -418,6 +418,67 @@ func UpdateBook(c *gin.Context) { resp.Status = 0 } +func GetBook(c *gin.Context) { + type ReqGetBook struct { + ID int32 `json:"id"` + } + resp := RespBase{} + var req ReqGetBook + defer func() { + c.JSON(200, resp) + }() + e := c.BindJSON(&req) + if nil != e { + logs.Error(e.Error()) + return + } + var book model.Book + book.ID = int64(req.ID) + if e == db.GetOrm().First(&book, req.ID).Error { + logs.Error(e.Error) + return + } + resp.Data = book + resp.Msg = "OK" + resp.Status = 0 +} + +func GetPageBook(c *gin.Context) { + type ReqGetPageBook struct { + } + var req ReqGetPageBook + resp := RespBase{} + defer func() { + c.JSON(200, resp) + }() + + limit := c.Query("limit") + offset := c.Query("offset") + + iLmit, e := strconv.Atoi(limit) + if nil != e { + return + } + iOffset, e := strconv.Atoi(offset) + if nil != e { + return + } + e = c.BindJSON(&req) + if nil != e { + logs.Error(e.Error()) + return + } + books := []model.Book{} + e = db.GetOrm().Limit(iLmit).Offset(iOffset).Find(&books).Error + if nil != e { + log.Print(e.Error()) + return + } + resp.Status = 0 + resp.Msg = "OK" + resp.Data = books +} + func UpdateMemo(c *gin.Context) { resp := RespBase{"unkown error", -231, nil} defer func() { @@ -544,9 +605,11 @@ func GetMemos(c *gin.Context) { } } + func GetDocTemplate(c *gin.Context) { } + func GetMemo(c *gin.Context) { rsp := RespBase{"ERR", -1, nil} defer func() { diff --git a/db/sqlManager.go b/db/sqlManager.go index b43ce05..e95a63b 100644 --- a/db/sqlManager.go +++ b/db/sqlManager.go @@ -29,7 +29,6 @@ var gOrm *gorm.DB func Init() { var e error mysqlconf := config.GetMysqlConfig() - //InitMongoDb() log.Print("api runmode is " + config.ApiConfig().RunMode) if config.ApiConfig().RunMode == "debug" { gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)} diff --git a/main.go b/main.go index 3d5edc1..3a8efd7 100644 --- a/main.go +++ b/main.go @@ -24,9 +24,9 @@ import ( // @BasePath /api/v1 var ( - userController = controller.UserController{} - mailContoller = controller.MailController{} - fileController = controller.FileController{} + userController = controller.UserController{} + mailContoller = controller.MailController{} + fileController = controller.FileController{} ) func CORSMiddleware(c *gin.Context) { @@ -168,12 +168,12 @@ func main() { api.GET("doc_versions", nil) // 获取文章的某个版本 + api.PUT("/book", controller.CreateBook) // + api.POST("/book", controller.UpdateBook) // + api.POST("/book", controller.GetBook) // 单书籍数据 + api.POST("/books", controller.GetPageBook) // 批量书籍 + api.POST("/delbook", controller.DeleteMemos) // 删除书籍 - - api.PUT("/book", controller.CreateBook) // 备忘录新建 - api.POST("/book", controller.UpdateBook) // 备忘录更新 - api.POST("/books", controller.GetMemos) // 备忘录批量 - api.POST("/delbook", controller.DeleteMemos) //删除备忘录 } openapi := r.Group("openapi")