Skip to content

Commit 61a78b1

Browse files
authored
Methods to manage Passes (Update April 1, 2024) (#76)
1 parent 97a9d2a commit 61a78b1

File tree

7 files changed

+1066
-0
lines changed

7 files changed

+1066
-0
lines changed

ozon/fbs.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,3 +2902,96 @@ func (c FBS) CreateOrGetProductExemplar(ctx context.Context, params *CreateOrGet
29022902

29032903
return resp, nil
29042904
}
2905+
2906+
type GetCarriageParams struct {
2907+
CarriageId int64 `json:"carriage_id"`
2908+
}
2909+
2910+
type GetCarriageResponse struct {
2911+
core.CommonResponse
2912+
2913+
// Acceptance certificate type for FBS sellers
2914+
ActType string `json:"act_type"`
2915+
2916+
// Pass identifiers for the freight
2917+
ArrivalPassIds []string `json:"arrival_pass_ids"`
2918+
2919+
// List of available actions on the freight
2920+
AvailableActions []string `json:"available_actions"`
2921+
2922+
// Cancel availability
2923+
CancelAvailability GetCarriageCancelAvailability `json:"cancel_availability"`
2924+
2925+
// Freight identifier
2926+
CarriageId int64 `json:"carriage_id"`
2927+
2928+
// Company identifier
2929+
CompanyId int64 `json:"company_id"`
2930+
2931+
// Number of package units
2932+
ContainersCount int32 `json:"containers_count"`
2933+
2934+
// Date and time of freight creation
2935+
CreatedAt time.Time `json:"created_at"`
2936+
2937+
// Delivery method identifier
2938+
DeliveryMethodId int64 `json:"delivery_method_id"`
2939+
2940+
// Shipping date
2941+
DepartureDate string `json:"departure_date"`
2942+
2943+
// First mile type
2944+
FirstMileType string `json:"first_mile_type"`
2945+
2946+
// true if there are shipments subject to shipping that are not in the current freight
2947+
HasPostingsForNextCarriage bool `json:"has_postings_for_next_carriage"`
2948+
2949+
// Delivery service integration type
2950+
IntegrationType string `json:"integration_type"`
2951+
2952+
// true if you already printed shipping labels
2953+
IsContainerLabelPrinted bool `json:"is_container_label_printed"`
2954+
2955+
// true if the freight is partial
2956+
IsPartial bool `json:"is_partial"`
2957+
2958+
// Serial number of the partial freight
2959+
PartialNum int64 `json:"partial_num"`
2960+
2961+
// The number of retries to create a freight
2962+
RetryCount int32 `json:"retry_count"`
2963+
2964+
// Freight status
2965+
Status string `json:"status"`
2966+
2967+
// Delivery method identifier
2968+
TPLProviderId int64 `json:"tpl_provider_id"`
2969+
2970+
// Date and time when the freight was last updated
2971+
UpdatedAt time.Time `json:"updated_at"`
2972+
2973+
// Warehouse identifier
2974+
WarehouseId int64 `json:"warehouse_id"`
2975+
}
2976+
2977+
type GetCarriageCancelAvailability struct {
2978+
// true if the freight can be cancelled
2979+
IsCancelAvailable bool `json:"is_cancel_available"`
2980+
2981+
// Reason why freight can't be cancelled
2982+
Reason string `json:"reason"`
2983+
}
2984+
2985+
func (c FBS) GetCarriage(ctx context.Context, params *GetCarriageParams) (*GetCarriageResponse, error) {
2986+
url := "/v1/carriage/get"
2987+
2988+
resp := &GetCarriageResponse{}
2989+
2990+
response, err := c.client.Request(ctx, http.MethodPost, url, params, resp, nil)
2991+
if err != nil {
2992+
return nil, err
2993+
}
2994+
response.CopyCommonResponse(&resp.CommonResponse)
2995+
2996+
return resp, nil
2997+
}

ozon/fbs_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,3 +2919,84 @@ func TestCreateOrGetProductExemplar(t *testing.T) {
29192919
}
29202920
}
29212921
}
2922+
2923+
func TestGetCarriage(t *testing.T) {
2924+
t.Parallel()
2925+
2926+
tests := []struct {
2927+
statusCode int
2928+
headers map[string]string
2929+
params *GetCarriageParams
2930+
response string
2931+
}{
2932+
// Test Ok
2933+
{
2934+
http.StatusOK,
2935+
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
2936+
&GetCarriageParams{
2937+
CarriageId: 15,
2938+
},
2939+
`{
2940+
"act_type": "string",
2941+
"arrival_pass_ids": [
2942+
"string"
2943+
],
2944+
"available_actions": [
2945+
"string"
2946+
],
2947+
"cancel_availability": {
2948+
"is_cancel_available": true,
2949+
"reason": "string"
2950+
},
2951+
"carriage_id": 15,
2952+
"company_id": 0,
2953+
"containers_count": 0,
2954+
"created_at": "2019-08-24T14:15:22Z",
2955+
"delivery_method_id": 0,
2956+
"departure_date": "string",
2957+
"first_mile_type": "string",
2958+
"has_postings_for_next_carriage": true,
2959+
"integration_type": "string",
2960+
"is_container_label_printed": true,
2961+
"is_partial": true,
2962+
"partial_num": 0,
2963+
"retry_count": 0,
2964+
"status": "string",
2965+
"tpl_provider_id": 0,
2966+
"updated_at": "2019-08-24T14:15:22Z",
2967+
"warehouse_id": 0
2968+
}`,
2969+
},
2970+
// Test No Client-Id or Api-Key
2971+
{
2972+
http.StatusUnauthorized,
2973+
map[string]string{},
2974+
&GetCarriageParams{},
2975+
`{
2976+
"code": 16,
2977+
"message": "Client-Id and Api-Key headers are required"
2978+
}`,
2979+
},
2980+
}
2981+
2982+
for _, test := range tests {
2983+
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
2984+
2985+
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
2986+
resp, err := c.FBS().GetCarriage(ctx, test.params)
2987+
if err != nil {
2988+
t.Error(err)
2989+
continue
2990+
}
2991+
2992+
compareJsonResponse(t, test.response, &GetCarriageResponse{})
2993+
2994+
if resp.StatusCode != test.statusCode {
2995+
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
2996+
}
2997+
2998+
if resp.CarriageId != test.params.CarriageId {
2999+
t.Errorf("carriage id in request and response should be equal")
3000+
}
3001+
}
3002+
}

