add List of delivery methods for a warehouse

This commit is contained in:
diPhantxm
2023-03-15 03:20:12 +03:00
parent be5b4a7119
commit 852576d520
3 changed files with 152 additions and 1 deletions

View File

@@ -71,7 +71,7 @@
## Warehouses ## Warehouses
- [x] List of warehouses - [x] List of warehouses
- [ ] List of delivery methods for a warehouse - [x] List of delivery methods for a warehouse
## Polygons ## Polygons
- [ ] Create delivery polygon - [ ] Create delivery polygon

View File

@@ -2,6 +2,7 @@ package ozon
import ( import (
"net/http" "net/http"
"time"
core "github.com/diphantxm/ozon-api-client" core "github.com/diphantxm/ozon-api-client"
) )
@@ -89,3 +90,91 @@ func (c Client) GetListOfWarehouses() (*GetListOfWarehousesResponse, error) {
return resp, nil return resp, nil
} }
type GetListOfDeliveryMethodsParams struct {
// Search filter for delivery methods
Filter GetListOfDeliveryMethodsFilter `json:"filter"`
// Number of items in a response. Maximum is 50, minimum is 1
Limit int64 `json:"limit"`
// Number of elements that will be skipped in the response.
// For example, if offset=10, the response will start with the 11th element found
Offset int64 `json:"offset"`
}
type GetListOfDeliveryMethodsFilter struct {
// Delivery service identifier
ProviderId int64 `json:"provider_id"`
// Delivery method status:
// - NEW—created
// - EDITED—being edited
// - ACTIVE—active
// - DISABLED—inactive
Status string `json:"status"`
// Warehouse identifier
WarehouseId int64 `json:"warehouse_id"`
}
type GetListOfDeliveryMethodsResponse struct {
core.CommonResponse
// Indication that only part of delivery methods was returned in the response:
// - true — make a request with a new offset parameter value for getting the rest of delivery methods;
// - false — all delivery methods were returned
HasNext bool `json:"has_next"`
// Method result
Result []struct {
// Company identifier
CompanyId int64 `json:"company_id"`
// Date and time of delivery method creation
CreatedAt time.Time `json:"created_at"`
// Time before an order must be packaged
Cutoff string `json:"cutoff"`
// Delivery method identifier
Id int64 `json:"id"`
// Delivery method name
Name string `json:"name"`
// Delivery service identifier
ProviderId int64 `json:"provider_id"`
// Delivery method status:
// - NEW—created,
// - EDITED—being edited,
// - ACTIVE—active,
// - DISABLED—inactive
Status string `json:"status"`
// Order delivery service identifier
TemplateId int64 `json:"template_id"`
// Date and time when the delivery method was last updated
UpdatedAt time.Time `json:"updated_at"`
// Warehouse identifier
WarehouseId int64 `json:"warehouse_id"`
} `json:"result"`
}
// This methods allows you to get list of all delivery methods that can be applied for this warehouse
func (c Client) GetListOfDeliveryMethods(params *GetListOfDeliveryMethodsParams) (*GetListOfDeliveryMethodsResponse, error) {
url := "/v1/delivery-method/list"
resp := &GetListOfDeliveryMethodsResponse{}
response, err := c.client.Request(http.MethodPost, url, nil, resp)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)
return resp, nil
}

View File

@@ -66,3 +66,65 @@ func TestGetListOfWarehouses(t *testing.T) {
} }
} }
} }
func TestGetListOfDeliveryMethods(t *testing.T) {
tests := []struct {
statusCode int
headers map[string]string
params *GetListOfDeliveryMethodsParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&GetListOfDeliveryMethodsParams{
Filter: GetListOfDeliveryMethodsFilter{
WarehouseId: 15588127982000,
},
Limit: 100,
Offset: 0,
},
`{
"result": [
{
"id": 15588127982000,
"company_id": 1,
"name": "Ozon Логистика курьеру, Есипово",
"status": "ACTIVE",
"cutoff": "13:00",
"provider_id": 24,
"template_id": 0,
"warehouse_id": 15588127982000,
"created_at": "2019-04-04T15:22:31.048202Z",
"updated_at": "2021-08-15T10:21:44.854209Z"
}
],
"has_next": false
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&GetListOfDeliveryMethodsParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.GetListOfDeliveryMethods(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}