This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/pkg/e621/builder/posts.go

57 lines
1.2 KiB
Go
Raw Normal View History

package builder
import (
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
"strconv"
)
type PostsBuilder interface {
Tags(tags string) PostsBuilder
PageAfter(postID int) PostsBuilder
pageBefore(postID int) PostsBuilder
SetLimit(limitUser int) PostsBuilder
Execute() ([]model.Post, error)
}
func NewGetPostsBuilder(requestContext model.RequestContext) PostsBuilder {
return &getPosts{
requestContext: requestContext,
query: make(map[string]string),
}
}
type getPosts struct {
requestContext model.RequestContext
query map[string]string
}
func (g *getPosts) Tags(tags string) PostsBuilder {
g.query["tags"] = tags
return g
}
func (g *getPosts) PageAfter(postID int) PostsBuilder {
g.query["page"] = "a" + strconv.Itoa(postID)
return g
}
func (g *getPosts) pageBefore(postID int) PostsBuilder {
g.query["page"] = "b" + strconv.Itoa(postID)
return g
}
func (g *getPosts) SetLimit(limitUser int) PostsBuilder {
g.query["limit"] = strconv.Itoa(limitUser)
return g
}
func (g *getPosts) Execute() ([]model.Post, error) {
posts, err := endpoints.GetPosts(g.requestContext, g.query)
if err != nil {
return nil, err
}
return posts, err
}