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/note.go
SoXX 9cee99ecb5 docs: added more & unified documentation format
Signed-off-by: SoXX <soxx@fenpa.ws>
2023-11-15 14:37:44 +01:00

65 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"
)
// NoteBuilder represents a builder for constructing queries to retrieve a specific note.
type NoteBuilder interface {
// SetNoteID sets the note ID for the query.
SetNoteID(noteID int) NoteBuilder
// Execute sends the constructed query and returns the requested note and an error, if any.
Execute() (*model.Note, error)
}
// NewGetNoteBuilder creates a new instance of NoteBuilder with the provided RequestContext.
//
// Parameters:
// - requestContext: The context for the API request, including the host, user agent, username, and API key.
//
// Returns:
// - NoteBuilder: An instance of the NoteBuilder interface.
func NewGetNoteBuilder(requestContext model.RequestContext) NoteBuilder {
return &getNote{requestContext: requestContext}
}
// getNote is an implementation of the NoteBuilder interface.
type getNote struct {
requestContext model.RequestContext
noteID int
}
// SetNoteID sets the note ID for the query.
//
// Parameters:
// - noteID: The ID of the note to be retrieved.
//
// Returns:
// - NoteBuilder: The instance of the NoteBuilder for method chaining.
func (g *getNote) SetNoteID(noteID int) NoteBuilder {
g.noteID = noteID
return g
}
// Execute sends the constructed query and returns the requested note and an error, if any.
//
// Returns:
// - *model.Note: The requested note.
// - error: An error, if any, encountered during the API request or response handling.
func (g *getNote) Execute() (*model.Note, error) {
if g.requestContext.RateLimiter != nil {
err := g.requestContext.RateLimiter.Wait(context.Background())
if err != nil {
return nil, err
}
}
note, err := endpoints.GetNote(g.requestContext, strconv.Itoa(g.noteID))
if err != nil {
return nil, err
}
return &note, nil
}