main return only one product for GetProductById

This commit is contained in:
Bastian de Byl
2023-05-12 10:46:54 -04:00
parent d56cf589da
commit f18e21f181

View File

@@ -297,7 +297,7 @@ func (s *Client) GetProducts(queries map[string]string) (*SnipcartProductsRespon
return &products, nil
}
func (s *Client) GetProductById(id string) (*SnipcartProductsResponse, error) {
func (s *Client) GetProductById(id string) (*SnipcartProduct, error) {
response, err := helper.Get(productsUri, "Basic", s.AuthBase64, map[string]string{"userDefinedId": id})
if err != nil {
return nil, err
@@ -314,5 +314,9 @@ func (s *Client) GetProductById(id string) (*SnipcartProductsResponse, error) {
return nil, err
}
return &products, nil
if len(products.Items) < 1 {
return nil, fmt.Errorf("no products with id '%s'", id)
}
return &products.Items[0], nil
}