Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE-636-backwards-compatibility | Backwards compatibility support #582

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading