text_list
This commit is contained in:
23
api/game.go
23
api/game.go
@@ -29,6 +29,7 @@ type Game struct {
|
||||
PraiseCount int `json:"praise_count" gorm:"column:praise"`
|
||||
CommentCount int `json:"comment_count" gorm:"column:comment_num"`
|
||||
TextCount int `json:"text_count" gorm:"column:text_count"`
|
||||
TextList []string `json:"text_list" gorm:"-"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
UpdateTime time.Time `json:"update_time"`
|
||||
}
|
||||
@@ -51,6 +52,7 @@ var gameType = graphql.NewObject(graphql.ObjectConfig{
|
||||
"praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"},
|
||||
"collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"},
|
||||
"text_count": &graphql.Field{Type: graphql.Int, Description: "文字数量"},
|
||||
"text_list": &graphql.Field{Type: graphql.NewList(graphql.String), Description: "文字列表"},
|
||||
},
|
||||
})
|
||||
|
||||
@@ -175,9 +177,6 @@ var GameItems = &graphql.Field{
|
||||
collect = ",CASE WHEN web_collect.id IS NOT NULL THEN TRUE ELSE FALSE END AS is_collect"
|
||||
collect_join = fmt.Sprintf("LEFT JOIN web_collect ON web_collect.collect_id = web_article.id AND web_collect.user_id = %d AND web_collect.type = 0", user_id)
|
||||
}
|
||||
if funk.Contains(fields, "text_count") {
|
||||
text_count = ",(SELECT COUNT(*) FROM web_images wi WHERE wi.article_id = web_article.id AND wi.text != '') AS text_count"
|
||||
}
|
||||
|
||||
sql = fmt.Sprintf(`
|
||||
WITH RankedArticles AS (%s)
|
||||
@@ -194,6 +193,24 @@ var GameItems = &graphql.Field{
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if funk.Contains(fields, "text_list") || funk.Contains(fields, "text_count") {
|
||||
fmt.Println("获取游戏文字列表")
|
||||
for index, item := range games {
|
||||
var images []Image
|
||||
if err := db.Table("web_images").Where("article_id", item.ID).Find(&images).Error; err != nil {
|
||||
fmt.Println("获取游戏图片列表失败", err)
|
||||
return nil, err
|
||||
}
|
||||
for _, image := range images {
|
||||
for _, text := range image.Text {
|
||||
item.TextList = append(item.TextList, text.Text)
|
||||
}
|
||||
}
|
||||
games[index].TextList = funk.UniqString(item.TextList)
|
||||
games[index].TextCount = len(item.TextList)
|
||||
}
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"list": games,
|
||||
"total": total,
|
||||
|
Reference in New Issue
Block a user