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 }