Skip to content

Commit

Permalink
Feat: add filterQuoteAge
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Jul 30, 2024
1 parent 399fd60 commit 0cc05e3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion services/rfq/api/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package rest

import (
"fmt"
"github.com/synapsecns/sanguine/services/rfq/api/config"
"net/http"
"strconv"
"time"

"github.com/synapsecns/sanguine/services/rfq/api/config"

"github.com/gin-gonic/gin"
"github.com/shopspring/decimal"
Expand Down Expand Up @@ -210,6 +212,9 @@ func (h *Handler) GetQuotes(c *gin.Context) {
}
}

// Filter quotes
dbQuotes = filterQuoteAge(h.cfg, dbQuotes)

// Convert quotes from db model to api model
quotes := make([]*model.GetQuoteResponse, len(dbQuotes))
for i, dbQuote := range dbQuotes {
Expand All @@ -236,3 +241,17 @@ func (h *Handler) GetContracts(c *gin.Context) {
}
c.JSON(http.StatusOK, model.GetContractsResponse{Contracts: contracts})
}

func filterQuoteAge(cfg config.Config, dbQuotes []*db.Quote) []*db.Quote {
maxAge := cfg.GetMaxQuoteAge()

thresh := time.Now().Add(-maxAge)
var filteredQuotes []*db.Quote
for _, quote := range dbQuotes {
if quote.UpdatedAt.After(thresh) {
filteredQuotes = append(filteredQuotes, quote)
}
}

return filteredQuotes
}

0 comments on commit 0cc05e3

Please sign in to comment.