补充用户信息
This commit is contained in:
@@ -197,7 +197,7 @@ var ArticleItems = &graphql.Field{
|
|||||||
fmt.Println(sql)
|
fmt.Println(sql)
|
||||||
|
|
||||||
if err := db.Raw(sql).Scan(&articles).Error; err != nil {
|
if err := db.Raw(sql).Scan(&articles).Error; err != nil {
|
||||||
fmt.Println("获取游戏列表失败", err)
|
fmt.Println("获取文章列表失败", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
api/game.go
25
api/game.go
@@ -45,6 +45,8 @@ var gameType = graphql.NewObject(graphql.ObjectConfig{
|
|||||||
"id": &graphql.Field{Type: graphql.Int, Description: "游戏ID"},
|
"id": &graphql.Field{Type: graphql.Int, Description: "游戏ID"},
|
||||||
"title": &graphql.Field{Type: graphql.String, Description: "游戏标题"},
|
"title": &graphql.Field{Type: graphql.String, Description: "游戏标题"},
|
||||||
"era": &graphql.Field{Type: graphql.String, Description: "游戏上线年份"},
|
"era": &graphql.Field{Type: graphql.String, Description: "游戏上线年份"},
|
||||||
|
"tags": &graphql.Field{Type: graphql.String, Description: "游戏标签"},
|
||||||
|
"user": &graphql.Field{Type: userType, Description: "所属用户"},
|
||||||
"create_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏创建时间"},
|
"create_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏创建时间"},
|
||||||
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"},
|
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "游戏更新时间"},
|
||||||
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
||||||
@@ -193,6 +195,29 @@ var GameItems = &graphql.Field{
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if funk.Contains(fields, "user") {
|
||||||
|
var ids []int
|
||||||
|
for _, game := range games {
|
||||||
|
ids = append(ids, game.UserId)
|
||||||
|
}
|
||||||
|
ids = funk.UniqInt(ids)
|
||||||
|
|
||||||
|
var users []User
|
||||||
|
if err := db.Table("web_member").Where("id in (?)", ids).Find(&users).Error; err != nil {
|
||||||
|
fmt.Println("获取用户信息失败", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, game := range games {
|
||||||
|
for _, user := range users {
|
||||||
|
if game.UserId == user.ID {
|
||||||
|
games[index].User = user
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if funk.Contains(fields, "text_list") || funk.Contains(fields, "text_count") {
|
if funk.Contains(fields, "text_list") || funk.Contains(fields, "text_count") {
|
||||||
fmt.Println("获取游戏文字列表")
|
fmt.Println("获取游戏文字列表")
|
||||||
for index, item := range games {
|
for index, item := range games {
|
||||||
|
27
api/work.go
27
api/work.go
@@ -41,6 +41,8 @@ var workType = graphql.NewObject(graphql.ObjectConfig{
|
|||||||
Fields: graphql.Fields{
|
Fields: graphql.Fields{
|
||||||
"id": &graphql.Field{Type: graphql.Int, Description: "作品ID"},
|
"id": &graphql.Field{Type: graphql.Int, Description: "作品ID"},
|
||||||
"title": &graphql.Field{Type: graphql.String, Description: "作品标题"},
|
"title": &graphql.Field{Type: graphql.String, Description: "作品标题"},
|
||||||
|
"tags": &graphql.Field{Type: graphql.String, Description: "作品标签"},
|
||||||
|
"user": &graphql.Field{Type: userType, Description: "所属用户"},
|
||||||
"create_time": &graphql.Field{Type: graphql.DateTime, Description: "作品创建时间"},
|
"create_time": &graphql.Field{Type: graphql.DateTime, Description: "作品创建时间"},
|
||||||
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "作品更新时间"},
|
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "作品更新时间"},
|
||||||
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
||||||
@@ -173,10 +175,33 @@ var WorkItems = &graphql.Field{
|
|||||||
fmt.Println(sql)
|
fmt.Println(sql)
|
||||||
|
|
||||||
if err := db.Raw(sql).Scan(&works).Error; err != nil {
|
if err := db.Raw(sql).Scan(&works).Error; err != nil {
|
||||||
fmt.Println("获取游戏列表失败", err)
|
fmt.Println("获取作品列表失败", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if funk.Contains(fields, "user") {
|
||||||
|
var ids []int
|
||||||
|
for _, game := range works {
|
||||||
|
ids = append(ids, game.UserId)
|
||||||
|
}
|
||||||
|
ids = funk.UniqInt(ids)
|
||||||
|
|
||||||
|
var users []User
|
||||||
|
if err := db.Table("web_member").Where("id in (?)", ids).Find(&users).Error; err != nil {
|
||||||
|
fmt.Println("获取用户信息失败", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for index, work := range works {
|
||||||
|
for _, user := range users {
|
||||||
|
if work.UserId == user.ID {
|
||||||
|
works[index].User = user
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"list": works,
|
"list": works,
|
||||||
"total": total,
|
"total": total,
|
||||||
|
Reference in New Issue
Block a user