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/favorite.go
2023-10-24 10:35:33 +02:00

45 lines
1.0 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 FavoritesBuilder interface {
SetUserID(userID int) FavoritesBuilder
SetLimit(limitFavorites 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 int) FavoritesBuilder {
g.query["user_id"] = strconv.Itoa(userID)
return g
}
func (g getFavorites) SetLimit(limitFavorites int) FavoritesBuilder {
g.query["limit"] = strconv.Itoa(limitFavorites)
return g
}
func (g getFavorites) Execute() ([]model.Post, error) {
favorites, err := endpoints.GetFavorites(g.requestContext, g.query)
if err != nil {
return nil, err
}
return favorites, nil
}