Skip to content

Commit

Permalink
BE-636-backwards-compatibility | Backwards compatibility support (#582)…
Browse files Browse the repository at this point in the history
… (#583)

Adds backwards compatibility support for /pools endpoint allowing independent deployment of SQS

(cherry picked from commit 16e9207)

Co-authored-by: Deividas Petraitis <hi@deividaspetraitis.lt>
  • Loading branch information
mergify[bot] and deividaspetraitis authored Dec 4, 2024
1 parent bc47293 commit 6743fcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/api/v1beta1/pools/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func (r *GetPoolsRequest) UnmarshalHTTPRequest(c echo.Context) error {
return nil
}

// IsLegacy checks if request contains deprecated query parameters.
// It's used to determine backward compatibility.
func (r *GetPoolsRequest) IsLegacy(c echo.Context) bool {
return c.QueryParam(queryIDs) != "" ||
c.QueryParam(queryMinLiquidityCap) != "" ||
c.QueryParam(queryWithMarketIncentives) != ""
}

// IsPresent checks if the pagination request is present in the HTTP request.
func (r *GetPoolsRequestFilter) IsPresent(c echo.Context) bool {
return c.QueryParam(queryIDs) != "" ||
Expand Down
8 changes: 6 additions & 2 deletions pools/delivery/http/pools_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (a *PoolsHandler) GetPools(c echo.Context) error {
}

// Convert pools to the appropriate format
resultPools := convertPoolsToResponse(&req, pools, total)
resultPools := convertPoolsToResponse(c, &req, pools, total)

return c.JSON(http.StatusOK, resultPools)
}
Expand Down Expand Up @@ -210,12 +210,16 @@ func convertPoolToResponse(pool sqsdomain.PoolI) PoolResponse {
}

// convertPoolsToResponse converts the given pools to the appropriate response type.
func convertPoolsToResponse(req *api.GetPoolsRequest, p []sqsdomain.PoolI, total uint64) *GetPoolsResponse {
func convertPoolsToResponse(c echo.Context, req *api.GetPoolsRequest, p []sqsdomain.PoolI, total uint64) any {
pools := make([]PoolResponse, 0, len(p))
for _, pool := range p {
pools = append(pools, convertPoolToResponse(pool))
}

if req.IsLegacy(c) {
return pools // backward compatibility
}

return &GetPoolsResponse{
Data: pools,
Meta: v1beta1.NewPaginationResponse(req.Pagination, total),
Expand Down

0 comments on commit 6743fcc

Please sign in to comment.