Skip to content

Commit

Permalink
fix lint issues + check hits length before access
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanach committed Aug 28, 2024
1 parent d6b1e4d commit a199a1c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions docs/data-sources/transport_product.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ data "autonomi_transport_product" "transport" {
- `facet_distribution` (Attributes) The **facet_distribution** attribute provides an overview of the distribution of various facets
within the transport products returned by the Meilisearch query. This attribute allows you to analyze the frequency
of different categories or attributes in the search results. (see [below for nested schema](#nestedatt--facet_distribution))
- `hit` (Attributes) The **hits** attribute contains the list of transport products returned by the Meilisearch query.
- `hit` (Attributes) The **hit** attribute contains the transport product returned by the Meilisearch query.
Each hit represents a transport product that matches the specified search criteria. (see [below for nested schema](#nestedatt--hit))

<a id="nestedatt--filters"></a>
Expand All @@ -71,7 +71,6 @@ Read-Only:
- `location_to` (Map of Number)
- `provider` (Map of Number)


<a id="nestedatt--hit"></a>
### Nested Schema for `hit`

Expand Down
2 changes: 1 addition & 1 deletion internal/data_sources/access_product_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (d *accessProductDataSource) Read(ctx context.Context, req datasource.ReadR
return
}

if accessProducts.Hits == nil {
if len(accessProducts.Hits) == 0 {
resp.Diagnostics.AddError("Not hit found", "")
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/data_sources/cloud_product_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (d *cloudProductDataSource) Read(ctx context.Context, req datasource.ReadRe
return
}

if cloudProducts.Hits == nil {
if len(cloudProducts.Hits) == 0 {
resp.Diagnostics.AddError("Not hit found", "")
return
}
Expand Down
7 changes: 6 additions & 1 deletion internal/data_sources/transport_product_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (d *transportProductDataSource) Schema(_ context.Context, _ datasource.Sche
},
},
"hit": schema.SingleNestedAttribute{
MarkdownDescription: `The **hits** attribute contains the list of transport products returned by the Meilisearch query.
MarkdownDescription: `The **hit** attribute contains the transport product returned by the Meilisearch query.
Each hit represents a transport product that matches the specified search criteria.`,
Computed: true,
Attributes: map[string]schema.Attribute{
Expand Down Expand Up @@ -181,6 +181,11 @@ func (d *transportProductDataSource) Read(ctx context.Context, req datasource.Re
return
}

if len(transportProducts.Hits) == 0 {
resp.Diagnostics.AddError("Not hit found", "")
return
}

// If Meiliesearch return more than one hit, check if `cheapest` filter has been set.
// If not, an error is returned, otherwise a sort will be done to order the list by price mrc. The first entry will be returned
if len(transportProducts.Hits) > 1 {
Expand Down

0 comments on commit a199a1c

Please sign in to comment.