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/notes.go
2023-10-24 15:10:39 +02:00

82 lines
1.9 KiB
Go

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 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) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
}
}
notes, err := endpoints.GetNotes(g.requestContext, g.query)
if err != nil {
return nil, err
}
return notes, nil
}