37 lines
757 B
Go
37 lines
757 B
Go
|
package builder
|
||
|
|
||
|
import (
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/endpoints"
|
||
|
"git.dragse.it/anthrove/e621-to-graph/pkg/e621/model"
|
||
|
"log"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type PostBuilder interface {
|
||
|
SetPostID(postID int) PostBuilder
|
||
|
Execute() (*model.Post, error)
|
||
|
}
|
||
|
|
||
|
func NewGetPostBuilder(requestContext model.RequestContext) PostBuilder {
|
||
|
return &getPost{requestContext: requestContext}
|
||
|
}
|
||
|
|
||
|
type getPost struct {
|
||
|
requestContext model.RequestContext
|
||
|
postID int
|
||
|
}
|
||
|
|
||
|
func (g *getPost) SetPostID(postID int) PostBuilder {
|
||
|
g.postID = postID
|
||
|
return g
|
||
|
}
|
||
|
|
||
|
func (g *getPost) Execute() (*model.Post, error) {
|
||
|
post, err := endpoints.GetPost(g.requestContext, strconv.Itoa(g.postID))
|
||
|
if err != nil {
|
||
|
log.Println(err)
|
||
|
return nil, err
|
||
|
}
|
||
|
return &post, nil
|
||
|
}
|