Skip to content

Commit

Permalink
add list warehouses
Browse files Browse the repository at this point in the history
  • Loading branch information
diPhantxm committed Dec 14, 2024
1 parent 8119ff6 commit a43bab3
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ozon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ const (
Sun WorkingDay = 7
)

type WorkingDayStr string

const (
MonStr WorkingDayStr = "1"
TueStr WorkingDayStr = "2"
WedStr WorkingDayStr = "3"
ThuStr WorkingDayStr = "4"
FriStr WorkingDayStr = "5"
SatStr WorkingDayStr = "6"
SunStr WorkingDayStr = "7"
)

type GetAnalyticsDataDimension string

const (
Expand Down
78 changes: 76 additions & 2 deletions ozon/warehouses.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type GetListOfWarehousesResult struct {
CanPrintActInAdvance bool `json:"can_print_act_in_advance"`

// FBS first mile
FirstMileType GetListOfWarehousesResultFirstMile `json:"first_mile_type"`
FirstMileType FirstMile `json:"first_mile_type"`

// Indication if there is a limit on the minimum number of orders. `true` if there is such a limit
HasPostingsLimit bool `json:"has_postings_limit"`
Expand Down Expand Up @@ -67,7 +67,7 @@ type GetListOfWarehousesResult struct {
WorkingDays []WorkingDay `json:"working_days"`
}

type GetListOfWarehousesResultFirstMile struct {
type FirstMile struct {
// DropOff point identifier
DropoffPointId string `json:"dropoff_point_id"`

Expand Down Expand Up @@ -244,3 +244,77 @@ func (c Warehouses) ListForShipping(ctx context.Context, params *ListForShipping

return resp, nil
}

type ListWarehousesResponse struct {
core.CommonResponse

// Warehouses list
Result []ListWarehousesResult `json:"result"`
}

type ListWarehousesResult struct {
// Trusted acceptance attribute. true if trusted acceptance is enabled in the warehouse
HasEntrustedAcceptance bool `json:"has_entrusted_acceptance"`

// Indication that the warehouse works under the rFBS scheme:
//
// true — the warehouse works under the rFBS scheme;
// false — the warehouse doesn't work under the rFBS scheme
IsRFBS bool `json:"is_rfbs"`

// Warehouse name
Name string `json:"name"`

// Warehouse identifier
WarehouseId int64 `json:"warehouse_id"`

// Possibility to print an acceptance certificate in advance. true if printing in advance is possible
CanPrintActInAdvance bool `json:"can_print_act_in_advance"`

// FBS first mile
FirstMileType FirstMile `json:"first_mile_type"`

// Indication if there is a limit on the minimum number of orders. true if there is such a limit
HasPostingsLimit bool `json:"has_postings_limit"`

// Indication that the warehouse is not working due to quarantine
IsKarantin bool `json:"is_karantin"`

// Indication that the warehouse accepts bulky products
IsKGT bool `json:"is_kgt"`

// true if the warehouse handles economy products
IsEconomy bool `json:"is_economy"`

// Indication that warehouse schedule can be changed
IsTimetableEditable bool `json:"is_timetable_editable"`

// Minimum limit value: the number of orders that can be brought in one shipment
MinPostingsLimit int32 `json:"min_postings_limit"`

// Limit value. -1 if there is no limit
PostingsLimit int32 `json:"postings_limit"`

// Number of warehouse working days
MinWorkingDays int64 `json:"min_working_days"`

// Warehouse status
Status string `json:"status"`

// Warehouse working days
WorkingDays []WorkingDayStr `json:"working_days"`
}

func (c Warehouses) List(ctx context.Context) (*ListWarehousesResponse, error) {
url := "/v1/warehouse/list"

resp := &ListWarehousesResponse{}

response, err := c.client.Request(ctx, http.MethodPost, url, nil, resp, nil)
if err != nil {
return nil, err
}
response.CopyCommonResponse(&resp.CommonResponse)

return resp, nil
}
71 changes: 71 additions & 0 deletions ozon/warehouses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,74 @@ func TestListForShipping(t *testing.T) {
}
}
}

func TestListWarehouses(t *testing.T) {
t.Parallel()

tests := []struct {
statusCode int
headers map[string]string
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
`{
"result": [
{
"has_entrusted_acceptance": true,
"is_rfbs": true,
"name": "string",
"warehouse_id": 0,
"can_print_act_in_advance": true,
"first_mile_type": {
"dropoff_point_id": "string",
"dropoff_timeslot_id": 0,
"first_mile_is_changing": true,
"first_mile_type": "DropOff"
},
"has_postings_limit": true,
"is_karantin": true,
"is_kgt": true,
"is_economy": true,
"is_timetable_editable": true,
"min_postings_limit": 0,
"postings_limit": 0,
"min_working_days": 0,
"status": "string",
"working_days": [
"1"
]
}
]
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
`{
"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))

ctx, _ := context.WithTimeout(context.Background(), testTimeout)
resp, err := c.Warehouses().List(ctx)
if err != nil {
t.Error(err)
continue
}

compareJsonResponse(t, test.response, &ListWarehousesResponse{})

if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}

0 comments on commit a43bab3

Please sign in to comment.