Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Пешков Дмитрий committed Sep 24, 2024
1 parent b51a74d commit 91118ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions internal/client/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/workers/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 91118ca

Please sign in to comment.