games
This commit is contained in:
		@@ -349,6 +349,18 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						game := graphql.NewObject(graphql.ObjectConfig{
 | 
				
			||||||
 | 
							Name:        "Game",
 | 
				
			||||||
 | 
							Description: "游戏",
 | 
				
			||||||
 | 
							Fields: graphql.Fields{
 | 
				
			||||||
 | 
								"id":          &graphql.Field{Type: graphql.Int, Description: "游戏ID"},
 | 
				
			||||||
 | 
								"title":       &graphql.Field{Type: graphql.String, Description: "游戏标题"},
 | 
				
			||||||
 | 
								"era":         &graphql.Field{Type: graphql.String, Description: "游戏上线年份"},
 | 
				
			||||||
 | 
								"create_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏创建时间"},
 | 
				
			||||||
 | 
								"update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	image.AddFieldConfig("user", &graphql.Field{Type: user, Description: "图像所属用户"})
 | 
						image.AddFieldConfig("user", &graphql.Field{Type: user, Description: "图像所属用户"})
 | 
				
			||||||
	image.AddFieldConfig("similars", &graphql.Field{Type: graphql.NewList(image), Description: "相似的图像", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
						image.AddFieldConfig("similars", &graphql.Field{Type: graphql.NewList(image), Description: "相似的图像", Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
				
			||||||
		return []Image{}, nil
 | 
							return []Image{}, nil
 | 
				
			||||||
@@ -502,6 +514,62 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
				}, nil
 | 
									}, nil
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							"games": &graphql.Field{
 | 
				
			||||||
 | 
								Name:        "games",
 | 
				
			||||||
 | 
								Description: "游戏列表",
 | 
				
			||||||
 | 
								Type: graphql.NewObject(graphql.ObjectConfig{
 | 
				
			||||||
 | 
									Name:        "GameConnection",
 | 
				
			||||||
 | 
									Description: "条件筛选游戏列表",
 | 
				
			||||||
 | 
									Fields: graphql.Fields{
 | 
				
			||||||
 | 
										"list": &graphql.Field{Type: graphql.NewList(game), Description: "游戏列表"},
 | 
				
			||||||
 | 
										//"total": &graphql.Field{Type: graphql.Int, Description: "游戏总数"},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								}),
 | 
				
			||||||
 | 
								Args: graphql.FieldConfigArgument{
 | 
				
			||||||
 | 
									"id":          &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选游戏中指定ID的"},
 | 
				
			||||||
 | 
									"title":       &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定标题的"},
 | 
				
			||||||
 | 
									"era":         &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定年份的"},
 | 
				
			||||||
 | 
									"create_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选游戏中创建时间等于指定值的"},
 | 
				
			||||||
 | 
									"update_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选游戏中更新时间等于指定值的"},
 | 
				
			||||||
 | 
									"first":       &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"},
 | 
				
			||||||
 | 
									"last":        &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"},
 | 
				
			||||||
 | 
									"after":       &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
 | 
				
			||||||
 | 
									"before":      &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之前的元素)"},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								Resolve: func(p graphql.ResolveParams) (interface{}, error) {
 | 
				
			||||||
 | 
									var games []Game
 | 
				
			||||||
 | 
									var total int
 | 
				
			||||||
 | 
									var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// 获取筛选条件
 | 
				
			||||||
 | 
									var arg struct {
 | 
				
			||||||
 | 
										ID     int
 | 
				
			||||||
 | 
										Title  string
 | 
				
			||||||
 | 
										Era    string
 | 
				
			||||||
 | 
										First  int
 | 
				
			||||||
 | 
										Last   int
 | 
				
			||||||
 | 
										After  string
 | 
				
			||||||
 | 
										Before string
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									mapstructure.Decode(p.Args, &arg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									var limit int = 10
 | 
				
			||||||
 | 
									if arg.First != 0 {
 | 
				
			||||||
 | 
										limit = arg.First
 | 
				
			||||||
 | 
									} else if arg.Last != 0 {
 | 
				
			||||||
 | 
										limit = arg.Last
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if err := db.Limit(limit).Where("category_top_id = 22").Find(&games).Error; err != nil {
 | 
				
			||||||
 | 
										return nil, err
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									return map[string]interface{}{
 | 
				
			||||||
 | 
										"list":  games,
 | 
				
			||||||
 | 
										"total": total,
 | 
				
			||||||
 | 
									}, err
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		"images": &graphql.Field{
 | 
							"images": &graphql.Field{
 | 
				
			||||||
			Name:        "images",
 | 
								Name:        "images",
 | 
				
			||||||
			Description: "图像列表",
 | 
								Description: "图像列表",
 | 
				
			||||||
@@ -792,11 +860,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
						goqu.I("web_images.user_id").Eq(goqu.I("web_fans.blogger_id")),
 | 
											goqu.I("web_images.user_id").Eq(goqu.I("web_fans.blogger_id")),
 | 
				
			||||||
						goqu.I("web_fans.follower_id").Eq(p.Args["follower"]),
 | 
											goqu.I("web_fans.follower_id").Eq(p.Args["follower"]),
 | 
				
			||||||
					))
 | 
										))
 | 
				
			||||||
					//query = query.Join(
 | 
					 | 
				
			||||||
					//	goqu.Dialect("mysql").From("web_fans").Select("web_fans.blogger_id").Where(goqu.Ex{"web_fans.follower_id": p.Args["follower"]}),
 | 
					 | 
				
			||||||
					//	goqu.On(goqu.I("web_images.user_id").Eq(goqu.I("web_fans.blogger_id"))),
 | 
					 | 
				
			||||||
					//)
 | 
					 | 
				
			||||||
					//query = query.Where(goqu.L("EXISTS (SELECT 1 FROM web_fans WHERE web_fans.blogger_id = web_images.user_id AND web_fans.follower_id = ?)", p.Args["follower"]))
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// 数据库中筛选: 按图像主色调颜色筛选
 | 
									// 数据库中筛选: 按图像主色调颜色筛选
 | 
				
			||||||
@@ -919,7 +982,6 @@ func NewSchema(config Config) (graphql.Schema, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				var find = db.Where("web_images.id IN ?", ids)
 | 
									var find = db.Where("web_images.id IN ?", ids)
 | 
				
			||||||
				for _, item := range LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections) {
 | 
									for _, item := range LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections) {
 | 
				
			||||||
					//fmt.Println(index, item)
 | 
					 | 
				
			||||||
					find = find.Preload(item)
 | 
										find = find.Preload(item)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,6 +109,26 @@ func (User) TableName() string {
 | 
				
			|||||||
	return "web_member"
 | 
						return "web_member"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Game struct {
 | 
				
			||||||
 | 
						ID          int       `json:"id" gorm:"primaryKey"`
 | 
				
			||||||
 | 
						Title       string    `json:"title"`
 | 
				
			||||||
 | 
						Orientation string    `json:"orientation"`
 | 
				
			||||||
 | 
						Device      string    `json:"device"`
 | 
				
			||||||
 | 
						Era         string    `json:"era"`
 | 
				
			||||||
 | 
						Tags        string    `json:"tags"`
 | 
				
			||||||
 | 
						UserId      int       `json:"user_id"`
 | 
				
			||||||
 | 
						Content     string    `json:"content"`
 | 
				
			||||||
 | 
						Image       string    `json:"image"`
 | 
				
			||||||
 | 
						Images      string    `json:"images"`
 | 
				
			||||||
 | 
						User        User      `json:"user" gorm:"foreignKey:UserId"`
 | 
				
			||||||
 | 
						CreateTime  time.Time `json:"create_time"`
 | 
				
			||||||
 | 
						UpdateTime  time.Time `json:"update_time"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (Game) TableName() string {
 | 
				
			||||||
 | 
						return "web_article"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Article struct {
 | 
					type Article struct {
 | 
				
			||||||
	ID          int       `json:"id"          db:"id" gorm:"primaryKey"`
 | 
						ID          int       `json:"id"          db:"id" gorm:"primaryKey"`
 | 
				
			||||||
	Title       string    `json:"title"       db:"title"`
 | 
						Title       string    `json:"title"       db:"title"`
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user