go-api-pkg/api/basket.go

38 lines
971 B
Go
Raw Normal View History

2022-12-25 21:39:20 +01:00
package api
import (
"fmt"
2024-12-24 17:59:01 +01:00
"git.ego.cloudns.be/egommerce/api-entities/basket"
basket "git.ego.cloudns.be/egommerce/api-entities/basket/dto"
2022-12-25 21:39:20 +01:00
"github.com/go-redis/redis/v8"
)
2022-12-25 22:59:04 +01:00
func NewBasketAPI(ua string, redis *redis.Client) *BasketAPI {
return &BasketAPI{NewHttpClient(ua, redis)}
2022-12-25 21:39:20 +01:00
}
type BasketAPI struct {
httpClient *HttpClient
}
2024-12-24 17:59:01 +01:00
func (a *BasketAPI) GetBasket(basketID string) (*basket.GetBasketResponseDTO, error) {
req := &basket.GetBasketRequestDTO{BasketID: basketID}
res := new(basket.GetBasketResponse)
2022-12-25 22:59:04 +01:00
if err := a.httpClient.SendGet("basket-svc", "/api/v1/basket", req, res); err != nil {
2022-12-25 21:39:20 +01:00
return nil, err
}
return res, nil
}
2024-12-24 17:59:01 +01:00
func (a *BasketAPI) GetBasketItems(basketID string) ([]*basket.GetBasketItemsResponseDTO, error) {
2022-12-25 21:39:20 +01:00
url := fmt.Sprintf("/api/v1/basket/%s/items", basketID)
2024-12-24 17:59:01 +01:00
var res []*basket.GetBasketItemsResponseDTO
2022-12-25 22:59:04 +01:00
if err := a.httpClient.SendGet("basket-svc", url, nil, &res); err != nil {
2022-12-25 21:39:20 +01:00
return nil, err
}
return res, nil
}