praise_count
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/graphql-go/graphql"
|
"github.com/graphql-go/graphql"
|
||||||
|
"github.com/thoas/go-funk"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collection struct {
|
type Collection struct {
|
||||||
@@ -20,6 +21,8 @@ type Collection struct {
|
|||||||
CreateTime time.Time `json:"create_time"`
|
CreateTime time.Time `json:"create_time"`
|
||||||
UpdateTime time.Time `json:"update_time"`
|
UpdateTime time.Time `json:"update_time"`
|
||||||
User User `json:"user" gorm:"foreignKey:UserId;references:ID"`
|
User User `json:"user" gorm:"foreignKey:UserId;references:ID"`
|
||||||
|
PraiseCount int `json:"praise_count" gorm:"default:0"`
|
||||||
|
Praise bool `json:"praise" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Collection) TableName() string {
|
func (Collection) TableName() string {
|
||||||
@@ -79,6 +82,14 @@ var CollectionItems = &graphql.Field{
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
items := LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections)
|
||||||
|
if funk.Contains(items, "praise_count") {
|
||||||
|
for i := range collects {
|
||||||
|
collects[i].PraiseCount = collects[i].Fans
|
||||||
|
collects[i].Praise = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"list": collects,
|
"list": collects,
|
||||||
"total": total,
|
"total": total,
|
||||||
|
@@ -124,6 +124,19 @@ func CheckColorNullRows(offset int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取 List 中的所有字段名
|
||||||
|
func ListItem(requestedFields []ast.Selection) (data []string) {
|
||||||
|
for _, field := range requestedFields {
|
||||||
|
fieldAST, _ := field.(*ast.Field)
|
||||||
|
if fieldAST.Name.Value == "list" {
|
||||||
|
for _, str := range LoadItem(fieldAST.SelectionSet.Selections) {
|
||||||
|
data = append(data, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
// 获取所有字段名
|
// 获取所有字段名
|
||||||
func LoadItem(requestedFields []ast.Selection) (data []string) {
|
func LoadItem(requestedFields []ast.Selection) (data []string) {
|
||||||
var items = []string{"user", "article"}
|
var items = []string{"user", "article"}
|
||||||
|
Reference in New Issue
Block a user