Skip to content

Commit c3995ea

Browse files
committed
chore: review comments
1 parent 4a294d9 commit c3995ea

11 files changed

Lines changed: 426 additions & 391 deletions

File tree

api/spec/packages/aip/src/common/parameters.tsp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,24 @@ model StringFieldFilterExact {
132132
"x-go-type-import",
133133
#{ path: "github.com/openmeterio/openmeter/api/v3/filters" }
134134
)
135-
model DateTimeFieldFilter {
136-
/** Value strictly equals given RFC-3339 formatted timestamp in UTC. */
137-
eq?: Shared.DateTime;
138-
139-
/** Value does not equal the given RFC-3339 formatted timestamp in UTC. */
140-
neq?: Shared.DateTime;
141-
142-
/** Returns entities that match any of the comma-delimited RFC-3339 formatted timestamps. */
143-
@encode(ArrayEncoding.commaDelimited)
144-
oeq?: Shared.DateTime[];
135+
union DateTimeFieldFilter {
136+
string: string,
137+
object: {
138+
/** Value strictly equals given RFC-3339 formatted timestamp in UTC. */
139+
eq?: Shared.DateTime,
145140

146-
/** Value is less than the given RFC-3339 formatted timestamp in UTC. */
147-
lt?: Shared.DateTime;
141+
/** Value is less than the given RFC-3339 formatted timestamp in UTC. */
142+
lt?: Shared.DateTime,
148143

149-
/** Value is less than or equal to the given RFC-3339 formatted timestamp in UTC. */
150-
lte?: Shared.DateTime;
144+
/** Value is less than or equal to the given RFC-3339 formatted timestamp in UTC. */
145+
lte?: Shared.DateTime,
151146

152-
/** Value is greater than the given RFC-3339 formatted timestamp in UTC. */
153-
gt?: Shared.DateTime;
147+
/** Value is greater than the given RFC-3339 formatted timestamp in UTC. */
148+
gt?: Shared.DateTime,
154149

155-
/** Value is greater than or equal to the given RFC-3339 formatted timestamp in UTC. */
156-
gte?: Shared.DateTime;
150+
/** Value is greater than or equal to the given RFC-3339 formatted timestamp in UTC. */
151+
gte?: Shared.DateTime,
152+
},
157153
}
158154

159155
/**

api/v3/api.gen.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v3/filters/convert.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
// ConvertFilterString converts an API FilterString to the internal filter.FilterString.
1313
func ConvertFilterString(f FilterString) filter.FilterString {
1414
out := filter.FilterString{
15-
Eq: f.Eq,
16-
Ne: f.Neq,
17-
Exists: f.Exists,
18-
Contains: f.Contains,
19-
Gt: f.Gt,
20-
Gte: f.Gte,
21-
Lt: f.Lt,
22-
Lte: f.Lte,
15+
Eq: f.Eq,
16+
Ne: f.Neq,
17+
Exists: f.Exists,
18+
Contains: f.Contains,
19+
Gt: f.Gt,
20+
Gte: f.Gte,
21+
Lt: f.Lt,
22+
Lte: f.Lte,
2323
}
2424

2525
if len(f.Oeq) > 0 {
@@ -138,8 +138,7 @@ func ConvertFilterDateTime(f FilterDateTime) (filter.FilterTime, error) {
138138
if err != nil {
139139
return out, fmt.Errorf("filter eq: %w", err)
140140
}
141-
// FilterTime has no Eq; use Gte as the closest approximation.
142-
out.Gte = &t
141+
out.Eq = &t
143142
}
144143

145144
if f.Gt != nil {

api/v3/filters/convert_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ func TestConvertFilterNumeric(t *testing.T) {
116116
}
117117

118118
func TestConvertFilterDateTime(t *testing.T) {
119+
t.Run("eq maps to filter.FilterTime Eq", func(t *testing.T) {
120+
out, err := ConvertFilterDateTime(FilterDateTime{
121+
Eq: lo.ToPtr("2024-06-15T12:00:00Z"),
122+
})
123+
require.NoError(t, err)
124+
require.NotNil(t, out.Eq)
125+
assert.Equal(t, time.Date(2024, 6, 15, 12, 0, 0, 0, time.UTC), *out.Eq)
126+
assert.Nil(t, out.Gte, "eq must not fall back to Gte")
127+
})
128+
119129
t.Run("gt and lt", func(t *testing.T) {
120130
out, err := ConvertFilterDateTime(FilterDateTime{
121131
Gt: lo.ToPtr("2024-01-01T00:00:00Z"),
@@ -126,11 +136,26 @@ func TestConvertFilterDateTime(t *testing.T) {
126136
assert.Equal(t, time.Date(2024, 12, 31, 23, 59, 59, 0, time.UTC), *out.Lt)
127137
})
128138

139+
t.Run("gte and lte", func(t *testing.T) {
140+
out, err := ConvertFilterDateTime(FilterDateTime{
141+
Gte: lo.ToPtr("2024-01-01T00:00:00Z"),
142+
Lte: lo.ToPtr("2024-12-31T23:59:59Z"),
143+
})
144+
require.NoError(t, err)
145+
assert.Equal(t, time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), *out.Gte)
146+
assert.Equal(t, time.Date(2024, 12, 31, 23, 59, 59, 0, time.UTC), *out.Lte)
147+
})
148+
129149
t.Run("invalid timestamp returns error", func(t *testing.T) {
130150
_, err := ConvertFilterDateTime(FilterDateTime{Gt: lo.ToPtr("not-a-date")})
131151
require.Error(t, err)
132152
})
133153

154+
t.Run("invalid eq timestamp returns error", func(t *testing.T) {
155+
_, err := ConvertFilterDateTime(FilterDateTime{Eq: lo.ToPtr("not-a-date")})
156+
require.Error(t, err)
157+
})
158+
134159
t.Run("nil returns nil", func(t *testing.T) {
135160
out, err := ConvertFilterDateTimePtr(nil)
136161
require.NoError(t, err)

api/v3/filters/filter.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ type FilterDateTime struct {
129129
// Eq requires the field to match the provided value exactly.
130130
Eq *string `json:"eq,omitempty"`
131131

132-
// Neq requires the field to not match the provided value.
133-
Neq *string `json:"neq,omitempty"`
134-
135-
// Oeq requires the field to match any of the provided comma-separated values.
136-
Oeq []string `json:"oeq,omitempty"`
137-
138132
// Gt requires the field to be greater than the provided value.
139133
Gt *string `json:"gt,omitempty"`
140134

@@ -151,8 +145,6 @@ type FilterDateTime struct {
151145
// IsEmpty returns true if no filter operator is set.
152146
func (f FilterDateTime) IsEmpty() bool {
153147
return f.Eq == nil &&
154-
f.Neq == nil &&
155-
len(f.Oeq) == 0 &&
156148
f.Gt == nil &&
157149
f.Gte == nil &&
158150
f.Lt == nil &&
@@ -167,8 +159,6 @@ func (f FilterDateTime) Validate(ctx context.Context, field string) error {
167159

168160
return validateMutuallyExclusiveFilters(ctx, field,
169161
f.Eq != nil,
170-
f.Neq != nil,
171-
len(f.Oeq) > 0,
172162
f.Gt != nil,
173163
f.Gte != nil,
174164
f.Lt != nil,

0 commit comments

Comments
 (0)