38 lines
971 B
Go
38 lines
971 B
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.ego.cloudns.be/egommerce/api-entities/basket"
|
|
basket "git.ego.cloudns.be/egommerce/api-entities/basket/dto"
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
func NewBasketAPI(ua string, redis *redis.Client) *BasketAPI {
|
|
return &BasketAPI{NewHttpClient(ua, redis)}
|
|
}
|
|
|
|
type BasketAPI struct {
|
|
httpClient *HttpClient
|
|
}
|
|
|
|
func (a *BasketAPI) GetBasket(basketID string) (*basket.GetBasketResponseDTO, error) {
|
|
req := &basket.GetBasketRequestDTO{BasketID: basketID}
|
|
res := new(basket.GetBasketResponse)
|
|
if err := a.httpClient.SendGet("basket-svc", "/api/v1/basket", req, res); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (a *BasketAPI) GetBasketItems(basketID string) ([]*basket.GetBasketItemsResponseDTO, error) {
|
|
url := fmt.Sprintf("/api/v1/basket/%s/items", basketID)
|
|
var res []*basket.GetBasketItemsResponseDTO
|
|
if err := a.httpClient.SendGet("basket-svc", url, nil, &res); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|