Skip to content

Commit

Permalink
fix: user controlled exclude list in queries
Browse files Browse the repository at this point in the history
Signed-off-by: Azanul <[email protected]>
  • Loading branch information
Azanul committed Jun 19, 2024
1 parent 51d70de commit 14e1423
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 14e1423

Please sign in to comment.