[API] Several fixes in `GET /api/v1/governor/limit` (#153)

### Summary

Changes to `GET /api/v1/governor/limit`:
* Fix the behavior of the parameters `page` and `pageSize` (which previously were being ignored).
* When no results are found, return an HTTP status code of 200 and set the response to an empty array.
* Remove the `sortOrder` query parameter.

The rationale for removing the `sortOrder` parameter is that sorting chains by ascending/descending chain ID doesn't seem to be a useful operation.
This commit is contained in:
agodnic 2023-02-10 15:58:10 -03:00 committed by GitHub
parent e85fa82784
commit 4ca0bf1c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 38 deletions

View File

@ -231,16 +231,6 @@ const docTemplate = `{
"description": "Number of elements per page.",
"name": "pageSize",
"in": "query"
},
{
"enum": [
"ASC",
"DESC"
],
"type": "string",
"description": "Sort results in ascending or descending order.",
"name": "sortOrder",
"in": "query"
}
],
"responses": {
@ -1970,7 +1960,7 @@ const docTemplate = `{
"build": {
"type": "string"
},
"buildDate": {
"build_date": {
"type": "string"
},
"machine": {

View File

@ -224,16 +224,6 @@
"description": "Number of elements per page.",
"name": "pageSize",
"in": "query"
},
{
"enum": [
"ASC",
"DESC"
],
"type": "string",
"description": "Sort results in ascending or descending order.",
"name": "sortOrder",
"in": "query"
}
],
"responses": {
@ -1963,7 +1953,7 @@
"build": {
"type": "string"
},
"buildDate": {
"build_date": {
"type": "string"
},
"machine": {

View File

@ -307,7 +307,7 @@ definitions:
type: string
build:
type: string
buildDate:
build_date:
type: string
machine:
type: string
@ -717,13 +717,6 @@ paths:
in: query
name: pageSize
type: integer
- description: Sort results in ascending or descending order.
enum:
- ASC
- DESC
in: query
name: sortOrder
type: string
responses:
"200":
description: OK

View File

@ -954,6 +954,7 @@ func (r *Repository) GetEnqueueVassByChainID(ctx context.Context, q *EnqueuedVaa
// GetGovernorLimit get a list of *GovernorLimit.
func (r *Repository) GetGovernorLimit(ctx context.Context, q *GovernorQuery) ([]*GovernorLimit, error) {
// lookup.
lookupStage1 := bson.D{
{Key: "$lookup", Value: bson.D{
@ -1072,7 +1073,7 @@ func (r *Repository) GetGovernorLimit(ctx context.Context, q *GovernorQuery) ([]
}
// define aggregate pipeline
pipeLine := mongo.Pipeline{
pipeline := mongo.Pipeline{
lookupStage1,
unwindStage2,
projectStage3,
@ -1086,8 +1087,20 @@ func (r *Repository) GetGovernorLimit(ctx context.Context, q *GovernorQuery) ([]
sortStage11,
}
// skip initial results
if q.Pagination.Skip != 0 {
pipeline = append(pipeline, bson.D{
{"$skip", q.Pagination.Skip},
})
}
// limit size of results
pipeline = append(pipeline, bson.D{
{"$limit", q.Pagination.Limit},
})
// execute aggregate operations.
cur, err := r.collections.governorConfig.Aggregate(ctx, pipeLine)
cur, err := r.collections.governorConfig.Aggregate(ctx, pipeline)
if err != nil {
requestID := fmt.Sprintf("%v", ctx.Value("requestid"))
r.logger.Error("failed execute Aggregate command to get governor limit",
@ -1105,11 +1118,6 @@ func (r *Repository) GetGovernorLimit(ctx context.Context, q *GovernorQuery) ([]
return nil, errors.WithStack(err)
}
// check exists records
if len(governorLimits) == 0 {
return nil, errs.ErrNotFound
}
return governorLimits, nil
}

View File

@ -140,7 +140,6 @@ func (c *Controller) FindGovernorStatusByGuardianAddress(ctx *fiber.Ctx) error {
// @ID governor-notional-limit
// @Param page query integer false "Page number."
// @Param pageSize query integer false "Number of elements per page."
// @Param sortOrder query string false "Sort results in ascending or descending order." Enums(ASC, DESC)
// @Success 200 {object} response.Response[[]GovernorLimit]
// @Failure 400
// @Failure 500