Skip to content

Commit 9a5c0c8

Browse files
authored
feat(product_catalog): add enum to filter by product type in the public catalog API (scaleway#2567)
1 parent fc3f746 commit 9a5c0c8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

api/product_catalog/v2alpha1/product_catalog_sdk.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,54 @@ var (
3939
_ = namegenerator.GetRandomName
4040
)
4141

42+
type ListPublicCatalogProductsRequestProductType string
43+
44+
const (
45+
// Unknown product type.
46+
ListPublicCatalogProductsRequestProductTypeUnknownProductType = ListPublicCatalogProductsRequestProductType("unknown_product_type")
47+
// Include the Instance information in the response.
48+
ListPublicCatalogProductsRequestProductTypeInstance = ListPublicCatalogProductsRequestProductType("instance")
49+
// Include the Apple Silicon information in the response.
50+
ListPublicCatalogProductsRequestProductTypeAppleSilicon = ListPublicCatalogProductsRequestProductType("apple_silicon")
51+
// Include the Elastic Metal information in the response.
52+
ListPublicCatalogProductsRequestProductTypeElasticMetal = ListPublicCatalogProductsRequestProductType("elastic_metal")
53+
// Include the Dedibox information in the response.
54+
ListPublicCatalogProductsRequestProductTypeDedibox = ListPublicCatalogProductsRequestProductType("dedibox")
55+
)
56+
57+
func (enum ListPublicCatalogProductsRequestProductType) String() string {
58+
if enum == "" {
59+
// return default value if empty
60+
return string(ListPublicCatalogProductsRequestProductTypeUnknownProductType)
61+
}
62+
return string(enum)
63+
}
64+
65+
func (enum ListPublicCatalogProductsRequestProductType) Values() []ListPublicCatalogProductsRequestProductType {
66+
return []ListPublicCatalogProductsRequestProductType{
67+
"unknown_product_type",
68+
"instance",
69+
"apple_silicon",
70+
"elastic_metal",
71+
"dedibox",
72+
}
73+
}
74+
75+
func (enum ListPublicCatalogProductsRequestProductType) MarshalJSON() ([]byte, error) {
76+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
77+
}
78+
79+
func (enum *ListPublicCatalogProductsRequestProductType) UnmarshalJSON(data []byte) error {
80+
tmp := ""
81+
82+
if err := json.Unmarshal(data, &tmp); err != nil {
83+
return err
84+
}
85+
86+
*enum = ListPublicCatalogProductsRequestProductType(ListPublicCatalogProductsRequestProductType(tmp).String())
87+
return nil
88+
}
89+
4290
type PublicCatalogProductPropertiesHardwareCPUArch string
4391

4492
const (
@@ -530,6 +578,9 @@ type PublicCatalogAPIListPublicCatalogProductsRequest struct {
530578

531579
// PageSize: the number of products per page. Value must be greater or equal to 1.
532580
PageSize *uint32 `json:"-"`
581+
582+
// ProductTypes: the list of filtered product categories.
583+
ProductTypes []ListPublicCatalogProductsRequestProductType `json:"-"`
533584
}
534585

535586
type PublicCatalogAPI struct {
@@ -555,6 +606,7 @@ func (s *PublicCatalogAPI) ListPublicCatalogProducts(req *PublicCatalogAPIListPu
555606
query := url.Values{}
556607
parameter.AddToQuery(query, "page", req.Page)
557608
parameter.AddToQuery(query, "page_size", req.PageSize)
609+
parameter.AddToQuery(query, "product_types", req.ProductTypes)
558610

559611
scwReq := &scw.ScalewayRequest{
560612
Method: "GET",

0 commit comments

Comments
 (0)