完善文章分组接口

master
DESKTOP-4RNDQIC\29019 2020-09-26 12:30:23 +08:00
parent 2333eb94c0
commit ccfbb662ff
6 changed files with 109 additions and 31 deletions

View File

@ -339,11 +339,8 @@ func ArticlesTypes(c *gin.Context) {
defer func() { defer func() {
c.JSON(200, resp) c.JSON(200, resp)
}() }()
type DocType struct {
Id int64 `sql:"id"` docTypes := []model.ArticleType{}
TypeName string `sql:"type_name"`
}
docTypes := []DocType{}
e := db.GetMysqlClient().Query2("select * from doc_type", e := db.GetMysqlClient().Query2("select * from doc_type",
&docTypes) &docTypes)
if nil != e { if nil != e {
@ -398,6 +395,54 @@ func UpdateMemo(c *gin.Context) {
resp.Status = 0 resp.Status = 0
} }
func GetDocTypeGroup(c *gin.Context) {
type DocType struct {
Id int32 `json:"id"`
}
rsp := RespBase{"ERR", -1, nil}
defer func() {
c.JSON(200, rsp)
}()
var id DocType
e := c.BindJSON(&id)
if nil != e {
log.Print(e.Error)
return
}
group, e := model.GetTypeGroup(id.Id)
if nil != e {
log.Print(e.Error)
return
}
rsp.Data = group
rsp.Status = 0
rsp.Msg = "OK"
}
func GetDoGroupcType(c *gin.Context) {
type DocType struct {
Id int32 `json:"id"`
}
rsp := RespBase{"ERR", -1, nil}
defer func() {
c.JSON(200, rsp)
}()
var id DocType
e := c.BindJSON(&id)
if nil != e {
log.Print(e.Error)
return
}
group, e := model.GetGroupTypes(id.Id)
if nil != e {
log.Print(e.Error)
return
}
rsp.Data = group
rsp.Status = 0
rsp.Msg = "OK"
}
func GetDocGroup(c *gin.Context) { func GetDocGroup(c *gin.Context) {
rsp := RespBase{"ERR", -1, nil} rsp := RespBase{"ERR", -1, nil}
defer func() { defer func() {

View File

@ -5,8 +5,9 @@ import (
"background/controller" "background/controller"
"background/model" "background/model"
"encoding/json" "encoding/json"
"github.com/gin-gonic/gin"
"log" "log"
"github.com/gin-gonic/gin"
) )
func AuthMiddle(c *gin.Context) { func AuthMiddle(c *gin.Context) {

View File

@ -2,6 +2,7 @@
package db package db
import ( import (
"background/logs"
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
@ -9,7 +10,6 @@ import (
"strconv" "strconv"
"sync" "sync"
"time" "time"
"background/logs"
) )
// 数据容器抽象对象定义 // 数据容器抽象对象定义

View File

@ -165,6 +165,9 @@ func main() {
api.POST("/delmemo", controller.DeleteMemos) //删除备忘录 api.POST("/delmemo", controller.DeleteMemos) //删除备忘录
api.GET("/memo", controller.GetMemo) // 单独读取 api.GET("/memo", controller.GetMemo) // 单独读取
api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组 api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组
api.POST("type_group", controller.GetDocTypeGroup) // 获取类所在的组
api.POST("group_type", controller.GetDoGroupcType) // 获取类所在的组
api.GET("templates", controller.GetDocTemplate) // 获取所有文章的模板 api.GET("templates", controller.GetDocTemplate) // 获取所有文章的模板
api.GET("doc_versions", nil) // 获取文章的某个版本 api.GET("doc_versions", nil) // 获取文章的某个版本

View File

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/pkg/errors"
"qiniupkg.com/x/log.v7" "qiniupkg.com/x/log.v7"
) )
@ -33,16 +34,17 @@ type ArticleType struct {
func GetArticlesType() []ArticleType { func GetArticlesType() []ArticleType {
ret := []ArticleType{} ret := []ArticleType{}
sql := fmt.Sprintf("select * from doc_type") sql := fmt.Sprintf("select * from doc_type")
e := db.GetBlogMysql().Query2(sql, &ret) e := db.GetMysqlClient().Query2(sql, &ret)
log.Print(ret)
for k, _ := range ret { for k, _ := range ret {
group := []DocGroup{} group := []DocGroup{}
sql = fmt.Sprintf("select * from doc_group where doc_group.int = %d", ret[k].Group) sql = fmt.Sprintf("select * from doc_group where doc_group.int = %d", ret[k].Group)
db.GetBlogMysql().Query2(sql, &group) db.GetMysqlClient().Query2(sql, &group)
if len(group) > 0 { if len(group) > 0 {
ret[k].GroupName = group[0].Name ret[k].GroupName = group[0].Name
} }
} }
log.Print(ret)
if nil != e { if nil != e {
logs.Error(e.Error()) logs.Error(e.Error())
return nil return nil
@ -143,3 +145,33 @@ func GetAllGroup() ([]DocGroup, error) {
} }
return ret, nil return ret, nil
} }
func GetTypeGroup(id int32) (DocGroup, error) {
ret := []DocGroup{}
sql := fmt.Sprintf("select * from doc_group where doc_group = ?", id)
e := db.GetMysqlClient().Query2(sql, &ret)
if nil != e {
logs.Error(e.Error())
return DocGroup{}, e
}
if len(ret) > 0 {
return ret[0], nil
} else {
return DocGroup{}, errors.New("no existed")
}
}
func GetGroupTypes(id int32) ([]ArticleType, error) {
ret := []ArticleType{}
sql := fmt.Sprintf("select * from doc_type where doc_type.group = %d", id)
log.Print(sql)
e := db.GetMysqlClient().Query2(sql, &ret)
if nil != e {
logs.Error(e.Error())
return nil, e
}
if len(ret) > 0 {
return ret, nil
} else {
return nil, errors.New("no existed")
}
}

View File

@ -1,7 +1,4 @@
package mq package mq
type mq struct { type mq struct {
} }