数据库中筛选:收藏夹中的截图
This commit is contained in:
		@@ -203,6 +203,17 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
				}
 | 
			
		||||
				return false, nil
 | 
			
		||||
			}},
 | 
			
		||||
			"collect_id": &graphql.Field{Type: graphql.Int, Description: "当前用户收藏ID", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
			
		||||
				var user_id = p.Context.Value("user_id").(int)
 | 
			
		||||
				if user_id != 0 {
 | 
			
		||||
					var collect_id int
 | 
			
		||||
					if err := db.Table("web_collect").Where("user_id = ?", user_id).Where("image_id = ?", p.Source.(Image).ID).First(&collect_id); err != nil {
 | 
			
		||||
						return nil, nil
 | 
			
		||||
					}
 | 
			
		||||
					return collect_id, nil
 | 
			
		||||
				}
 | 
			
		||||
				return nil, nil
 | 
			
		||||
			}},
 | 
			
		||||
			"text": &graphql.Field{
 | 
			
		||||
				Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
 | 
			
		||||
					Name:        "Text",
 | 
			
		||||
@@ -398,6 +409,8 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
				},
 | 
			
		||||
			}),
 | 
			
		||||
			Args: graphql.FieldConfigArgument{
 | 
			
		||||
				"collect_id":    &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定收藏夹的"},
 | 
			
		||||
				"collect":       &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定用户收藏过的"},
 | 
			
		||||
				"praise":        &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选图像中指定用户点赞过的"},
 | 
			
		||||
				"follower":      &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的关注列表发布的图像"},
 | 
			
		||||
				"interest":      &graphql.ArgumentConfig{Type: graphql.Int, Description: "获取指定ID用户的兴趣推荐图像"},
 | 
			
		||||
@@ -518,7 +531,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
				// 如果没有外部排序则使用指定排序
 | 
			
		||||
				if p.Args["text"] == nil && p.Args["similar"] == nil {
 | 
			
		||||
					query = query.Select("web_images.id", goqu.L(
 | 
			
		||||
						fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY %s %s)", p.Args["sort"], p.Args["order"]),
 | 
			
		||||
						fmt.Sprintf("ROW_NUMBER() OVER(ORDER BY web_images.%s %s)", p.Args["sort"], p.Args["order"]),
 | 
			
		||||
					).As("row_num"))
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -563,6 +576,22 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
			
		||||
					))
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 数据库中筛选:用户收藏的截图
 | 
			
		||||
				if p.Args["collect"] != nil {
 | 
			
		||||
					query = query.Join(goqu.T("web_collect"), goqu.On(
 | 
			
		||||
						goqu.I("web_images.id").Eq(goqu.I("web_collect.image_id")),
 | 
			
		||||
						goqu.I("web_collect.user_id").Eq(p.Args["collect"]),
 | 
			
		||||
					))
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 数据库中筛选:收藏夹中的截图
 | 
			
		||||
				if p.Args["collect_id"] != nil {
 | 
			
		||||
					query = query.Join(goqu.T("web_collect"), goqu.On(
 | 
			
		||||
						goqu.I("web_images.id").Eq(goqu.I("web_collect.image_id")),
 | 
			
		||||
						goqu.I("web_collect.collect_id").Eq(p.Args["collect_id"]),
 | 
			
		||||
					))
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// 数据库中筛选:游戏设备
 | 
			
		||||
				if p.Args["device"] != nil {
 | 
			
		||||
					query = query.Join(goqu.T("web_article"), goqu.On(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user