Skip to content

Commit

Permalink
✨ Add assessed field to Archetype REST resource (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
mansam authored Oct 3, 2023
1 parent f8b66f2 commit 6bb1e25
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ func (h ArchetypeHandler) Get(ctx *gin.Context) {
return
}

resolver, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
_ = ctx.Error(err)
return
}

r := Archetype{}
r.With(m)
r.WithApplications(applications)
r.Assessed = resolver.Assessed(m.Assessments)
h.Respond(ctx, http.StatusOK, r)
}

Expand All @@ -86,17 +93,25 @@ func (h ArchetypeHandler) List(ctx *gin.Context) {
return
}

resolver, err := assessment.NewQuestionnaireResolver(h.DB(ctx))
if err != nil {
_ = ctx.Error(err)
return
}

membership := assessment.NewMembershipResolver(h.DB(ctx))
resources := []Archetype{}
for i := range list {
m := &list[i]
r := Archetype{}
applications, err := membership.Applications(&list[i])
applications, err := membership.Applications(m)
if err != nil {
_ = ctx.Error(err)
return
}
r.With(&list[i])
r.With(m)
r.WithApplications(applications)
r.Assessed = resolver.Assessed(m.Assessments)
resources = append(resources, r)
}

Expand Down Expand Up @@ -320,6 +335,7 @@ type Archetype struct {
StakeholderGroups []Ref `json:"stakeholderGroups" yaml:"stakeholderGroups"`
Applications []Ref `json:"applications" yaml:"applications"`
Assessments []Ref `json:"assessments" yaml:"assessments"`
Assessed bool `json:"assessed"`
Review *Ref `json:"review"`
}

Expand Down

0 comments on commit 6bb1e25

Please sign in to comment.