Skip to content

Commit

Permalink
add new field filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rrequero committed Aug 27, 2024
1 parent d88868a commit 8473863
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 33 deletions.
68 changes: 35 additions & 33 deletions gfw/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,42 +154,44 @@ type RelatedDataset struct {
Type string `json:"type"`
}
type Dataset struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
Type string `json:"type"`
Alias []string `json:"alias"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Unit string `json:"unit"`
Status string `json:"status"`
Category string `json:"category"`
Subcategory string `json:"subcategory"`
Source string `json:"source"`
Configuration *DatasetConfiguration `json:"configuration"`
RelatedDatasets []RelatedDataset `json:"relatedDatasets"`
Schema *map[string]interface{} `json:"schema"`
FieldsAllowed []string `json:"fieldsAllowed"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt string `json:"createdAt"`
Type string `json:"type"`
Alias []string `json:"alias"`
StartDate string `json:"startDate"`
EndDate string `json:"endDate"`
Unit string `json:"unit"`
Status string `json:"status"`
Category string `json:"category"`
Subcategory string `json:"subcategory"`
Source string `json:"source"`
Configuration *DatasetConfiguration `json:"configuration"`
RelatedDatasets []RelatedDataset `json:"relatedDatasets"`
Schema *map[string]interface{} `json:"schema"`
Filters []map[string]interface{} `json:"filters"`
FieldsAllowed []string `json:"fieldsAllowed"`
}

type CreateDataset struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Alias []string `json:"alias,omitempty"`
StartDate string `json:"startDate,omitempty"`
EndDate string `json:"endDate,omitempty"`
Unit string `json:"unit,omitempty"`
Status string `json:"status,omitempty"`
Category string `json:"category,omitempty"`
Subcategory string `json:"subcategory,omitempty"`
Source string `json:"source,omitempty"`
Configuration *DatasetConfiguration `json:"configuration,omitempty"`
RelatedDatasets []RelatedDataset `json:"relatedDatasets,omitempty"`
Schema *map[string]interface{} `json:"schema,omitempty"`
FieldsAllowed []string `json:"fieldsAllowed,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Alias []string `json:"alias,omitempty"`
StartDate string `json:"startDate,omitempty"`
EndDate string `json:"endDate,omitempty"`
Unit string `json:"unit,omitempty"`
Status string `json:"status,omitempty"`
Category string `json:"category,omitempty"`
Subcategory string `json:"subcategory,omitempty"`
Source string `json:"source,omitempty"`
Configuration *DatasetConfiguration `json:"configuration,omitempty"`
RelatedDatasets []RelatedDataset `json:"relatedDatasets,omitempty"`
Schema *map[string]interface{} `json:"schema,omitempty"`
Filters []map[string]interface{} `json:"filters,omitempty"`
FieldsAllowed []string `json:"fieldsAllowed,omitempty"`
}

type DataviewLayer struct {
Expand Down
22 changes: 22 additions & 0 deletions gfw/resource_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ func resourceDataset() *schema.Resource {
Optional: true,
ValidateFunc: validation.StringIsJSON,
},
"filters": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsJSON,
},
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -539,6 +544,15 @@ func resourceDatasetRead(ctx context.Context, d *schema.ResourceData, m interfac
return diag.FromErr(err)
}
}
if dataset.Filters != nil {
jsonStr, err := json.Marshal(dataset.Filters)
if err != nil {
return diag.FromErr(err)
}
if err := d.Set("filters", string(jsonStr)); err != nil {
return diag.FromErr(err)
}
}

if dataset.Configuration != nil {
configuration := flattenDatasetConfiguration(*dataset.Configuration)
Expand Down Expand Up @@ -605,6 +619,14 @@ func schemaToDataset(d *schema.ResourceData) (api.CreateDataset, error) {
}
dataset.Schema = &obj
}
if d.Get("filters") != nil && d.Get("filters").(string) != "" {
var obj []map[string]interface{}
err := json.Unmarshal([]byte(d.Get("filters").(string)), &obj)
if err != nil {
return api.CreateDataset{}, err
}
dataset.Filters = obj
}
if d.Get("configuration") != nil {
configuration := d.Get("configuration").([]interface{})
if len(configuration) > 0 {
Expand Down

0 comments on commit 8473863

Please sign in to comment.