diff --git a/api/graphql.go b/api/graphql.go index 2ebaf62..ecd92e9 100644 --- a/api/graphql.go +++ b/api/graphql.go @@ -838,6 +838,7 @@ func NewSchema(config Config) (graphql.Schema, error) { }, }), Args: graphql.FieldConfigArgument{ + "activity": &graphql.ArgumentConfig{Type: graphql.Boolean, Description: "按是否活动筛选图像"}, "style": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏风格筛选图像"}, "device": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏平台筛选图像"}, "orientation": &graphql.ArgumentConfig{Type: graphql.String, Description: "按游戏版式筛选图像"}, @@ -1020,6 +1021,11 @@ func NewSchema(config Config) (graphql.Schema, error) { applyTimeCondition("update_time", p.Args["update_time"].(string)) } + // 数据库中筛选:按是否活动 + if activity, ok := p.Args["activity"].(bool); ok { + query = query.Where(goqu.Ex{"web_images.activity": map[bool]string{true: "1", false: "0"}[activity]}) + } + // 数据库中筛选:按游戏标签 if p.Args["tags"] != nil { tags := strings.Split(strings.ReplaceAll(p.Args["tags"].(string), " ", ""), ",") @@ -1245,7 +1251,7 @@ func NewSchema(config Config) (graphql.Schema, error) { ids = append(ids, item.ID) } - var find = db.Where("web_images.id IN ?", ids) + var find = db.Where("web_images.id IN ?", ids).Select("*", "CASE WHEN activity = '1' THEN TRUE ELSE FALSE END AS is_active") for _, item := range LoadItem(p.Info.FieldASTs[0].SelectionSet.Selections) { find = find.Preload(item) } diff --git a/api/struct.go b/api/struct.go index 4917310..9b449a3 100644 --- a/api/struct.go +++ b/api/struct.go @@ -74,6 +74,7 @@ type Image struct { Text TextList `json:"text" db:"text" gorm:"type:json"` User User `json:"user" gorm:"foreignKey:UserID"` Article Article `json:"article" gorm:"foreignKey:ArticleID"` + Activity bool `json:"activity"` } func (Image) TableName() string {