first
This commit is contained in:
@@ -1,25 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/graphql-go/graphql"
|
||||
)
|
||||
|
||||
type Collect struct {
|
||||
type Collection struct {
|
||||
ID int `json:"id" gorm:"primaryKey"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
Type int `json:"type"`
|
||||
Thumbnail string `json:"thumbnail"`
|
||||
Num int `json:"num"`
|
||||
Fans int `json:"fans"`
|
||||
UserId int `json:"user_id"`
|
||||
ArticleId int `json:"article_id"`
|
||||
CreateTime time.Time `json:"create_time"`
|
||||
UpdateTime time.Time `json:"update_time"`
|
||||
User User `json:"user" gorm:"foreignKey:UserId;references:ID"`
|
||||
}
|
||||
|
||||
func (Collect) TableName() string {
|
||||
return "web_collect"
|
||||
func (Collection) TableName() string {
|
||||
return "web_member_explorer"
|
||||
}
|
||||
|
||||
var CollectItems = &graphql.Field{
|
||||
Name: "collects",
|
||||
var CollectionItems = &graphql.Field{
|
||||
Name: "collections",
|
||||
Description: "收藏列表",
|
||||
Type: graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "CollectConnection",
|
||||
@@ -30,14 +38,19 @@ var CollectItems = &graphql.Field{
|
||||
Description: "收藏",
|
||||
Fields: graphql.Fields{
|
||||
"id": &graphql.Field{Type: graphql.Int, Description: "收藏ID"},
|
||||
"title": &graphql.Field{Type: graphql.String, Description: "收藏标题"},
|
||||
"type": &graphql.Field{Type: graphql.Int, Description: "收藏类型"},
|
||||
"title": &graphql.Field{Type: graphql.String, Description: "收藏标题"},
|
||||
"content": &graphql.Field{Type: graphql.String, Description: "收藏内容"},
|
||||
"thumbnail": &graphql.Field{Type: graphql.String, Description: "收藏缩略图"},
|
||||
"num": &graphql.Field{Type: graphql.Int, Description: "收藏数量"},
|
||||
"fans": &graphql.Field{Type: graphql.Int, Description: "收藏粉絲數"},
|
||||
"create_time": &graphql.Field{Type: graphql.DateTime, Description: "收藏创建时间"},
|
||||
"update_time": &graphql.Field{Type: graphql.DateTime, Description: "收藏更新时间"},
|
||||
"praise_count": &graphql.Field{Type: graphql.Int, Description: "点赞数"},
|
||||
"collect_count": &graphql.Field{Type: graphql.Int, Description: "收藏数"},
|
||||
"praise": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否点赞"},
|
||||
"collect": &graphql.Field{Type: graphql.Boolean, Description: "当前用户是否收藏"},
|
||||
"user": &graphql.Field{Type: userType, Description: "收藏用户"},
|
||||
},
|
||||
})), Description: "收藏列表"},
|
||||
"total": &graphql.Field{Type: graphql.Int, Description: "收藏总数"},
|
||||
@@ -55,8 +68,19 @@ var CollectItems = &graphql.Field{
|
||||
"before": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之前的元素)"},
|
||||
},
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
var collects []Collect
|
||||
var collects []Collection
|
||||
var total int
|
||||
var limit int = 10
|
||||
|
||||
if p.Args["first"] != nil {
|
||||
limit = p.Args["first"].(int)
|
||||
}
|
||||
|
||||
if err := db.Limit(limit).Preload("User").Find(&collects).Error; err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"list": collects,
|
||||
"total": total,
|
||||
|
Reference in New Issue
Block a user