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 FavoritesBuilder interface { SetUserID(userID model.UserID) FavoritesBuilder SetLimit(limitFavorites int) FavoritesBuilder Page(number int) FavoritesBuilder Execute() ([]model.Post, error) } func NewGetFavoritesBuilder(requestContext model.RequestContext) FavoritesBuilder { return &getFavorites{ requestContext: requestContext, query: make(map[string]string), } } type getFavorites struct { query map[string]string requestContext model.RequestContext } func (g *getFavorites) SetUserID(userID model.UserID) FavoritesBuilder { g.query["user_id"] = strconv.Itoa(int(userID)) return g } func (g *getFavorites) SetLimit(limitFavorites int) FavoritesBuilder { g.query["limit"] = strconv.Itoa(limitFavorites) return g } func (g *getFavorites) Page(pageNumber int) FavoritesBuilder { g.query["page"] = strconv.Itoa(pageNumber) return g } func (g *getFavorites) Execute() ([]model.Post, error) { if g.requestContext.RateLimiter != nil { err := g.requestContext.RateLimiter.Wait(context.Background()) if err != nil { return nil, err } } favorites, err := endpoints.GetFavorites(g.requestContext, g.query) if err != nil { return nil, err } return favorites, nil }