Skip to content

Commit

Permalink
Merge pull request #12 from Avanis-GmbH/associations-and-json
Browse files Browse the repository at this point in the history
Associations and json
  • Loading branch information
Valentin-Kaiser authored Jul 24, 2023
2 parents d56722b + edbbc09 commit 9345d24
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
1 change: 0 additions & 1 deletion com/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func (c *Client) checkResponse(r *http.Response) error {
if err != nil {
return fmt.Errorf("parsing json response failed: %w", err)
}

return errors.Wrapf(&aerr, "request failed")
}

Expand Down
43 changes: 17 additions & 26 deletions com/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,26 @@ type APIError struct {
}

type ErrorResponse struct {
Success bool `json:"success"`
Data map[string]struct {
Result []struct {
Entities []interface{} `json:"entities"`
Errors []struct {
Status string `json:"status"`
Code string `json:"code"`
Title string `json:"title"`
Detail string `json:"detail"`
Source struct {
Pointer string `json:"pointer"`
} `json:"source"`
Meta struct {
Parameters interface{} `json:"parameters"`
} `json:"meta"`
} `json:"errors"`
} `json:"result"`
Extensions []interface{} `json:"extensions"`
} `json:"data"`
Errors []struct {
Status string `json:"status"`
Code string `json:"code"`
Title string `json:"title"`
Detail string `json:"detail"`
Source struct {
Pointer string `json:"pointer"`
} `json:"source"`
Meta struct {
Parameters interface{} `json:"parameters"`
} `json:"meta"`
} `json:"errors"`

Extensions []interface{} `json:"extensions"`
}

