2023-10-23 13:35:36 +00:00
|
|
|
package builder
|
|
|
|
|
|
|
|
import (
|
2023-10-24 13:10:39 +00:00
|
|
|
"context"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/endpoints"
|
|
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
|
2023-10-23 13:35:36 +00:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NotesBuilder interface {
|
|
|
|
SearchInBody(body string) NotesBuilder
|
|
|
|
NoteID(noteID int) NotesBuilder
|
|
|
|
SearchTags(tags string) NotesBuilder
|
|
|
|
SearchCreatorID(creatorID int) NotesBuilder
|
|
|
|
searchCreatorName(creatorName string) NotesBuilder
|
|
|
|
Active(isActive bool) NotesBuilder
|
|
|
|
SetLimit(limitNotes int) NotesBuilder
|
|
|
|
Execute() ([]model.Note, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetNotesBuilder(requestContext model.RequestContext) NotesBuilder {
|
|
|
|
return &getNotes{
|
|
|
|
requestContext: requestContext,
|
|
|
|
query: make(map[string]string),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type getNotes struct {
|
|
|
|
requestContext model.RequestContext
|
|
|
|
query map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) SearchInBody(body string) NotesBuilder {
|
|
|
|
g.query["search[body_matches]"] = body
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) NoteID(noteID int) NotesBuilder {
|
|
|
|
g.query["search[post_id]"] = strconv.Itoa(noteID)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) SearchTags(tags string) NotesBuilder {
|
|
|
|
g.query["search[post_tags_match]"] = tags
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) SearchCreatorID(creatorID int) NotesBuilder {
|
|
|
|
g.query["search[creator_id]"] = strconv.Itoa(creatorID)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) searchCreatorName(creatorName string) NotesBuilder {
|
|
|
|
g.query["search[creator_name]"] = creatorName
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) Active(isActive bool) NotesBuilder {
|
|
|
|
g.query["search[is_active]"] = strconv.FormatBool(isActive)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) SetLimit(limitNotes int) NotesBuilder {
|
|
|
|
g.query["limit"] = strconv.Itoa(limitNotes)
|
|
|
|
return g
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g getNotes) Execute() ([]model.Note, error) {
|
2023-10-24 13:10:39 +00:00
|
|
|
if g.requestContext.RateLimiter != nil {
|
|
|
|
err := g.requestContext.RateLimiter.Wait(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
2023-10-23 13:35:36 +00:00
|
|
|
notes, err := endpoints.GetNotes(g.requestContext, g.query)
|
|
|
|
if err != nil {
|
2023-10-24 08:35:33 +00:00
|
|
|
|
2023-10-23 13:35:36 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return notes, nil
|
|
|
|
}
|