排序条件
This commit is contained in:
@@ -526,11 +526,20 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
Args: graphql.FieldConfigArgument{
|
Args: graphql.FieldConfigArgument{
|
||||||
|
"style": &graphql.ArgumentConfig{Type: graphql.String, Description: "按风格筛选游戏"},
|
||||||
|
"device": &graphql.ArgumentConfig{Type: graphql.String, Description: "按平台筛选游戏"},
|
||||||
|
"orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按屏幕方向筛选游戏"},
|
||||||
|
"era": &graphql.ArgumentConfig{Type: graphql.String, Description: "按年份筛选游戏"},
|
||||||
|
"category_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "按分类ID筛选游戏"},
|
||||||
|
"tags": &graphql.ArgumentConfig{Type: graphql.String, Description: "按标签筛选游戏"},
|
||||||
|
"user_id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "按用户ID筛选游戏"},
|
||||||
"id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选游戏中指定ID的"},
|
"id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选游戏中指定ID的"},
|
||||||
"title": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定标题的"},
|
"title": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定标题的"},
|
||||||
"era": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定年份的"},
|
"rank": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选游戏中含有指定排名的"},
|
||||||
"create_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选游戏中创建时间等于指定值的"},
|
"create_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "按创建时间筛选游戏"},
|
||||||
"update_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选游戏中更新时间等于指定值的"},
|
"update_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "按修改时间筛选游戏"},
|
||||||
|
"sort": &graphql.ArgumentConfig{Type: graphql.String, Description: "按指定字段排序游戏"},
|
||||||
|
"order": &graphql.ArgumentConfig{Type: orderType, Description: "排序类型(升序或降序)", DefaultValue: "ASC"},
|
||||||
"first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"},
|
"first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"},
|
||||||
"last": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"},
|
"last": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"},
|
||||||
"after": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
|
"after": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
|
||||||
@@ -541,23 +550,30 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
var total int
|
var total int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// 获取筛选条件
|
var query = goqu.Dialect("mysql").From("web_article")
|
||||||
var arg struct {
|
|
||||||
ID int
|
// 筛选条件
|
||||||
Title string
|
for _, format := range []string{"id", "style", "device", "orientation", "era", "category_id", "tags"} {
|
||||||
Era string
|
if p.Args[format] != nil {
|
||||||
First int
|
query = query.Where(goqu.C(format).Eq(p.Args[format]))
|
||||||
Last int
|
}
|
||||||
After string
|
}
|
||||||
Before string
|
|
||||||
|
// 排序条件
|
||||||
|
if p.Args["sort"] != nil {
|
||||||
|
if p.Args["order"].(string) == "ASC" {
|
||||||
|
query = query.Order(goqu.C(p.Args["sort"].(string)).Asc())
|
||||||
|
}
|
||||||
|
if p.Args["order"].(string) == "DESC" {
|
||||||
|
query = query.Order(goqu.C(p.Args["sort"].(string)).Desc())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mapstructure.Decode(p.Args, &arg)
|
|
||||||
|
|
||||||
var limit int = 10
|
var limit int = 10
|
||||||
if arg.First != 0 {
|
if p.Args["first"] != nil {
|
||||||
limit = arg.First
|
limit = p.Args["first"].(int)
|
||||||
} else if arg.Last != 0 {
|
} else if p.Args["last"] != nil {
|
||||||
limit = arg.Last
|
limit = p.Args["last"].(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.Limit(limit).Where("category_top_id = 22").Find(&games).Error; err != nil {
|
if err := db.Limit(limit).Where("category_top_id = 22").Find(&games).Error; err != nil {
|
||||||
@@ -610,7 +626,7 @@ func NewSchema(config Config) (graphql.Schema, error) {
|
|||||||
"content": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定内容的"},
|
"content": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定内容的"},
|
||||||
"remark": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定备注的"},
|
"remark": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定备注的"},
|
||||||
"description": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定描述的"},
|
"description": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定描述的"},
|
||||||
"rank": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定等级的"},
|
"rank": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定排名的"},
|
||||||
"text": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定文字的"},
|
"text": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中含有指定文字的"},
|
||||||
"create_time": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中创建时间等于指定值的"},
|
"create_time": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中创建时间等于指定值的"},
|
||||||
"update_time": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中更新时间等于指定值的"},
|
"update_time": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选图像中更新时间等于指定值的"},
|
||||||
|
Reference in New Issue
Block a user