func (e APIError) Error() string {
str := fmt.Sprintf("%d - errrors: \n", e.StatusCode)
for subject, data := range e.Response.Data {
for _, result := range data.Result {
for _, err := range result.Errors {
str += fmt.Sprintf("\t%s: %s -> %s => %s \n", subject, err.Code, err.Detail, err.Source.Pointer)
}
}
str := fmt.Sprintf("%d - errors: \n", e.StatusCode)
for _, err := range e.Response.Errors {
str += fmt.Sprintf("\t: %s -> %s => %s \n", err.Code, err.Detail, err.Source.Pointer)
}

return str
Expand Down
8 changes: 4 additions & 4 deletions model/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Category struct {
CmsPageVersionId string `json:"cmsPageVersionId,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
CustomFields interface{} `json:"customFields,omitempty"`
Description string `json:"description,omitempty"`
Description string `json:"description"`
DisplayNestedProducts bool `json:"displayNestedProducts,omitempty"` // required
ExternalLink string `json:"externalLink,omitempty"`
FooterSalesChannels []SalesChannel `json:"footerSalesChannels,omitempty"`
Expand All @@ -27,9 +27,9 @@ type Category struct {
LinkType string `json:"linkType,omitempty"`
MainCategories []MainCategory `json:"mainCategories,omitempty"`
Media *Media `json:"media,omitempty"`
MediaId string `json:"mediaId,omitempty"`
MetaDescription string `json:"metaDescription,omitempty"`
MetaTitle string `json:"metaTitle,omitempty"`
MediaId *string `json:"mediaId"`
MetaDescription string `json:"metaDescription"`
MetaTitle string `json:"metaTitle"`
Name string `json:"name,omitempty"` // required
NavigationSalesChannels []SalesChannel `json:"navigationSalesChannels,omitempty"`
NestedProducts []Product `json:"nestedProducts,omitempty"`
Expand Down
18 changes: 9 additions & 9 deletions model/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Product struct {
CanonicalProductId string `json:"canonicalProductId,omitempty"`
Categories []Category `json:"categories,omitempty"`
CategoriesRo []Category `json:"categoriesRo,omitempty"`
CategoryIds interface{} `json:"categoryIds,omitempty"`
CategoryIds []string `json:"categoryIds,omitempty"`
CategoryTree interface{} `json:"categoryTree,omitempty"`
CheapestPrice interface{} `json:"cheapestPrice,omitempty"`
ChildCount float64 `json:"childCount,omitempty"`
Expand All @@ -22,7 +22,7 @@ type Product struct {
ConfiguratorGroupConfig interface{} `json:"configuratorGroupConfig,omitempty"` // deprecated
ConfiguratorSettings []ProductConfiguratorSetting `json:"configuratorSettings,omitempty"`
Cover *ProductMedia `json:"cover,omitempty"`
CoverId string `json:"coverId,omitempty"`
CoverId *string `json:"coverId"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
CrossSellingAssignedProducts []ProductCrossSellingAssignedProducts `json:"crossSellingAssignedProducts,omitempty"`
CrossSellings []ProductCrossSelling `json:"crossSellings,omitempty"`
Expand All @@ -32,26 +32,26 @@ type Product struct {
CustomSearchKeywords interface{} `json:"customSearchKeywords,omitempty"`
DeliveryTime *DeliveryTime `json:"deliveryTime,omitempty"`
DeliveryTimeId string `json:"deliveryTimeId,omitempty"`
Description string `json:"description,omitempty"`
Description string `json:"description"`
DisplayGroup string `json:"displayGroup,omitempty"`
Ean string `json:"ean,omitempty"`
FeatureSet *ProductFeatureSet `json:"featureSet,omitempty"`
FeatureSetId string `json:"featureSetId,omitempty"`
Height float64 `json:"height,omitempty"`
Height float64 `json:"height"`
Id string `json:"id,omitempty"`
IsCloseout bool `json:"isCloseout,omitempty"`
Keywords string `json:"keywords,omitempty"`
Keywords string `json:"keywords"`
Length float64 `json:"length,omitempty"`
MainCategories []MainCategory `json:"mainCategories,omitempty"`
MainVariantId string `json:"mainVariantId,omitempty"` // deprecated
Manufacturer *ProductManufacturer `json:"manufacturer,omitempty"`
ManufacturerId string `json:"manufacturerId,omitempty"`
ManufacturerId *string `json:"manufacturerId"`
ManufacturerNumber string `json:"manufacturerNumber,omitempty"`
MarkAsTopseller bool `json:"markAsTopseller,omitempty"`
MaxPurchase float64 `json:"maxPurchase,omitempty"`
Media []ProductMedia `json:"media,omitempty"`
MetaDescription string `json:"metaDescription,omitempty"`
MetaTitle string `json:"metaTitle,omitempty"`
MetaDescription string `json:"metaDescription"`
MetaTitle string `json:"metaTitle"`
MinPurchase float64 `json:"minPurchase,omitempty"`
Name string `json:"name,omitempty"` // required
OptionIds interface{} `json:"optionIds,omitempty"`
Expand All @@ -69,7 +69,7 @@ type Product struct {
ProductNumber string `json:"productNumber,omitempty"` // required
ProductReviews []ProductReview `json:"productReviews,omitempty"`
Properties []PropertyGroupOption `json:"properties,omitempty"`
PropertyIds interface{} `json:"propertyIds,omitempty"`
PropertyIds []string `json:"propertyIds,omitempty"`
PurchasePrices interface{} `json:"purchasePrices,omitempty"`
PurchaseSteps float64 `json:"purchaseSteps,omitempty"`
PurchaseUnit float64 `json:"purchaseUnit,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions model/product_manufacturer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import "time"
type ProductManufacturer struct {
CreatedAt *time.Time `json:"createdAt,omitempty"`
CustomFields interface{} `json:"customFields,omitempty"`
Description string `json:"description,omitempty"`
Description string `json:"description"`
Id string `json:"id,omitempty"`
Link string `json:"link,omitempty"`
Media *Media `json:"media,omitempty"`
MediaId string `json:"mediaId,omitempty"`
MediaId *string `json:"mediaId"`
Name string `json:"name,omitempty"` // required
Products []Product `json:"products,omitempty"`
Translated interface{} `json:"translated,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion model/property_group_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type PropertyGroupOption struct {
GroupId string `json:"groupId,omitempty"` // required
Id string `json:"id,omitempty"`
Media *Media `json:"media,omitempty"`
MediaId string `json:"mediaId,omitempty"`
MediaId *string `json:"mediaId"`
Name string `json:"name,omitempty"` // required
Position float64 `json:"position,omitempty"`
ProductConfiguratorSettings []ProductConfiguratorSetting `json:"productConfiguratorSettings,omitempty"`
Expand Down

0 comments on commit 9345d24

Please sign in to comment.