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/users.go

43 lines
983 B
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"
"log"
"strconv"
)
type UsersBuilder interface {
SetPage(pageNumber int) UsersBuilder
SetLimit(limitUser int) UsersBuilder
Execute() ([]model.User, error)
}
func NewGetUsersBuilder(requestContext model.RequestContext) UsersBuilder {
return &getUsers{requestContext: requestContext, query: make(map[string]string)}
}
type getUsers struct {
requestContext model.RequestContext
query map[string]string
}
func (g *getUsers) SetPage(pageNumber int) UsersBuilder {
g.query["page"] = strconv.Itoa(pageNumber)
return g
}
func (g *getUsers) SetLimit(limitUser int) UsersBuilder {
g.query["limit"] = strconv.Itoa(limitUser)
return g
}
func (g *getUsers) Execute() ([]model.User, error) {
users, err := endpoints.GetUsers(g.requestContext, g.query)
if err != nil {
log.Println(err)
return nil, err
}
return users, nil
}