Skip to content

Commit

Permalink
Merge pull request #1449 from Azanul/develop
Browse files Browse the repository at this point in the history
fix: user controlled exclude list in queries
  • Loading branch information
Azanul authored Jun 19, 2024
2 parents cc0335e + 9392c74 commit 909a57b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions handlers/dashboard_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ func (handler *ApiHandler) CostBreakdownHandler(c *gin.Context) {
}
excludeList := strings.Trim(string(s), "[]")
excludeList = strings.ReplaceAll(excludeList, `"`, "'")
excludeItems := strings.Split(excludeList, ",")
for i := range excludeItems {
excludeItems[i] = strings.TrimSpace(excludeItems[i])
}

query := fmt.Sprintf(`%s ? NOT IN (%s) AND DATE(fetched_at) BETWEEN ? AND ? GROUP BY ?`, query, excludeList)
err = handler.db.NewRaw(query, bun.Ident(input.Group), input.Start, input.End, bun.Ident(input.Group)).Scan(handler.ctx, &groups)
query = query + ` ? NOT IN ? AND DATE(fetched_at) BETWEEN ? AND ? GROUP BY ?`
err = handler.db.NewRaw(query, bun.Ident(input.Group), bun.In(excludeItems), input.Start, input.End, bun.Ident(input.Group)).Scan(handler.ctx, &groups)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
Expand Down

0 comments on commit 909a57b

Please sign in to comment.