fix/change string to time.Time where possible

This commit is contained in:
diPhantxm
2023-03-12 23:11:00 +03:00
parent ca40ab4559
commit c9a0f83145
5 changed files with 165 additions and 174 deletions

View File

@@ -82,9 +82,9 @@ func (c Client) Request(method string, path string, req, resp interface{}) (*Res
response.Data = resp response.Data = resp
response.StatusCode = httpResp.StatusCode response.StatusCode = httpResp.StatusCode
if httpResp.StatusCode == http.StatusOK { if httpResp.StatusCode == http.StatusOK {
err = json.Unmarshal(body, &response)
} else {
err = json.Unmarshal(body, &response.Data) err = json.Unmarshal(body, &response.Data)
} else {
err = json.Unmarshal(body, &response)
} }
if err != nil { if err != nil {
return nil, err return nil, err

10
core.go
View File

@@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"reflect" "reflect"
"testing"
"time"
) )
type CommonResponse struct { type CommonResponse struct {
@@ -99,3 +101,11 @@ func isZero(v interface{}) (bool, error) {
} }
return v == reflect.Zero(t).Interface(), nil return v == reflect.Zero(t).Interface(), nil
} }
func TimeFromString(t *testing.T, datetime string) time.Time {
dt, err := time.Parse("2006-01-02T15:04:05Z", datetime)
if err != nil {
t.Errorf("error when parsing time: %s", err)
}
return dt
}

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"
) )
@@ -15,14 +16,14 @@ type ListUnprocessedShipmentsParams struct {
} }
type ListUnprocessedShipmentsFilter struct { type ListUnprocessedShipmentsFilter struct {
CutoffFrom string `json:"cutoff_from"` CutoffFrom time.Time `json:"cutoff_from"`
CutoffTo string `json:"cutoff_to"` CutoffTo time.Time `json:"cutoff_to"`
DeliveringDateFrom string `json:"delivering_date_from"` DeliveringDateFrom time.Time `json:"delivering_date_from"`
DeliveringDateTo string `json:"delivering_date_to"` DeliveringDateTo time.Time `json:"delivering_date_to"`
DeliveryMethodId []int64 `json:"deliveryMethodId"` DeliveryMethodId []int64 `json:"deliveryMethodId"`
ProviderId []int64 `json:"provider_id"` ProviderId []int64 `json:"provider_id"`
Status string `json:"status"` Status string `json:"status"`
WarehouseId []int64 `json:"warehouse_id"` WarehouseId []int64 `json:"warehouse_id"`
} }
type ListUnprocessedShipmentsWith struct { type ListUnprocessedShipmentsWith struct {
@@ -50,18 +51,18 @@ type ListUnprocessedShipmentsPosting struct {
} `json:"addressee"` } `json:"addressee"`
AnalyticsData struct { AnalyticsData struct {
City string `json:"city"` City string `json:"city"`
DeliveryDateBegin string `json:"delivery_date_begin"` DeliveryDateBegin time.Time `json:"delivery_date_begin"`
DeliveryDateEnd string `json:"delivery_date_end"` DeliveryDateEnd time.Time `json:"delivery_date_end"`
DeliveryType string `json:"delivery_type"` DeliveryType string `json:"delivery_type"`
IsLegal bool `json:"is_legal"` IsLegal bool `json:"is_legal"`
IsPremium bool `json:"is_premium"` IsPremium bool `json:"is_premium"`
PaymentTypeGroupName string `json:"payment_type_group_name"` PaymentTypeGroupName string `json:"payment_type_group_name"`
Region string `json:"region"` Region string `json:"region"`
TPLProvider string `json:"tpl_provider"` TPLProvider string `json:"tpl_provider"`
TPLProviderId int64 `json:"tpl_provider_id"` TPLProviderId int64 `json:"tpl_provider_id"`
Warehouse string `json:"warehouse"` Warehouse string `json:"warehouse"`
WarehouseId int64 `json:"warehouse_id"` WarehouseId int64 `json:"warehouse_id"`
} `json:"analytics_data"` } `json:"analytics_data"`
Barcodes struct { Barcodes struct {
@@ -85,7 +86,7 @@ type ListUnprocessedShipmentsPosting struct {
Comment string `json:"comment"` Comment string `json:"comment"`
Country string `json:"country"` Country string `json:"country"`
District string `json:"district"` District string `json:"district"`
Latitude float64 `json:'latitude"` Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"` Longitude float64 `json:"longitude"`
ProviderPVZCode string `json:"provider_pvz_code"` ProviderPVZCode string `json:"provider_pvz_code"`
PVZCode int64 `json:"pvz_code"` PVZCode int64 `json:"pvz_code"`
@@ -99,7 +100,8 @@ type ListUnprocessedShipmentsPosting struct {
Phone string `json:"phone"` Phone string `json:"phone"`
} `json:"customer"` } `json:"customer"`
DeliveringDate string `json:"delivering_date"` DeliveringDate time.Time `json:"delivering_date"`
DeliveryMethod struct { DeliveryMethod struct {
Id int64 `json:"id"` Id int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
@@ -125,9 +127,9 @@ type ListUnprocessedShipmentsPosting struct {
OldPrice float64 `json:"old_price"` OldPrice float64 `json:"old_price"`
Payout float64 `json:"payout"` Payout float64 `json:"payout"`
Picking struct { Picking struct {
Amount float64 `json:"amount"` Amount float64 `json:"amount"`
Moment string `json:"moment"` Moment time.Time `json:"moment"`
Tag string `json:"tag"` Tag string `json:"tag"`
} `json:"picking"` } `json:"picking"`
Price float64 `json:"price"` Price float64 `json:"price"`
ProductId int64 `json:"product_id"` ProductId int64 `json:"product_id"`
@@ -137,16 +139,16 @@ type ListUnprocessedShipmentsPosting struct {
} `json:"products"` } `json:"products"`
} }
InProccessAt string `json:"in_process_at"` InProccessAt time.Time `json:"in_process_at"`
IsExpress bool `json:"is_express"` IsExpress bool `json:"is_express"`
IsMultibox bool `json:"is_multibox"` IsMultibox bool `json:"is_multibox"`
MultiBoxQuantity int32 `json:"multi_box_qty"` MultiBoxQuantity int32 `json:"multi_box_qty"`
OrderId int64 `json:"order_id"` OrderId int64 `json:"order_id"`
OrderNumber string `json:"order_number"` OrderNumber string `json:"order_number"`
ParentPostingNumber string `json:"parent_posting_number"` ParentPostingNumber string `json:"parent_posting_number"`
PostingNumber string `json:"posting_number"` PostingNumber string `json:"posting_number"`
Products struct { Products []struct {
MandatoryMark []string `json:"mandatory_mark"` MandatoryMark []string `json:"mandatory_mark"`
Name string `json:"name"` Name string `json:"name"`
OfferId string `json:"offer_id"` OfferId string `json:"offer_id"`
@@ -163,10 +165,10 @@ type ListUnprocessedShipmentsPosting struct {
ProductsRequiringRNPT []string `json:"products_requiring_rnpt"` ProductsRequiringRNPT []string `json:"products_requiring_rnpt"`
} `json:"requirements"` } `json:"requirements"`
ShipmentDate string `json:"shipment_date"` ShipmentDate time.Time `json:"shipment_date"`
Status string `json:"status"` Status string `json:"status"`
TPLIntegrationType string `json:"tpl_integration_type"` TPLIntegrationType string `json:"tpl_integration_type"`
TrackingNumber string `json:"tracking_number"` TrackingNumber string `json:"tracking_number"`
} }
type MarketplaceServices struct { type MarketplaceServices struct {

View File

@@ -19,8 +19,8 @@ func TestListUnprocessedShipments(t *testing.T) {
&ListUnprocessedShipmentsParams{ &ListUnprocessedShipmentsParams{
Direction: "ASC", Direction: "ASC",
Filter: ListUnprocessedShipmentsFilter{ Filter: ListUnprocessedShipmentsFilter{
CutoffFrom: "2021-08-24T14:15:22Z", CutoffFrom: core.TimeFromString(t, "2021-08-24T14:15:22Z"),
CutoffTo: "2021-08-31T14:15:22Z", CutoffTo: core.TimeFromString(t, "2021-08-31T14:15:22Z"),
Status: "awaiting_packaging", Status: "awaiting_packaging",
}, },
Limit: 100, Limit: 100,

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"
) )
@@ -34,42 +35,36 @@ type GetStocksInfoResponse struct {
core.CommonResponse core.CommonResponse
// Method Result // Method Result
Result GetStocksInfoResponseResult `json:"result,omitempty"` Result struct {
} // Identifier of the last value on the page
//
// To get the next values, specify the recieved value in the next request in the last_id parameter
LastId string `json:"last_id,omitempty"`
type GetStocksInfoResponseResult struct { // The number of unique products for which information about stocks is displayed
// Identifier of the last value on the page Total int32 `json:"total,omitempty"`
//
// To get the next values, specify the recieved value in the next request in the last_id parameter
LastId string `json:"last_id,omitempty"`
// The number of unique products for which information about stocks is displayed // Product details
Total int32 `json:"total,omitempty"` Items []struct {
// Product identifier in the seller's system
OfferId string `json:"offer_id,omitempty"`
// Product details // Product identifier
Items []GetStocksInfoResponseItem `json:"items,omitempty"` ProductId int64 `json:"product_id,omitempty"`
}
type GetStocksInfoResponseItem struct { // Stock details
// Product identifier in the seller's system Stocks []struct {
OfferId string `json:"offer_id,omitempty"` // In a warehouse
Present int32 `json:"present,omitempty"`
// Product identifier // Reserved
ProductId int64 `json:"product_id,omitempty"` Reserved int32 `json:"reserved,omitempty"`
// Stock details // Warehouse type
Stocks []GetStocksInfoResponseStock `json:"stocks,omitempty"` Type string `json:"type,omitempty" default:"ALL"`
} } `json:"stocks,omitempty"`
} `json:"items,omitempty"`
type GetStocksInfoResponseStock struct { } `json:"result,omitempty"`
// In a warehouse
Present int32 `json:"present,omitempty"`
// Reserved
Reserved int32 `json:"reserved,omitempty"`
// Warehouse type
Type string `json:"type,omitempty" default:"ALL"`
} }
func (c Client) GetStocksInfo(params *GetStocksInfoParams) (*GetStocksInfoResponse, error) { func (c Client) GetStocksInfo(params *GetStocksInfoParams) (*GetStocksInfoResponse, error) {
@@ -95,111 +90,95 @@ type GetProductDetailsParams struct {
type GetProductDetailsResponse struct { type GetProductDetailsResponse struct {
core.CommonResponse core.CommonResponse
Result GetProductDetailsResponseResult `json:"Result"` Result struct {
} Barcode string `json:"barcode"`
Barcodes []string `json:"barcodes"`
type GetProductDetailsResponseResult struct { BuyboxPrice string `json:"buybox_price"`
Barcode string `json:"barcode"` CategoryId int64 `json:"category_id"`
Barcodes []string `json:"barcodes"` ColorImage string `json:"color_image"`
BuyboxPrice string `json:"buybox_price"` Commissions []struct {
CategoryId int64 `json:"category_id"` DeliveryAmount float64 `json:"deliveryAmount"`
ColorImage string `json:"color_image"` MinValue float64 `json:"minValue"`
Commissions []GetProductDetailsResponseCommission `json:"commissions"` Percent float64 `json:"percent"`
CreatedAt string `json:"created_at"` ReturnAmount float64 `json:"returnAmount"`
FBOSKU int64 `json:"fbo_sku"` SaleSchema string `json:"saleSchema"`
FBSSKU int64 `json:"fbs_sku"` Value float64 `json:"value"`
Id int64 `json:"id"` } `json:"commissions"`
Images []string `json:"images"` CreatedAt time.Time `json:"created_at"`
PrimaryImage string `json:"primary_image"` FBOSKU int64 `json:"fbo_sku"`
Images360 []string `json:"images360"` FBSSKU int64 `json:"fbs_sku"`
HasDiscountedItem bool `json:"has_discounted_item"` Id int64 `json:"id"`
IsDiscounted bool `json:"is_discounted"` Images []string `json:"images"`
DiscountedStocks GetProductDetailsResponseDiscountedStocks `json:"discounted_stocks"` PrimaryImage string `json:"primary_image"`
IsKGT bool `json:"is_kgt"` Images360 []string `json:"images360"`
IsPrepayment bool `json:"is_prepayment"` HasDiscountedItem bool `json:"has_discounted_item"`
IsPrepaymentAllowed bool `json:"is_prepayment_allowed"` IsDiscounted bool `json:"is_discounted"`
CurrencyCode string `json:"currency_code"` DiscountedStocks struct {
MarketingPrice string `json:"marketing_price"` Coming int32 `json:"coming"`
MinOzonPrice string `json:"min_ozon_price"` Present int32 `json:"present"`
MinPrice string `json:"min_price"` Reserved int32 `json:"reserved"`
Name string `json:"name"` } `json:"discounted_stocks"`
OfferId string `json:"offer_id"` IsKGT bool `json:"is_kgt"`
OldPrice string `json:"old_price"` IsPrepayment bool `json:"is_prepayment"`
PremiumPrice string `json:"premium_price"` IsPrepaymentAllowed bool `json:"is_prepayment_allowed"`
Price string `json:"price"` CurrencyCode string `json:"currency_code"`
PriceIndex string `json:"price_idnex"` MarketingPrice string `json:"marketing_price"`
RecommendedPrice string `json:"recommended_price"` MinOzonPrice string `json:"min_ozon_price"`
Status GetProductDetailsResponseStatus `json:"status"` MinPrice string `json:"min_price"`
Sources []GetProductDetailsResponseSource `json:"sources"` Name string `json:"name"`
Stocks GetProductDetailsResponseStocks `json:"stocks"` OfferId string `json:"offer_id"`
UpdatedAt string `json:"updated_at"` OldPrice string `json:"old_price"`
VAT string `json:"vat"` PremiumPrice string `json:"premium_price"`
VisibilityDetails GetProductDetailsResponseDetails `json:"visibility_details"` Price string `json:"price"`
Visible bool `json:"visible"` PriceIndex string `json:"price_idnex"`
VolumeWeight float64 `json:"volume_weights"` RecommendedPrice string `json:"recommended_price"`
} Status struct {
State string `json:"state"`
type GetProductDetailsResponseCommission struct { StateFailed string `json:"state_failed"`
DeliveryAmount float64 `json:"deliveryAmount"` ModerateStatus string `json:"moderate_status"`
MinValue float64 `json:"minValue"` DeclineReasons []string `json:"decline_reasons"`
Percent float64 `json:"percent"` ValidationsState string `json:"validation_state"`
ReturnAmount float64 `json:"returnAmount"` StateName string `json:"state_name"`
SaleSchema string `json:"saleSchema"` StateDescription string `json:"state_description"`
Value float64 `json:"value"` IsFailed bool `json:"is_failed"`
} IsCreated bool `json:"is_created"`
StateTooltip string `json:"state_tooltip"`
type GetProductDetailsResponseDiscountedStocks struct { ItemErrors []GetProductDetailsResponseItemError `json:"item_errors"`
Coming int32 `json:"coming"` StateUpdatedAt time.Time `json:"state_updated_at"`
Present int32 `json:"present"` } `json:"status"`
Reserved int32 `json:"reserved"` Sources []struct {
} IsEnabled bool `json:"is_enabled"`
SKU int64 `json:"sku"`
type GetProductDetailsResponseStatus struct { Source string `json:"source"`
State string `json:"state"` } `json:"sources"`
StateFailed string `json:"state_failed"` Stocks struct {
ModerateStatus string `json:"moderate_status"` Coming int32 `json:"coming"`
DeclineReasons []string `json:"decline_reasons"` Present int32 `json:"present"`
ValidationsState string `json:"validation_state"` Reserved int32 `json:"reserved"`
StateName string `json:"state_name"` } `json:"stocks"`
StateDescription string `json:"state_description"` UpdatedAt time.Time `json:"updated_at"`
IsFailed bool `json:"is_failed"` VAT string `json:"vat"`
IsCreated bool `json:"is_created"` VisibilityDetails struct {
StateTooltip string `json:"state_tooltip"` ActiveProduct bool `json:"active_product"`
ItemErrors []GetProductDetailsResponseItemError `json:"item_errors"` HasPrice bool `json:"has_price"`
StateUpdatedAt string `json:"state_updated_at"` HasStock bool `json:"has_stock"`
} `json:"visibility_details"`
Visible bool `json:"visible"`
VolumeWeight float64 `json:"volume_weights"`
} `json:"Result"`
} }
type GetProductDetailsResponseItemError struct { type GetProductDetailsResponseItemError struct {
Code string `json:"code"` Code string `json:"code"`
State string `json:"state"` State string `json:"state"`
Level string `json:"level"` Level string `json:"level"`
Description string `json:"description"` Description string `json:"description"`
Field string `json:"field"` Field string `json:"field"`
AttributeId int64 `json:"attribute_id"` AttributeId int64 `json:"attribute_id"`
AttributeName string `json:"attribute_name"` AttributeName string `json:"attribute_name"`
OptionalDescriptionElements GetProductDetailsResponseOptionalDescriptionElements `json:"optional_description_elements"` OptionalDescriptionElements struct {
} PropertyName string `json:"property_name"`
} `json:"optional_description_elements"`
type GetProductDetailsResponseOptionalDescriptionElements struct {
PropertyName string `json:"property_name"`
}
type GetProductDetailsResponseSource struct {
IsEnabled bool `json:"is_enabled"`
SKU int64 `json:"sku"`
Source string `json:"source"`
}
type GetProductDetailsResponseStocks struct {
Coming int32 `json:"coming"`
Present int32 `json:"present"`
Reserved int32 `json:"reserved"`
}
type GetProductDetailsResponseDetails struct {
ActiveProduct bool `json:"active_product"`
HasPrice bool `json:"has_price"`
HasStock bool `json:"has_stock"`
} }
func (c Client) GetProductDetails(params *GetProductDetailsParams) (*GetProductDetailsResponse, error) { func (c Client) GetProductDetails(params *GetProductDetailsParams) (*GetProductDetailsResponse, error) {