From 7de1958974206992a7b5992a30a8f0780afc68ad Mon Sep 17 00:00:00 2001 From: satori Date: Sat, 9 Nov 2024 10:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E8=97=8F=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/graphql.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/api/graphql.go b/api/graphql.go index 858800f..12dba84 100644 --- a/api/graphql.go +++ b/api/graphql.go @@ -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",