praise_count
This commit is contained in:
		@@ -5,6 +5,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/graphql-go/graphql"
 | 
			
		||||
	"github.com/thoas/go-funk"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Collection struct {
 | 
			
		||||
@@ -20,6 +21,8 @@ type Collection struct {
 | 
			
		||||
	CreateTime  time.Time `json:"create_time"`
 | 
			
		||||
	UpdateTime  time.Time `json:"update_time"`
 | 
			
		||||
	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 {
 | 
			
		||||
@@ -79,6 +82,14 @@ var CollectionItems = &graphql.Field{
 | 
			
		||||
			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{}{
 | 
			
		||||
			"list":  collects,
 | 
			
		||||
			"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) {
 | 
			
		||||
	var items = []string{"user", "article"}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user