API分页

This commit is contained in:
2024-12-02 06:53:52 +08:00
parent 520e3bade6
commit f4bec98b7a
10 changed files with 1385 additions and 1446 deletions

65
api/collect.go Normal file
View File

@@ -0,0 +1,65 @@
package api
import (
"time"
"github.com/graphql-go/graphql"
)
type Collect struct {
ID int `json:"id" gorm:"primaryKey"`
UserId int `json:"user_id"`
ArticleId int `json:"article_id"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
}
func (Collect) TableName() string {
return "web_collect"
}
var CollectItems = &graphql.Field{
Name: "collects",
Description: "收藏列表",
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "CollectConnection",
Description: "条件筛选收藏列表",
Fields: graphql.Fields{
"list": &graphql.Field{Type: graphql.NewList(graphql.NewObject(graphql.ObjectConfig{
Name: "Collect",
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: "收藏类型"},
"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: "当前用户是否收藏"},
},
})), Description: "收藏列表"},
"total": &graphql.Field{Type: graphql.Int, Description: "收藏总数"},
},
}),
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选收藏中指定ID的"},
"title": &graphql.ArgumentConfig{Type: graphql.String, Description: "筛选收藏中含有指定标题的"},
"type": &graphql.ArgumentConfig{Type: graphql.Int, Description: "筛选收藏中含有指定类型的"},
"create_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选收藏中创建时间等于指定值的"},
"update_time": &graphql.ArgumentConfig{Type: graphql.DateTime, Description: "筛选收藏中更新时间等于指定值的"},
"first": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的前n個元素)"},
"last": &graphql.ArgumentConfig{Type: graphql.Int, Description: "翻页参数(傳回清單中的最後n個元素)"},
"after": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之後的元素)"},
"before": &graphql.ArgumentConfig{Type: graphql.String, Description: "翻页参数(傳回清單中指定遊標之前的元素)"},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
var collects []Collect
var total int
return map[string]interface{}{
"list": collects,
"total": total,
}, nil
},
}