增加字段:用户是否点赞
This commit is contained in:
		@@ -173,6 +173,22 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
			"create_time":             &graphql.Field{Type: graphql.DateTime, Description: "图像创建时间"},
 | 
			
		||||
			"update_time":             &graphql.Field{Type: graphql.DateTime, Description: "图像更新时间"},
 | 
			
		||||
			"article":                 &graphql.Field{Type: article, Description: "图像所属文章"},
 | 
			
		||||
			"demo": &graphql.Field{Type: graphql.String, Description: "demo", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
			
		||||
				return "ok", nil
 | 
			
		||||
			}},
 | 
			
		||||
			"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
			
		||||
				var user_id = p.Context.Value("user_id").(int)
 | 
			
		||||
				if user_id != 0 {
 | 
			
		||||
					var praise int64
 | 
			
		||||
					if err := db.Table("web_praise").Where("user_id = ?", user_id).Where("image_id = ?", p.Source.(Image).ID).Count(&praise); err != nil {
 | 
			
		||||
						return false, nil
 | 
			
		||||
					}
 | 
			
		||||
					if praise > 0 {
 | 
			
		||||
						return true, nil
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				return false, nil
 | 
			
		||||
			}},
 | 
			
		||||
			"text": &graphql.Field{
 | 
			
		||||
				Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
 | 
			
		||||
					Name:        "Text",
 | 
			
		||||
@@ -409,13 +425,9 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
					Orientation string
 | 
			
		||||
					Sort        string
 | 
			
		||||
					Order       string
 | 
			
		||||
					CreateTime  string `json:"create_time"`
 | 
			
		||||
					UpdateTime  string
 | 
			
		||||
				}
 | 
			
		||||
				mapstructure.Decode(p.Args, &args)
 | 
			
		||||
 | 
			
		||||
				fmt.Println("args.CreateTime:", args.CreateTime)
 | 
			
		||||
 | 
			
		||||
				// 限制长度防止全表扫描
 | 
			
		||||
				var limit = 10
 | 
			
		||||
				if args.First != 0 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user