收藏夹封面
This commit is contained in:
		@@ -9,6 +9,11 @@ import (
 | 
			
		||||
	"gorm.io/gorm/clause"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Cover struct {
 | 
			
		||||
	ID   int    `json:"id"`
 | 
			
		||||
	Type string `json:"type"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Collection struct {
 | 
			
		||||
	ID         int       `json:"id" gorm:"primaryKey"`
 | 
			
		||||
	Title      string    `json:"title"`
 | 
			
		||||
@@ -23,6 +28,7 @@ type Collection struct {
 | 
			
		||||
	UpdateTime time.Time `json:"update_time"`
 | 
			
		||||
	User       User      `json:"user" gorm:"foreignKey:UserId;references:ID"`
 | 
			
		||||
	Fan        bool      `json:"praise" gorm:"-"`
 | 
			
		||||
	Covers     []Cover   `json:"covers" gorm:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (Collection) TableName() string {
 | 
			
		||||
@@ -51,6 +57,17 @@ var CollectionItems = &graphql.Field{
 | 
			
		||||
					"fans":        &graphql.Field{Type: graphql.Int, Description: "关注数"},
 | 
			
		||||
					"fan":         &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否关注"},
 | 
			
		||||
					"user":        &graphql.Field{Type: userType, Description: "用户"},
 | 
			
		||||
					"covers": &graphql.Field{
 | 
			
		||||
						Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
 | 
			
		||||
							Name:        "cover",
 | 
			
		||||
							Description: "封面",
 | 
			
		||||
							Fields: graphql.Fields{
 | 
			
		||||
								"id":   &graphql.Field{Type: graphql.Int, Description: "ID"},
 | 
			
		||||
								"type": &graphql.Field{Type: graphql.String, Description: "类型"},
 | 
			
		||||
							},
 | 
			
		||||
						})),
 | 
			
		||||
						Description: "封面集",
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			})), Description: "收藏夹列表"},
 | 
			
		||||
			"total": &graphql.Field{Type: graphql.Int, Description: "收藏夹总数"},
 | 
			
		||||
@@ -101,6 +118,23 @@ var CollectionItems = &graphql.Field{
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		for index, item := range collects {
 | 
			
		||||
			var data []Cover
 | 
			
		||||
			var t string = "article"
 | 
			
		||||
			if item.Type == 1 {
 | 
			
		||||
				t = "image"
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if err := db.Table("web_collect").Limit(3).Where("explorer_id = ?", item.ID).Find(&data).Error; err != nil {
 | 
			
		||||
				fmt.Println("获取封面ID失败", err)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			for i := range data {
 | 
			
		||||
				data[i].Type = t
 | 
			
		||||
			}
 | 
			
		||||
			collects[index].Covers = data
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return map[string]interface{}{
 | 
			
		||||
			"list":  collects,
 | 
			
		||||
			"total": total,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user