58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
|
package builder
|
||
|
|
||
|
import (
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
|
||
|
"log"
|
||
|
"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 {
|
||
|
log.Println(err)
|
||
|
return nil, err
|
||
|
}
|
||
|
return posts, err
|
||
|
}
|