Skip to content

Commit e60a3f1

Browse files
committed
add method for getting ozon warehouses workload
1 parent 2f1dbd5 commit e60a3f1

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

ozon/fbo.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,52 @@ func (c FBO) ListProductsInSupplyRequest(params *ListProductsInSupplyRequestPara
470470

471471
return resp, nil
472472
}
473+
474+
type GetWarehouseWorkloadResponse struct {
475+
core.CommonResponse
476+
477+
// Method result
478+
Result []struct {
479+
// Workload
480+
Schedule struct {
481+
// Data on the products quantity supplied to the warehouse
482+
Capacity []struct {
483+
// Period start, local time
484+
Start time.Time `json:"start"`
485+
486+
// Period end, local time
487+
End time.Time `json:"end"`
488+
489+
// Average number of products that the warehouse can accept per day for the period
490+
Value int32 `json:"value"`
491+
} `json:"capacity"`
492+
493+
// The closest available date for supply, local time
494+
Date time.Time `json:"date"`
495+
} `json:"schedule"`
496+
497+
// Warehouse
498+
Warehouse struct {
499+
// Warehouse identifier
500+
Id string `json:"id"`
501+
502+
// Warehouse name
503+
Name string `json:"name"`
504+
} `json:"warehouse"`
505+
} `json:"result"`
506+
}
507+
508+
// Method returns a list of active Ozon warehouses with information about their average workload in the nearest future
509+
func (c FBO) GetWarehouseWorkload() (*GetWarehouseWorkloadResponse, error) {
510+
url := "/v1/supplier/available_warehouses"
511+
512+
resp := &GetWarehouseWorkloadResponse{}
513+
514+
response, err := c.client.Request(http.MethodGet, url, nil, resp, nil)
515+
if err != nil {
516+
return nil, err
517+
}
518+
response.CopyCommonResponse(&resp.CommonResponse)
519+
520+
return resp, nil
521+
}

ozon/fbo_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,61 @@ func TestListProductsInSupplyRequest(t *testing.T) {
482482
}
483483
}
484484
}
485+
486+
func TestGetWarehouseWorkload(t *testing.T) {
487+
t.Parallel()
488+
489+
tests := []struct {
490+
statusCode int
491+
headers map[string]string
492+
response string
493+
}{
494+
// Test Ok
495+
{
496+
http.StatusOK,
497+
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
498+
`{
499+
"result": [
500+
{
501+
"schedule": {
502+
"capacity": [
503+
{
504+
"start": "2019-08-24T14:15:22Z",
505+
"end": "2019-08-24T14:15:22Z",
506+
"value": 0
507+
}
508+
],
509+
"date": "2019-08-24T14:15:22Z"
510+
},
511+
"warehouse": {
512+
"id": "string",
513+
"name": "string"
514+
}
515+
}
516+
]
517+
}`,
518+
},
519+
// Test No Client-Id or Api-Key
520+
{
521+
http.StatusUnauthorized,
522+
map[string]string{},
523+
`{
524+
"code": 16,
525+
"message": "Client-Id and Api-Key headers are required"
526+
}`,
527+
},
528+
}
529+
530+
for _, test := range tests {
531+
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
532+
533+
resp, err := c.FBO().GetWarehouseWorkload()
534+
if err != nil {
535+
t.Error(err)
536+
}
537+
538+
if resp.StatusCode != test.statusCode {
539+
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
540+
}
541+
}
542+
}

0 commit comments

Comments
 (0)