package builder import ( "context" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints" "git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model" "strconv" ) type UsersBuilder interface { SetPage(pageNumber int) UsersBuilder SetLimit(limitUser int) UsersBuilder SearchByName(userName string) UsersBuilder SearchByAbout(about string) UsersBuilder SearchByAvatarID(postID model.PostID) UsersBuilder SearchByLevel(level model.UserLevel) UsersBuilder SearchByMinLevel(level model.UserLevel) UsersBuilder SearchByMaxLevellevel(model.UserLevel) UsersBuilder searchByCanUpload(canUpload bool) UsersBuilder SearchByIsApprover(isApprover bool) UsersBuilder SearchByOrder(order model.Order) 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) SearchByName(userName string) UsersBuilder { g.query["search[name_matches]"] = userName return g } func (g *getUsers) SearchByAbout(about string) UsersBuilder { g.query["search[about_me"] = about return g } func (g *getUsers) SearchByAvatarID(postID model.PostID) UsersBuilder { g.query["search[avatar_id]"] = strconv.FormatInt(int64(postID), 10) return g } func (g *getUsers) SearchByLevel(level model.UserLevel) UsersBuilder { g.query["search[level]"] = strconv.Itoa(int(level)) return g } func (g *getUsers) SearchByMinLevel(level model.UserLevel) UsersBuilder { g.query["search[min_level"] = strconv.Itoa(int(level)) return g } func (g *getUsers) SearchByMaxLevellevel(level model.UserLevel) UsersBuilder { g.query["search[max_level]"] = strconv.Itoa(int(level)) return g } func (g *getUsers) searchByCanUpload(canUpload bool) UsersBuilder { g.query["search[can_upload_free]"] = strconv.FormatBool(canUpload) return g } func (g *getUsers) SearchByIsApprover(isApprover bool) UsersBuilder { g.query["search[can_approve_posts]"] = strconv.FormatBool(isApprover) return g } func (g *getUsers) SearchByOrder(order model.Order) UsersBuilder { g.query["search[order]"] = string(order) return g } 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) { if g.requestContext.RateLimiter != nil { err := g.requestContext.RateLimiter.Wait(context.Background()) if err != nil { return nil, err } } users, err := endpoints.GetUsers(g.requestContext, g.query) if err != nil { return nil, err } return users, nil }