Skip to content

Commit

Permalink
make the inputs to bulk optional
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall committed Jul 7, 2024
1 parent 10d52d4 commit 38b86ef
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
17 changes: 11 additions & 6 deletions pointers.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package starr

// String returns a pointer to a string.
func String(s string) *string {
return &s
// Ptr returns a pointer to the provided "whatever".
func Ptr[P any](p P) *P {
return &p
}

// True returns a pointer to a true boolean.
func True() *bool {
s := true
return &s
return Ptr(true)
}

// False returns a pointer to a false boolean.
func False() *bool {
s := false
return Ptr(false)
}

// String returns a pointer to a string.
// Deprecated: Use Ptr() function instead.
func String(s string) *string {
return &s
}

// Int64 returns a pointer to the provided integer.
// Deprecated: Use Ptr() function instead.
func Int64(s int64) *int64 {
return &s
}
20 changes: 10 additions & 10 deletions prowlarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@ func (p *Prowlarr) DeleteIndexerContext(ctx context.Context, indexerID int64) er
return nil
}

// BulkIndexer is the input to UpdateIndexers.
// BulkIndexer is the input to UpdateIndexers. Use the starr.Ptr(any) func to create the pointers.
type BulkIndexer struct {
IDs []int64 `json:"ids"`
Tags []int `json:"tags"`
ApplyTags starr.ApplyTags `json:"applyTags"`
Enable bool `json:"enable"`
AppProfileID int64 `json:"appProfileId"`
Priority int64 `json:"priority"`
MinimumSeeders int `json:"minimumSeeders"`
SeedRatio int `json:"seedRatio"`
SeedTime int `json:"seedTime"`
PackSeedTime int `json:"packSeedTime"`
Tags []int `json:"tags,omitempty"`
ApplyTags starr.ApplyTags `json:"applyTags,omitempty"`
Enable *bool `json:"enable,omitempty"`
AppProfileID *int64 `json:"appProfileId,omitempty"`
Priority *int64 `json:"priority,omitempty"`
MinimumSeeders *int `json:"minimumSeeders,omitempty"`
SeedRatio *int `json:"seedRatio,omitempty"`
SeedTime *int `json:"seedTime,omitempty"`
PackSeedTime *int `json:"packSeedTime,omitempty"`
}

// UpdateIndexers bulk updates indexers.
Expand Down
8 changes: 4 additions & 4 deletions radarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ func (r *Radarr) DeleteIndexerContext(ctx context.Context, indexerID int64) erro
}

// UpdateIndexers bulk updates indexers.
func (r *Radarr) UpdateIndexers(indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (r *Radarr) UpdateIndexers(indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
return r.UpdateIndexersContext(context.Background(), indexer)
}

// UpdateIndexersContext bulk updates indexers.
func (r *Radarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (r *Radarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
var (
output IndexerOutput
output []*IndexerOutput
body bytes.Buffer
)

Expand All @@ -192,5 +192,5 @@ func (r *Radarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkI
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
return output, nil
}
8 changes: 4 additions & 4 deletions readarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ func (r *Readarr) DeleteIndexerContext(ctx context.Context, indexerID int64) err
}

// UpdateIndexers bulk updates indexers.
func (r *Readarr) UpdateIndexers(indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (r *Readarr) UpdateIndexers(indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
return r.UpdateIndexersContext(context.Background(), indexer)
}

// UpdateIndexersContext bulk updates indexers.
func (r *Readarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (r *Readarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
var (
output IndexerOutput
output []*IndexerOutput
body bytes.Buffer
)

Expand All @@ -190,5 +190,5 @@ func (r *Readarr) UpdateIndexersContext(ctx context.Context, indexer *starr.Bulk
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
return output, nil
}
13 changes: 7 additions & 6 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ const (
)

// BulkIndexer is the input to UpdateIndexers on all apps except Prowlarr.
// Use the starr.True/False/Int64() funcs to create the pointers.
type BulkIndexer struct {
IDs []int64 `json:"ids"`
Tags []int `json:"tags"`
ApplyTags ApplyTags `json:"applyTags"`
EnableRss bool `json:"enableRss"`
EnableAutomaticSearch bool `json:"enableAutomaticSearch"`
EnableInteractiveSearch bool `json:"enableInteractiveSearch"`
Priority int64 `json:"priority"`
Tags []int `json:"tags,omitempty"`
ApplyTags ApplyTags `json:"applyTags,omitempty"`
EnableRss *bool `json:"enableRss,omitempty"`
EnableAutomaticSearch *bool `json:"enableAutomaticSearch,omitempty"`
EnableInteractiveSearch *bool `json:"enableInteractiveSearch,omitempty"`
Priority *int64 `json:"priority,omitempty"`
}
8 changes: 4 additions & 4 deletions sonarr/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ func (s *Sonarr) DeleteIndexerContext(ctx context.Context, indexerID int64) erro
}

// UpdateIndexers bulk updates indexers.
func (s *Sonarr) UpdateIndexers(indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (s *Sonarr) UpdateIndexers(indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
return s.UpdateIndexersContext(context.Background(), indexer)
}

// UpdateIndexersContext bulk updates indexers.
func (s *Sonarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) (*IndexerOutput, error) {
func (s *Sonarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkIndexer) ([]*IndexerOutput, error) {
var (
output IndexerOutput
output []*IndexerOutput
body bytes.Buffer
)

Expand All @@ -196,5 +196,5 @@ func (s *Sonarr) UpdateIndexersContext(ctx context.Context, indexer *starr.BulkI
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}

return &output, nil
return output, nil
}

0 comments on commit 38b86ef

Please sign in to comment.