@@ -115,6 +115,21 @@ func fromAPICustomerIDFilter(ctx context.Context, f *api.ULIDFieldFilter) (*filt
115115 return & filter.FilterString {In : & values }, nil
116116}
117117
118+ func FromAPIEventSortField (ctx context.Context , field string ) (streaming.EventSortField , error ) {
119+ switch field {
120+ case "time" :
121+ return streaming .EventSortFieldTime , nil
122+ case "ingested_at" :
123+ return streaming .EventSortFieldIngestedAt , nil
124+ case "stored_at" :
125+ return streaming .EventSortFieldStoredAt , nil
126+ default :
127+ return "" , apierrors .NewUnsupportedSortFieldError (
128+ ctx , field , "time" , "ingested_at" , "stored_at" ,
129+ )
130+ }
131+ }
132+
118133// fromAPIEventSort resolves the public sort query into a backend sort field and direction.
119134func fromAPIEventSort (ctx context.Context , sort * api.SortQuery ) (streaming.EventSortField , sortx.Order , error ) {
120135 if lo .FromPtr (sort ) == "" {
@@ -132,23 +147,9 @@ func fromAPIEventSort(ctx context.Context, sort *api.SortQuery) (streaming.Event
132147 })
133148 }
134149
135- var field streaming.EventSortField
136- switch parsed .Field {
137- case string (streaming .EventSortFieldTime ):
138- field = streaming .EventSortFieldTime
139- case string (streaming .EventSortFieldIngestedAt ):
140- field = streaming .EventSortFieldIngestedAt
141- case string (streaming .EventSortFieldStoredAt ):
142- field = streaming .EventSortFieldStoredAt
143- default :
144- err := fmt .Errorf ("unsupported sort field: %q" , parsed .Field )
145- return "" , "" , apierrors .NewBadRequestError (ctx , err , apierrors.InvalidParameters {
146- {
147- Field : "sort" ,
148- Reason : err .Error (),
149- Source : apierrors .InvalidParamSourceQuery ,
150- },
151- })
150+ field , err := FromAPIEventSortField (ctx , parsed .Field )
151+ if err != nil {
152+ return "" , "" , err
152153 }
153154
154155 // If the caller did not supply an explicit asc/desc suffix, default to
0 commit comments