完善文章分组接口

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() {
c.JSON(200, resp)
}()
type DocType struct {
Id int64 `sql:"id"`
TypeName string `sql:"type_name"`
}
docTypes := []DocType{}
docTypes := []model.ArticleType{}
e := db.GetMysqlClient().Query2("select * from doc_type",
&docTypes)
if nil != e {
@ -398,6 +395,54 @@ func UpdateMemo(c *gin.Context) {
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) {
rsp := RespBase{"ERR", -1, nil}
defer func() {

View File

@ -5,18 +5,19 @@ import (
"background/controller"
"background/model"
"encoding/json"
"github.com/gin-gonic/gin"
"log"
"github.com/gin-gonic/gin"
)
func AuthMiddle(c *gin.Context) {
func AuthMiddle(c *gin.Context) {
token := c.Query("token")
user := c.Query("userid")
if user == "" || token == ""{
if user == "" || token == "" {
log.Print("error user not existed or token missing")
log.Print(c.Request.URL.String())
c.JSON(200,controller.RespBase{
"auth err",20,nil,
c.JSON(200, controller.RespBase{
"auth err", 20, nil,
})
c.Abort()
return
@ -24,20 +25,20 @@ func AuthMiddle(c *gin.Context) {
if config.RedisOne().Exists(token).Val() {
users := model.Users{}
userInfo := config.RedisOne().Get(token).Val()
e := json.Unmarshal([]byte(userInfo),&users)
if nil != e{
c.JSON(200,controller.RespBase{
"auth err",10,nil,
e := json.Unmarshal([]byte(userInfo), &users)
if nil != e {
c.JSON(200, controller.RespBase{
"auth err", 10, nil,
})
c.Abort()
return
}
}else {
c.JSON(200,controller.RespBase{
"expired or no login",210,nil,
} else {
c.JSON(200, controller.RespBase{
"expired or no login", 210, nil,
})
c.Abort()
return
}
c.Next()
}
}

View File

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

15
main.go
View File

@ -159,12 +159,15 @@ func main() {
api.GET("/filelist", fileController.FileList) // 文件列表
api.GET("/fileType", fileController.FileType) // 文件类型
api.PUT("/memo", controller.CreateMemo) // 备忘录新建
api.POST("/memo", controller.UpdateMemo) // 备忘录更新
api.POST("/memos", controller.GetMemos) // 备忘录批量
api.POST("/delmemo", controller.DeleteMemos) //删除备忘录
api.GET("/memo", controller.GetMemo) // 单独读取
api.GET("doc_groups", controller.GetDocGroup) // 获取所有的文章分组
api.PUT("/memo", controller.CreateMemo) // 备忘录新建
api.POST("/memo", controller.UpdateMemo) // 备忘录更新
api.POST("/memos", controller.GetMemos) // 备忘录批量
api.POST("/delmemo", controller.DeleteMemos) //删除备忘录
api.GET("/memo", controller.GetMemo) // 单独读取
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("doc_versions", nil) // 获取文章的某个版本

View File

@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"github.com/pkg/errors"
"qiniupkg.com/x/log.v7"
)
@ -33,16 +34,17 @@ type ArticleType struct {
func GetArticlesType() []ArticleType {
ret := []ArticleType{}
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 {
group := []DocGroup{}
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 {
ret[k].GroupName = group[0].Name
}
}
log.Print(ret)
if nil != e {
logs.Error(e.Error())
return nil
@ -143,3 +145,33 @@ func GetAllGroup() ([]DocGroup, error) {
}
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
type mq struct {
}