Skip to content

Commit e14a4bb

Browse files
authored
✨ API updates for platform awareness. (#874)
Filter apps on platform id: GET /applications?filter=platform.id=1 Closes #872 Add platform to the task dashboard. Closes #875 Add list of manifest (refs) to application. Closes #876 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Applications listing API now supports server-side filtering by platform ID. * Applications listing now includes manifest references for each application. * Task dashboard responses now include platform information for each task when available. * **Documentation** * API docs updated to describe the platform ID filter and the new manifest and platform fields in responses. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jeff Ortel <[email protected]>
1 parent a1f66e2 commit e14a4bb

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

api/application.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/gin-gonic/gin"
10+
qf "github.com/konveyor/tackle2-hub/api/filter"
1011
"github.com/konveyor/tackle2-hub/api/jsd"
1112
"github.com/konveyor/tackle2-hub/assessment"
1213
"github.com/konveyor/tackle2-hub/metrics"
@@ -145,6 +146,8 @@ func (h ApplicationHandler) Get(ctx *gin.Context) {
145146
// List godoc
146147
// @summary List all applications.
147148
// @description List all applications.
149+
// @description filters:
150+
// @description - platform.id
148151
// @tags applications
149152
// @produce json
150153
// @success 200 {object} []api.Application
@@ -173,6 +176,16 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
173176
return
174177
}
175178

179+
filter, err := qf.New(ctx,
180+
[]qf.Assert{
181+
{Field: "platform.id", Kind: qf.LITERAL},
182+
})
183+
if err != nil {
184+
_ = ctx.Error(err)
185+
return
186+
}
187+
filter = filter.Renamed("platform.id", "PlatformId")
188+
176189
type M struct {
177190
*model.Application
178191
IdentityId uint
@@ -189,6 +202,7 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
189202
PlatformName string
190203
ReviewId uint
191204
AssessmentId uint
205+
ManifestId uint
192206
QuestionnaireId uint
193207
AnalysisId uint
194208
Effort int
@@ -210,6 +224,7 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
210224
"pf.Name PlatformName",
211225
"rv.ID ReviewId",
212226
"at.ID AssessmentId",
227+
"mf.ID ManifestId",
213228
"at.QuestionnaireID QuestionnaireId",
214229
"an.ID AnalysisId",
215230
"an.Effort Effort",
@@ -225,8 +240,10 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
225240
db = db.Joins("LEFT JOIN Platform pf ON pf.ID = a.PlatformID")
226241
db = db.Joins("LEFT JOIN Review rv ON rv.ApplicationID = a.ID")
227242
db = db.Joins("LEFT JOIN Assessment at ON at.ApplicationID = a.ID")
243+
db = db.Joins("LEFT JOIN Manifest mf ON mf.ApplicationID = a.ID")
228244
db = db.Joins("LEFT JOIN Analysis an ON an.ApplicationID = a.ID")
229245
db = db.Order("a.ID")
246+
db = filter.Where(db)
230247
page := Page{}
231248
page.With(ctx)
232249
cursor := Cursor{}
@@ -236,6 +253,7 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
236253
identities := make(map[uint]model.Identity)
237254
contributors := make(map[uint]model.Stakeholder)
238255
assessments := make(map[uint]model.Assessment)
256+
manifests := make(map[uint]model.Manifest)
239257
analyses := make(map[uint]model.Analysis)
240258
for i := range batch {
241259
m := batch[i].(*M)
@@ -282,6 +300,11 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
282300
ref.QuestionnaireID = m.QuestionnaireId
283301
assessments[m.AssessmentId] = ref
284302
}
303+
if m.ManifestId > 0 {
304+
ref := model.Manifest{}
305+
ref.ID = m.ManifestId
306+
manifests[m.ManifestId] = ref
307+
}
285308
if m.AnalysisId > 0 {
286309
ref := model.Analysis{}
287310
ref.ID = m.AnalysisId
@@ -298,6 +321,9 @@ func (h ApplicationHandler) List(ctx *gin.Context) {
298321
for _, m := range assessments {
299322
app.Assessments = append(app.Assessments, m)
300323
}
324+
for _, m := range manifests {
325+
app.Manifest = append(app.Manifest, m)
326+
}
301327
for _, m := range analyses {
302328
app.Analyses = append(app.Analyses, m)
303329
}
@@ -1311,6 +1337,7 @@ type Application struct {
13111337
Platform *Ref `json:"platform"`
13121338
Archetypes []Ref `json:"archetypes"`
13131339
Assessments []Ref `json:"assessments"`
1340+
Manifests []Ref `json:"manifests"`
13141341
Assessed bool `json:"assessed"`
13151342
Risk string `json:"risk"`
13161343
Confidence int `json:"confidence"`
@@ -1381,6 +1408,10 @@ func (r *Application) With(m *model.Application, tags []AppTag) {
13811408
})
13821409
r.Effort = m.Analyses[len(m.Analyses)-1].Effort
13831410
}
1411+
r.Manifests = []Ref{}
1412+
for _, mf := range m.Manifest {
1413+
r.Manifests = append(r.Manifests, Ref{ID: mf.ID})
1414+
}
13841415
r.Risk = assessment.RiskUnassessed
13851416
}
13861417

api/task.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ type TaskDashboard struct {
10061006
State string `json:"state,omitempty" yaml:",omitempty"`
10071007
Locator string `json:"locator,omitempty" yaml:",omitempty"`
10081008
Application *Ref `json:"application,omitempty" yaml:",omitempty"`
1009+
Platform *Ref `json:"platform,omitempty" yaml:",omitempty"`
10091010
Started *time.Time `json:"started,omitempty" yaml:",omitempty"`
10101011
Terminated *time.Time `json:"terminated,omitempty" yaml:",omitempty"`
10111012
Errors int `json:"errors,omitempty" yaml:",omitempty"`
@@ -1019,6 +1020,7 @@ func (r *TaskDashboard) With(m *model.Task) {
10191020
r.State = m.State
10201021
r.Locator = m.Locator
10211022
r.Application = r.refPtr(m.ApplicationID, m.Application)
1023+
r.Platform = r.refPtr(m.PlatformID, m.Platform)
10221024
r.Started = m.Started
10231025
r.Terminated = m.Terminated
10241026
r.Errors = len(m.Errors)

0 commit comments

Comments
 (0)