Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions readarr/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ type AddBookAuthor struct {

// AddAuthorOptions is part of AddBookAuthor.
type AddAuthorOptions struct {
SearchForMissingBooks bool `json:"searchForMissingBooks"`
Monitored bool `json:"monitored"`
Monitor string `json:"monitor"`
BooksToMonitor []int64 `json:"booksToMonitor"`
SearchForMissingBooks bool `json:"searchForMissingBooks"`
Monitored bool `json:"monitored"`
Monitor string `json:"monitor"`
BooksToMonitor []string `json:"booksToMonitor"`
}

// AddBookEdition is part of AddBookInput.
Expand Down
44 changes: 44 additions & 0 deletions readarr/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package readarr

import (
"context"
"fmt"
"net/url"

"golift.io/starr"
)

const bpSearch = APIver + "/search"

// SearchResult is the struct returned from the /api/v1/search endpoint.
// ID in this context means the index of the search result, not the book's ID.
type SearchResult struct {
ForeignID string `json:"foreignId,omitempty"`
Author *Author `json:"author,omitempty"`
Book *Book `json:"book,omitempty"`
ID int `json:"id,omitempty"`
}

// Search returns a slice of pointers to SearchResult.
func (r *Readarr) Search(term string) ([]*SearchResult, error) {
return r.SearchContext(context.Background(), term)
}

// SearchContext returns a slice of pointers to SearchResult.
func (r *Readarr) SearchContext(ctx context.Context, term string) ([]*SearchResult, error) {
var output []*SearchResult

if term == "" {
return output, nil
}

params := make(url.Values)
params.Set("term", term)

req := starr.Request{URI: bpSearch, Query: params}
if err := r.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}

return output, nil
}
Loading
Loading