收藏状态
This commit is contained in:
@@ -173,9 +173,6 @@ 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 {
|
||||
@@ -189,6 +186,19 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
||||
}
|
||||
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("image_id = ?", p.Source.(Image).ID).Count(&collect); err != nil {
|
||||
return false, nil
|
||||
}
|
||||
if collect > 0 {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}},
|
||||
"text": &graphql.Field{
|
||||
Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "Text",
|
||||
|
Reference in New Issue
Block a user