collect_id
This commit is contained in:
28
api/game.go
28
api/game.go
@@ -41,8 +41,32 @@ var gameType = graphql.NewObject(graphql.ObjectConfig{
|
||||
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"},
|
||||
"praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"},
|
||||
"collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"},
|
||||
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
||||
"collect": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否收藏"},
|
||||
"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("praise_id = ?", p.Source.(Game).ID).Where("type = ?", 0).Count(&praise); err != nil {
|
||||
return false, nil
|
||||
}
|
||||
if praise > 0 {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}},
|
||||
"collect": &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 collect int64
|
||||
if err := db.Table("web_collect").Where("user_id = ?", user_id).Where("collect_id = ?", p.Source.(Game).ID).Where("type = ?", 0).Count(&collect); err != nil {
|
||||
return false, nil
|
||||
}
|
||||
if collect > 0 {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user