@@ -15,6 +15,7 @@ import (
15
15
"kusionstack.io/kusion/pkg/domain/response"
16
16
"kusionstack.io/kusion/pkg/server/handler"
17
17
"kusionstack.io/kusion/pkg/server/manager/variableset"
18
+ "kusionstack.io/kusion/pkg/server/middleware"
18
19
logutil "kusionstack.io/kusion/pkg/server/util/logging"
19
20
)
20
21
@@ -100,7 +101,7 @@ func (h *Handler) DeleteVariableSet() http.HandlerFunc {
100
101
// @Failure 429 {object} error "Too Many Requests"
101
102
// @Failure 404 {object} error "Not Found"
102
103
// @Failure 500 {object} error "Internal Server Error"
103
- // @Router /api/v1/variablesets/{variableSetName} [put]
104
+ // @Router /api/v1/variablesets/{variableSetName} [put]
104
105
func (h * Handler ) UpdateVariableSet () http.HandlerFunc {
105
106
return func (w http.ResponseWriter , r * http.Request ) {
106
107
// Getting stuff from context.
@@ -147,7 +148,7 @@ func (h *Handler) UpdateVariableSet() http.HandlerFunc {
147
148
// @Failure 429 {object} error "Too Many Requests"
148
149
// @Failure 404 {object} error "Not Found"
149
150
// @Failure 500 {object} error "Internal Server Error"
150
- // @Router /api/v1/variablesets/{variableSetName} [get]
151
+ // @Router /api/v1/variablesets/{variableSetName} [get]
151
152
func (h * Handler ) GetVariableSet () http.HandlerFunc {
152
153
return func (w http.ResponseWriter , r * http.Request ) {
153
154
// Getting stuff from context.
@@ -172,7 +173,7 @@ func (h *Handler) GetVariableSet() http.HandlerFunc {
172
173
// @Param page query uint false "The current page to fetch. Default to 1"
173
174
// @Param pageSize query uint false "The size of the page. Default to 10"
174
175
// @Param sortBy query string false "Which field to sort the list by. Default to id"
175
- // @Param ascending query bool false "Whether to sort the list in ascending order. Default to false"
176
+ // @Param descending query bool false "Whether to sort the list in descending order. Default to false"
176
177
// @Param fetchAll query bool false "Whether to list all the variable sets"
177
178
// @Success 200 {object} handler.Response{data=response.PaginatedVariableSetResponse} "Success"
178
179
// @Failure 400 {object} error "Bad Request"
@@ -204,6 +205,12 @@ func (h *Handler) ListVariableSets() http.HandlerFunc {
204
205
return
205
206
}
206
207
208
+ // If the amount of variable sets exceeds the maximum result limit,
209
+ // then indicate in the response message.
210
+ if len (variableSetEntities .VariableSets ) < variableSetEntities .Total {
211
+ ctx = context .WithValue (ctx , middleware .ResponseMessageKey , "the result exceeds the maximum amount limit" )
212
+ }
213
+
207
214
paginatedResponse := response.PaginatedVariableSetResponse {
208
215
VariableSets : variableSetEntities .VariableSets ,
209
216
Total : variableSetEntities .Total ,
@@ -247,13 +254,13 @@ func (h *Handler) ListVariableSetsByLabels() http.HandlerFunc {
247
254
filter := & entity.VariableSetFilter {
248
255
Pagination : & entity.Pagination {
249
256
Page : constant .CommonPageDefault ,
250
- PageSize : constant .CommonPageSizeDefault ,
257
+ PageSize : constant .CommonMaxResultLimit ,
251
258
},
252
259
FetchAll : true ,
253
260
}
254
261
sortOptions := & entity.SortOptions {
255
- Field : constant .SortByID ,
256
- Ascending : false ,
262
+ Field : constant .SortByID ,
263
+ Descending : false ,
257
264
}
258
265
259
266
variableSetEntities , err := h .variableSetManager .ListVariableSets (ctx , filter , sortOptions )
@@ -263,21 +270,9 @@ func (h *Handler) ListVariableSetsByLabels() http.HandlerFunc {
263
270
}
264
271
265
272
// If the amount of variable sets exceeds the maximum result limit,
266
- // then retrieve the complete result through a looped query.
267
- for len (variableSetEntities .VariableSets ) < variableSetEntities .Total {
268
- filter = & entity.VariableSetFilter {
269
- Pagination : & entity.Pagination {
270
- Page : 2 ,
271
- PageSize : len (variableSetEntities .VariableSets ),
272
- },
273
- FetchAll : true ,
274
- }
275
- tmpVariableSetEntities , err := h .variableSetManager .ListVariableSets (ctx , filter , sortOptions )
276
- if err != nil {
277
- render .Render (w , r , handler .FailureResponse (ctx , err ))
278
- return
279
- }
280
- variableSetEntities .VariableSets = append (variableSetEntities .VariableSets , tmpVariableSetEntities .VariableSets ... )
273
+ // then indicate in the response message.
274
+ if len (variableSetEntities .VariableSets ) < variableSetEntities .Total {
275
+ ctx = context .WithValue (ctx , middleware .ResponseMessageKey , "the result exceeds the maximum amount limit" )
281
276
}
282
277
283
278
var matchedVariableSets []* entity.VariableSet
0 commit comments