书籍管理功能

master
zcy 2021-01-25 17:28:50 +08:00
parent 7a97d9532e
commit 37dd7d8b6f
3 changed files with 71 additions and 9 deletions

View File

@ -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() {

View File

@ -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)}

16
main.go
View File

@ -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")