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/pools.go
2023-10-24 15:10:39 +02:00

94 lines
2.3 KiB
Go

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 PoolsBuilder interface {
SearchName(name string) PoolsBuilder
SearchID(poolIDs string) PoolsBuilder
SearchDescritpion(description string) PoolsBuilder
SearchCreatorID(creatorID int) PoolsBuilder
searchCreatorName(creatorName string) PoolsBuilder
Active(isActive bool) PoolsBuilder
SearchCategory(category model.PoolCategory) PoolsBuilder
Order(order model.PoolOrder) PoolsBuilder
SetLimit(limitPools int) PoolsBuilder
Execute() ([]model.Pool, error)
}
func NewGetPoolsBuilder(requstContext model.RequestContext) PoolsBuilder {
return &getPools{
requestContext: requstContext,
query: make(map[string]string),
}
}
type getPools struct {
requestContext model.RequestContext
query map[string]string
}
func (g *getPools) SearchName(name string) PoolsBuilder {
g.query["search[name_matches]"] = name
return g
}
func (g *getPools) SearchID(poolIDs string) PoolsBuilder {
g.query["search[id]"] = poolIDs
return g
}
func (g *getPools) SearchDescritpion(description string) PoolsBuilder {
g.query["search[description_matches]"] = description
return g
}
func (g *getPools) SearchCreatorID(creatorID int) PoolsBuilder {
g.query["search[creator_id]"] = strconv.Itoa(creatorID)
return g
}
func (g *getPools) searchCreatorName(creatorName string) PoolsBuilder {
g.query["search[creator_name]"] = creatorName
return g
}
func (g *getPools) Active(isActive bool) PoolsBuilder {
g.query["search[is_active]"] = strconv.FormatBool(isActive)
return g
}
func (g *getPools) SearchCategory(category model.PoolCategory) PoolsBuilder {
g.query["search[category]"] = string(category)
return g
}
func (g *getPools) Order(order model.PoolOrder) PoolsBuilder {
g.query["search[order]"] = string(order)
return g
}
func (g *getPools) SetLimit(limitUser int) PoolsBuilder {
g.query["limit"] = strconv.Itoa(limitUser)
return g
}
func (g *getPools) Execute() ([]model.Pool, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
}
}
pools, err := endpoints.GetPools(g.requestContext, g.query)
if err != nil {
return nil, err
}
return pools, nil
}