diff --git a/internal/client/order.go b/internal/client/order.go index 6662f2a..bed5803 100644 --- a/internal/client/order.go +++ b/internal/client/order.go @@ -10,32 +10,36 @@ import ( "strconv" ) -type OrderClient struct { +type OrderClient interface { + CheckOrder(OrderNum string) (services.OrderFromAccrual, int, error) +} + +type OrderClientService struct { logger *zap.Logger accrualSystemAddress string } -func NewOrderClient(opts ...func(*OrderClient)) *OrderClient { - orderClient := &OrderClient{} +func NewOrderClient(opts ...func(*OrderClientService)) *OrderClientService { + orderClient := &OrderClientService{} for _, opt := range opts { opt(orderClient) } return orderClient } -func WithLogger(logger *zap.Logger) func(*OrderClient) { - return func(o *OrderClient) { +func WithLogger(logger *zap.Logger) func(*OrderClientService) { + return func(o *OrderClientService) { o.logger = logger } } -func WithAccrualSystemAddress(accrualSystemAddress string) func(*OrderClient) { - return func(o *OrderClient) { +func WithAccrualSystemAddress(accrualSystemAddress string) func(*OrderClientService) { + return func(o *OrderClientService) { o.accrualSystemAddress = accrualSystemAddress } } -func (c OrderClient) CheckOrder(OrderNum string) (services.OrderFromAccrual, int, error) { +func (c OrderClientService) CheckOrder(OrderNum string) (services.OrderFromAccrual, int, error) { data := services.OrderFromAccrual{} resp, err := http.Get(c.accrualSystemAddress + "/api/orders/" + OrderNum) if err != nil { diff --git a/internal/workers/order.go b/internal/workers/order.go index a3190a1..a6703af 100644 --- a/internal/workers/order.go +++ b/internal/workers/order.go @@ -16,7 +16,7 @@ type OrderWorker struct { orderQueue chan string logger *zap.Logger conf config.Config - orderClient *client.OrderClient + orderClient client.OrderClient } func NewOrderWorker(opts ...func(*OrderWorker)) *OrderWorker { @@ -59,7 +59,7 @@ func WithConfig(conf config.Config) func(*OrderWorker) { } } -func WithOrderClient(orderClient *client.OrderClient) func(*OrderWorker) { +func WithOrderClient(orderClient client.OrderClient) func(*OrderWorker) { return func(o *OrderWorker) { o.orderClient = orderClient }