ozon/ozon.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Client struct {
4141
certificates *Certificates
4242
strategies *Strategies
4343
barcodes *Barcodes
44+
passes *Passes
4445
}
4546

4647
func (c Client) Analytics() *Analytics {
@@ -119,6 +120,10 @@ func (c Client) Barcodes() *Barcodes {
119120
return c.barcodes
120121
}
121122

123+
func (c Client) Passes() *Passes {
124+
return c.passes
125+
}
126+
122127
type ClientOption func(c *ClientOptions)
123128

124129
func WithHttpClient(httpClient core.HttpClient) ClientOption {
@@ -182,6 +187,7 @@ func NewClient(opts ...ClientOption) *Client {
182187
certificates: &Certificates{client: coreClient},
183188
strategies: &Strategies{client: coreClient},
184189
barcodes: &Barcodes{client: coreClient},
190+
passes: &Passes{client: coreClient},
185191
}
186192
}
187193

@@ -209,5 +215,6 @@ func NewMockClient(handler http.HandlerFunc) *Client {
209215
certificates: &Certificates{client: coreClient},
210216
strategies: &Strategies{client: coreClient},
211217
barcodes: &Barcodes{client: coreClient},
218+
passes: &Passes{client: coreClient},
212219
}
213220
}

0 commit comments

Comments
 (0)