2023-10-23 12:27:20 +00:00
|
|
|
package builder
|
|
|
|
|
|
|
|
import (
|
2023-10-24 13:10:39 +00:00
|
|
|
"context"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
2023-10-23 12:27:20 +00:00
|
|
|
"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) {
|
2023-10-24 13:10:39 +00:00
|
|
|
if g.requestContext.RateLimiter != nil {
|
|
|
|
err := g.requestContext.RateLimiter.Wait(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2023-10-23 12:27:20 +00:00
|
|
|
pools, err := endpoints.GetPools(g.requestContext, g.query)
|
|
|
|
if err != nil {
|
2023-10-24 08:35:33 +00:00
|
|
|
|
2023-10-23 12:27:20 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return pools, nil
|
|
|
|
}
|