Skip to content

Commit

Permalink
fix: makeup miss date on productdata struct (#5)
Browse files Browse the repository at this point in the history
Co-authored-by: yan.jinbin <yan.jinbin@shipper.id>
  • Loading branch information
yanjinbin and yan.jinbin authored May 16, 2022
1 parent 1c6c73d commit f54ada1
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 483 deletions.
4 changes: 2 additions & 2 deletions product_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestClient_CreateProductRequest_Integration(t *testing.T) {
Description: "<ul><li>It is recommended to avoid using Chinese because the copy will be displayed to local users</li></ul><img src=\"https://p19-oec-va.ibyteimg.com/tos-maliva-i-o3syd03w52-us/8de4c52c078042589e427c681ca10d0e~tplv-o3syd03w52-origin-jpeg.jpeg?\">",
CategoryID: "903560",
BrandID: "0",
Images: []tiktok.Image{
Images: []tiktok.ImgID{
{ID: "tos-maliva-i-o3syd03w52-us/342ff2ab5fac414fb1d0af5eb490cae9"},
},
WarrantyPeriod: 1,
Expand Down Expand Up @@ -351,7 +351,7 @@ func TestClient_EditProduct_Integration(t *testing.T) {
Description: "<ul><li>It is recommended to avoid using Chinese because the copy will be displayed to local users</li></ul><img src=\"https://p19-oec-va.ibyteimg.com/tos-maliva-i-o3syd03w52-us/8de4c52c078042589e427c681ca10d0e~tplv-o3syd03w52-origin-jpeg.jpeg?\">",
CategoryID: "903560",
BrandID: "0",
Images: []tiktok.Image{
Images: []tiktok.ImgID{
{ID: "tos-maliva-i-o3syd03w52-us/342ff2ab5fac414fb1d0af5eb490cae9"},
},
WarrantyPeriod: 1,
Expand Down
14 changes: 4 additions & 10 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,14 @@ type SKU struct {
OriginalPrice string `json:"original_price,omitempty"`
}

type File struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
}

type Image struct {
type ImgID struct {
ID string `json:"id"`
}

type ProductCertificationRequest struct {
ID string `json:"id"`
Files []File `json:"files"`
Images []Image `json:"images"`
Images []ImgID `json:"images"`
}

// CreateProductRequest is creating product
Expand All @@ -122,7 +116,7 @@ type CreateProductRequest struct {
Description string `json:"description" validate:"required"`
CategoryID string `json:"category_id" validate:"required"`
BrandID string `json:"brand_id"`
Images []Image `json:"images,omitempty"`
Images []ImgID `json:"images,omitempty"`
WarrantyPeriod int `json:"warranty_period"`
WarrantyPolicy string `json:"warranty_policy"`
PackageLength int `json:"package_length"`
Expand Down Expand Up @@ -180,7 +174,7 @@ type EditProductRequest struct {
Description string `json:"description" validate:"required"`
CategoryID string `json:"category_id" validate:"required"`
BrandID string `json:"brand_id"`
Images []Image `json:"images,omitempty"`
Images []ImgID `json:"images,omitempty"`
WarrantyPeriod int `json:"warranty_period" example:"Need to choose among the candidate values provided by the platform: 1: 4 weeks" 2:"2 months" 3:"3 months" 4:"4 months" 5:"5 months" 6:"6 months" 7:"7 months" 8:"8 months" 9:"9 months" 10:"10 months" 11:"11 months" 12:"12 months" 13:"2 years" 14:"3 years" 15:"1 week" 16:"2 weeks" 17:"18 months" 18:"4 years" 19:"5 years" 20:"10 years" 21:"lifetime warranty"`
WarrantyPolicy string `json:"warranty_policy"`
PackageLength int `json:"package_length" example:"14. unit is cm"`
Expand Down
174 changes: 118 additions & 56 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ type CategoryRules struct {
CategoryRules []CategoryRule `json:"category_rules"`
}

type Brand struct {
ID string `json:"id"`
Name string `json:"name"`
}
type BrandList struct {
BrandList []Brand `json:"brand_list"`
}
Expand All @@ -276,7 +272,7 @@ type FileInfo struct {
type SalesAttribute struct {
AttributeID string `json:"attribute_id"`
CustomValue string `json:"custom_value,omitempty"`
SKUImage *Image `json:"sku_img,omitempty"`
SKUImage *ImgID `json:"sku_img,omitempty"`
ValueID string `json:"value_id,omitempty"`
}

Expand All @@ -285,63 +281,129 @@ type ProductSKU struct {
SellerSku string `json:"seller_sku"`
SalesAttributes []SalesAttribute `json:"sales_attributes"`
}
type Brand struct {
ID string `json:"id"`
Name string `json:"name"`
Status int `json:"status"` // ONLINE=1; OFFLINE=2;
}

type File struct {
ID string `json:"id"`
List []string `json:"list,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
}

type Image struct {
ID string `json:"id"`
Height int `json:"height"`
Width int `json:"width"`
ThumbUrlList []string `json:"thumb_url_list"`
UrlList []string `json:"url_list"`
}

type Certification struct {
ID string `json:"id"`
Title string `json:"title"`
Files []File `json:"files"`
Images []Image `json:"images"`
}

type QCReason struct {
Reason string `json:"reason"`
SubReasons []string `json:"sub_reasons"`
}

type DeliveryService struct {
DeliveryServiceID int64 `json:"delivery_service_id"`
DeliveryOptionName string `json:"delivery_option_name"`
DeliveryServiceStatus bool `json:"delivery_service_status"`
}

type SizeChart struct {
Height int `json:"height"`
ID string `json:"id"`
ThumbUrlList string `json:"thumb_url_list"`
UrlList string `json:"url_list"`
Width int `json:"width"`
}

type VideoInfo struct {
BackupUrl string `json:"backup_url"`
Bitrate int `json:"bitrate"`
FileHash string `json:"file_hash"`
Format string `json:"format"`
Height int `json:"height"`
MainUrl string `json:"main_url"`
Size int `json:"size"`
UrlExpire int64 `json:"url_expire"`
Width int `json:"width"`
}

type Video struct {
Duration float64 `json:"duration"`
ID string `json:"id"`
MediaType string `json:"media_type"`
PostUrl string `json:"post_url"`
VideoInfos []VideoInfo `json:"video_infos"`
}
type Value struct {
ID string `json:"id"`
Name string `json:"name"`
}

type Price struct {
Currency string `json:"currency"`
OriginalPrice string `json:"original_price"`
PriceIncludeVat string `json:"price_include_vat"`
}
type SalesAttr struct {
ID string `json:"id"`
Name string `json:"name"`
ValueID string `json:"value_id"`
ValueName string `json:"value_name"`
SkuImg Image `json:"sku_img"`
}
type SKUData struct {
ID string `json:"id"`
SellerSku string `json:"seller_sku"`
Price Price `json:"price"`
StockInfos []StockInfo `json:"stock_infos"`
SalesAttributes []SalesAttr `json:"sales_attributes"`
}
type ProductAttribute struct {
ID string `json:"id"`
Name string `json:"name"`
Values []Value `json:"values"`
}

type ProductData struct {
CategoryList []struct {
ID string `json:"id"`
IsLeaf bool `json:"is_leaf"`
LocalDisplayName string `json:"local_display_name"`
ParentID string `json:"parent_id"`
} `json:"category_list"`
CreateTime int64 `json:"create_time"`
Description string `json:"description"`
Images []struct {
Height int `json:"height"`
ID string `json:"id"`
ThumbUrlList []string `json:"thumb_url_list"`
UrlList []string `json:"url_list"`
Width int `json:"width"`
} `json:"images"`
IsCodOpen bool `json:"is_cod_open"`
PackageHeight int `json:"package_height"`
PackageLength int `json:"package_length"`
PackageWeight string `json:"package_weight"`
PackageWidth int `json:"package_width"`
ProductAttributes []struct {
ID string `json:"id"`
Name string `json:"name"`
Values []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"values"`
} `json:"product_attributes"`
ProductID string `json:"product_id"`
ProductName string `json:"product_name"`
ProductStatus int `json:"product_status"`
Skus []struct {
ID string `json:"id"`
Price struct {
Currency string `json:"currency"`
OriginalPrice string `json:"original_price"`
} `json:"price"`
SalesAttributes []struct {
ID string `json:"id"`
Name string `json:"name"`
ValueID string `json:"value_id"`
ValueName string `json:"value_name"`
} `json:"sales_attributes"`
SellerSku string `json:"seller_sku"`
StockInfos []struct {
WarehouseID string `json:"warehouse_id"`
AvailableStock int `json:"available_stock"`
} `json:"stock_infos"`
} `json:"skus"`
UpdateTime int64 `json:"update_time"`
ProductID string `json:"product_id"`
ProductStatus int `json:"product_status"` // 1-draft、2-pending、3-failed(initial creation)、4-live、5-seller_deactivated、6-platform_deactivated、7-freeze 8-deleted
ProductName string `json:"product_name"`
CategoryList []Category `json:"category_list"`
Brand Brand `json:"brand"`
Images []Image `json:"images"`
Video Video `json:"video"`
Description string `json:"description"`
WarrantyPeriod struct {
WarrantyID int `json:"warranty_id"`
WarrantyDescription string `json:"warranty_description"`
} `json:"warranty_period"`
WarrantyPolicy string `json:"warranty_policy"`
WarrantyPolicy string `json:"warranty_policy"`
PackageHeight int `json:"package_height"`
PackageLength int `json:"package_length"`
PackageWidth int `json:"package_width"`
PackageWeight string `json:"package_weight"`
Skus []SKUData `json:"skus"`
ProductCertifications []Certification `json:"product_certifications"`
SizeChart Image `json:"size_chart"`
IsCodOpen bool `json:"is_cod_open"`
ProductAttributes []ProductAttribute `json:"product_attributes"`
QcReasons []QCReason `json:"qc_reasons"`
UpdateTime int64 `json:"update_time"`
CreateTime int64 `json:"create_time"`
DeliveryServices []DeliveryService `json:"delivery_services"`
}

type GetProductListData struct {
Expand Down
81 changes: 81 additions & 0 deletions respsonse_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package tiktok

import (
"encoding/json"
"fmt"
"testing"
)

func TestProductData(t *testing.T) {
img01 := Image{
ID: "ACC", Height: 1, Width: 2, ThumbUrlList: []string{"01.JPG", "02.JPG"}, UrlList: []string{"www.google.com", "twitter.com"},
}
data := &ProductData{
ProductID: "A",
ProductStatus: 1,
ProductName: "A",
CategoryList: []Category{
{
ID: "C1", ParentID: "003", LocalDisplayName: "LAKE-NIKE", IsLeaf: false,
},
},
Brand: Brand{
ID: "P", Name: "Nike",
},
Images: []Image{
{
ID: "ACC", Height: 1, Width: 2, ThumbUrlList: []string{"01.JPG", "02.JPG"}, UrlList: []string{"www.google.com", "twitter.com"},
},
},
Video: Video{
ID: "tokyo", Duration: 12.5, MediaType: "mkv", PostUrl: "www.yyets.com", VideoInfos: []VideoInfo{
{Height: 1, Width: 2, FileHash: "29393ns9s23=", Format: "mpv", MainUrl: "shipping.com", Size: 1, UrlExpire: 3600, BackupUrl: "www.g.com", Bitrate: 1024},
},
},
Description: "nike sb series",
WarrantyPeriod: struct {
WarrantyID int `json:"warranty_id"`
WarrantyDescription string `json:"warranty_description"`
}(struct {
WarrantyID int
WarrantyDescription string
}{WarrantyID: 996, WarrantyDescription: "996 day"}),

WarrantyPolicy: "free return",
PackageHeight: 100,
PackageLength: 99,
PackageWidth: 7,
PackageWeight: "100kg",
Skus: []SKUData{
{
Price: Price{OriginalPrice: "100", PriceIncludeVat: "1", Currency: "IDR"},
SellerSku: "ship-id-iphone13",
ID: "zh-fz-01",
StockInfos: []StockInfo{{WarehouseID: "001", AvailableStock: 10}},
SalesAttributes: []SalesAttr{
{ID: "001", Name: "ABC", ValueID: "9", ValueName: "COLOR", SkuImg: img01},
},
},
},
ProductCertifications: []Certification{
{ID: "1a", Title: "disney", Files: []File{
{ID: "1", List: []string{"P", "Q"}, Name: "QQ", Type: "PDF"},
}},
},
SizeChart: img01,
IsCodOpen: false,
ProductAttributes: []ProductAttribute{{ID: "12", Name: "pptv", Values: []Value{{ID: "LL", Name: "waka"}}}},
QcReasons: []QCReason{{Reason: "Illegal", SubReasons: []string{"R18", "AV"}}},
UpdateTime: 1652684619,
CreateTime: 1652684619,
DeliveryServices: []DeliveryService{
{
DeliveryServiceStatus: false,
DeliveryServiceID: 12,
DeliveryOptionName: "J&T Express",
},
},
}
d, _ := json.Marshal(data)
fmt.Println(string(d))
}
Loading

0 comments on commit f54ada1

Please sign in to comment.