45 lines
1.0 KiB
Go
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
|
|
}
|