praise_count
This commit is contained in:
		@@ -5,21 +5,24 @@ import (
 | 
				
			|||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/graphql-go/graphql"
 | 
						"github.com/graphql-go/graphql"
 | 
				
			||||||
 | 
						"github.com/thoas/go-funk"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Collection struct {
 | 
					type Collection struct {
 | 
				
			||||||
	ID         int       `json:"id" gorm:"primaryKey"`
 | 
						ID          int       `json:"id" gorm:"primaryKey"`
 | 
				
			||||||
	Title      string    `json:"title"`
 | 
						Title       string    `json:"title"`
 | 
				
			||||||
	Content    string    `json:"content"`
 | 
						Content     string    `json:"content"`
 | 
				
			||||||
	Type       int       `json:"type"`
 | 
						Type        int       `json:"type"`
 | 
				
			||||||
	Thumbnail  string    `json:"thumbnail"`
 | 
						Thumbnail   string    `json:"thumbnail"`
 | 
				
			||||||
	Num        int       `json:"num"`
 | 
						Num         int       `json:"num"`
 | 
				
			||||||
	Fans       int       `json:"fans"`
 | 
						Fans        int       `json:"fans"`
 | 
				
			||||||
	UserId     int       `json:"user_id"`
 | 
						UserId      int       `json:"user_id"`
 | 
				
			||||||
	ArticleId  int       `json:"article_id"`
 | 
						ArticleId   int       `json:"article_id"`
 | 
				
			||||||
	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