43 lines
983 B
Go
43 lines
983 B
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 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
|
||
|
}
|