feat: add missing endpoitn implementation
This commit is contained in:
45
client/retreats.go
Normal file
45
client/retreats.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/kratisto/tcgdex-golang/models"
|
||||
)
|
||||
|
||||
// Retreats retrieves all retreat costs.
|
||||
func (s *tcgDexClient) Retreats(ctx context.Context) ([]string, error) {
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, s.baseURL+"/retreats", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return doRequestSlice[string](s.httpClient, request)
|
||||
}
|
||||
|
||||
// GetCardsByRetreat retrieves all cards for a given retreat cost.
|
||||
func (s *tcgDexClient) GetCardsByRetreat(ctx context.Context, retreat string, params *FilterParams) ([]models.Card, error) {
|
||||
endpoint := s.baseURL + "/retreats/" + retreat
|
||||
urlParams := url.Values{}
|
||||
if params != nil {
|
||||
if params.Sort != "" {
|
||||
urlParams.Add("sort", params.Sort)
|
||||
}
|
||||
if params.Page > 0 {
|
||||
urlParams.Add("page", fmt.Sprintf("%d", params.Page))
|
||||
}
|
||||
if params.PageSize > 0 {
|
||||
urlParams.Add("pageSize", fmt.Sprintf("%d", params.PageSize))
|
||||
}
|
||||
}
|
||||
if len(urlParams) > 0 {
|
||||
endpoint += "?" + urlParams.Encode()
|
||||
}
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return doRequestSlice[models.Card](s.httpClient, request)
|
||||
}
|
||||
Reference in New Issue
Block a user