Skip to content

Commit

Permalink
Merge pull request #2447 from opengovern/feat-optimize-apis
Browse files Browse the repository at this point in the history
feat: update routes
  • Loading branch information
mohamadch91 authored Jan 13, 2025
2 parents 2325161 + b431012 commit 143ac30
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions services/compliance/http_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3175,28 +3175,11 @@ func (h *HttpHandler) GetBenchmarksSummary(echoCtx echo.Context) error {
for _, b := range benchmarks {


metadata := db.BenchmarkMetadata{}

if len(b.Metadata.Bytes) > 0 {
err := json.Unmarshal(b.Metadata.Bytes, &metadata)
if err != nil {
h.logger.Error("failed to unmarshal metadata", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
}

benchmarkDetails := api.GetBenchmarkListSummaryMetadata{
ID: b.ID,
Title: b.Title,
Description: b.Description,
Enabled: b.Enabled,
CreatedAt: b.CreatedAt,
UpdatedAt: b.UpdatedAt,
}

if b.IntegrationType != nil {
benchmarkDetails.IntegrationType = b.IntegrationType
}


items = append(items, benchmarkDetails)
}
Expand All @@ -3220,8 +3203,18 @@ func (h *HttpHandler) GetBenchmarksSummary(echoCtx echo.Context) error {
}
// finding summary of paginated benchmarks
var new_items []api.GetBenchmarkListSummaryMetadata
var benchmarkids []string
for _, item := range items {
benchmarkids = append(benchmarkids, item.ID)
}
h.logger.Info("benchmarkids", zap.Any("benchmarkids", benchmarkids))
all_benchmarks, err := h.db.GetBenchmarksBare(ctx, benchmarkids)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}


for _, benchmark := range items {
for _, benchmark := range all_benchmarks {

controls, err := h.db.ListControlsByBenchmarkID(ctx, benchmark.ID)
if err != nil {
Expand Down Expand Up @@ -3314,6 +3307,7 @@ func (h *HttpHandler) GetBenchmarksSummary(echoCtx echo.Context) error {
} else {
complianceScore = 0
}



new_items = append(new_items, api.GetBenchmarkListSummaryMetadata{
Expand Down

0 comments on commit 143ac30

Please sign in to comment.