-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfields.go
More file actions
71 lines (62 loc) · 1.79 KB
/
fields.go
File metadata and controls
71 lines (62 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package flashduty
import (
"context"
)
// ListFieldsInput contains parameters for listing custom fields
type ListFieldsInput struct {
FieldIDs []string // Filter by field IDs
FieldName string // Filter by exact field name
}
// ListFieldsOutput contains the result of listing fields
type ListFieldsOutput struct {
Fields []FieldInfo `json:"fields"`
Total int `json:"total"`
}
// ListFields queries custom field definitions
func (c *Client) ListFields(ctx context.Context, input *ListFieldsInput) (*ListFieldsOutput, error) {
result, err := postData[struct {
Items []struct {
FieldID string `json:"field_id"`
FieldName string `json:"field_name"`
DisplayName string `json:"display_name"`
FieldType string `json:"field_type"`
ValueType string `json:"value_type"`
Options []string `json:"options,omitempty"`
DefaultValue any `json:"default_value,omitempty"`
} `json:"items"`
}](c, ctx, "/field/list", map[string]any{}, "failed to list fields")
if err != nil {
return nil, err
}
// Build filter ID set
filterIDSet := make(map[string]struct{})
for _, id := range input.FieldIDs {
filterIDSet[id] = struct{}{}
}
fields := []FieldInfo{}
for _, f := range result.Items {
// Filter by ID if provided
if len(filterIDSet) > 0 {
if _, ok := filterIDSet[f.FieldID]; !ok {
continue
}
}
// Filter by name if provided
if input.FieldName != "" && f.FieldName != input.FieldName {
continue
}
fields = append(fields, FieldInfo{
FieldID: f.FieldID,
FieldName: f.FieldName,
DisplayName: f.DisplayName,
FieldType: f.FieldType,
ValueType: f.ValueType,
Options: f.Options,
DefaultValue: f.DefaultValue,
})
}
return &ListFieldsOutput{
Fields: fields,
Total: len(fields),
}, nil
}