87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package builder
|
|
|
|
import (
|
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
|
|
"git.dragse.it/anthrove/e621-to-graph/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) {
|
|
pools, err := endpoints.GetPools(g.requestContext, g.query)
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
}
|
|
return pools, nil
|
|
}
|