Skip to content

Commit

Permalink
✨ Surface latest analysis effort on Application resource (#537)
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam authored Oct 24, 2023
1 parent 77fa5af commit 2c1728e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/konveyor/tackle2-hub/model"
"gorm.io/gorm/clause"
"net/http"
"sort"
"strings"
)

Expand Down Expand Up @@ -107,7 +108,6 @@ func (h ApplicationHandler) Get(ctx *gin.Context) {
m := &model.Application{}
id := h.pk(ctx)
db := h.preLoad(h.DB(ctx), clause.Associations)
db = db.Omit("Analyses")
result := db.First(m, id)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down Expand Up @@ -154,7 +154,6 @@ func (h ApplicationHandler) Get(ctx *gin.Context) {
func (h ApplicationHandler) List(ctx *gin.Context) {
var list []model.Application
db := h.preLoad(h.DB(ctx), clause.Associations)
db = db.Omit("Analyses")
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down Expand Up @@ -1078,6 +1077,7 @@ type Application struct {
Assessed bool `json:"assessed"`
Risk string `json:"risk"`
Confidence int `json:"confidence"`
Effort int `json:"effort"`
}

//
Expand Down Expand Up @@ -1125,6 +1125,13 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) {
ref.With(a.ID, "")
r.Assessments = append(r.Assessments, ref)
}

if len(m.Analyses) > 0 {
sort.Slice(m.Analyses, func(i, j int) bool {
return m.Analyses[i].ID < m.Analyses[j].ID
})
r.Effort = m.Analyses[len(m.Analyses)-1].Effort
}
}

//
Expand Down

0 comments on commit 2c1728e

Please sign in to comment.