collect_id

This commit is contained in:
2024-12-02 07:42:38 +08:00
parent 9519ca7e65
commit 51c8a7fe2e
2 changed files with 27 additions and 3 deletions

View File

@@ -41,8 +41,32 @@ var gameType = graphql.NewObject(graphql.ObjectConfig{
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"}, "update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"},
"praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"}, "praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"},
"collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"}, "collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"},
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"}, "praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
"collect": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否收藏"}, 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
}},
}, },
}) })

View File

@@ -100,7 +100,7 @@ var imageType = graphql.NewObject(graphql.ObjectConfig{
var user_id = p.Context.Value("user_id").(int) var user_id = p.Context.Value("user_id").(int)
if user_id != 0 { if user_id != 0 {
var collect int64 var collect int64
if err := db.Table("web_collect").Where("user_id = ?", user_id).Where("image_id = ?", p.Source.(Image).ID).Count(&collect); err != nil { if err := db.Table("web_collect").Where("user_id = ?", user_id).Where("collect_id = ?", p.Source.(Image).ID).Where("type = ?", 1).Count(&collect); err != nil {
return false, nil return false, nil
} }
if collect > 0 { if collect > 0 {