Skip to content

Commit

Permalink
Use TagRefs for Archetypes, merge asessment tags
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Lucidi <slucidi@redhat.com>
  • Loading branch information
mansam committed Oct 4, 2023
1 parent 9a2a94c commit 1a5f19f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
47 changes: 26 additions & 21 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,17 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
// Archetype REST resource.
type Archetype struct {
Resource
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Comments string `json:"comments" yaml:"comments"`
Tags []Ref `json:"tags" yaml:"tags"`
CriteriaTags []Ref `json:"criteriaTags" yaml:"criteriaTags"`
AssessmentTags []Ref `json:"assessmentTags" yaml:"assessmentTags"`
Stakeholders []Ref `json:"stakeholders" yaml:"stakeholders"`
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"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
Comments string `json:"comments" yaml:"comments"`
Tags []TagRef `json:"tags" yaml:"tags"`
Criteria []TagRef `json:"criteria" yaml:"criteria"`
Stakeholders []Ref `json:"stakeholders" yaml:"stakeholders"`
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 All @@ -361,14 +360,17 @@ func (r *Archetype) With(m *model.Archetype) {
r.Name = m.Name
r.Description = m.Description
r.Comments = m.Comments
r.AssessmentTags = []Ref{}
r.Tags = []Ref{}
r.Tags = []TagRef{}
for _, t := range m.Tags {
r.Tags = append(r.Tags, r.ref(t.ID, &t))
ref := TagRef{}
ref.With(t.ID, t.Name, "", false)
r.Tags = append(r.Tags, ref)
}
r.CriteriaTags = []Ref{}
r.Criteria = []TagRef{}
for _, t := range m.CriteriaTags {
r.CriteriaTags = append(r.CriteriaTags, r.ref(t.ID, &t))
ref := TagRef{}
ref.With(t.ID, t.Name, "", false)
r.Criteria = append(r.Criteria, ref)
}
r.Stakeholders = []Ref{}
for _, s := range m.Stakeholders {
Expand Down Expand Up @@ -403,9 +405,9 @@ func (r *Archetype) WithApplications(apps []model.Application) {
// WithAssessmentTags updates the Archetype resource with tags inherited from assessments.
func (r *Archetype) WithAssessmentTags(tags []model.Tag) {
for _, t := range tags {
ref := Ref{}
ref.With(t.ID, t.Name)
r.AssessmentTags = append(r.AssessmentTags, ref)
ref := TagRef{}
ref.With(t.ID, t.Name, SourceAssessment, true)
r.Tags = append(r.Tags, ref)
}
}

Expand All @@ -419,6 +421,9 @@ func (r *Archetype) Model() (m *model.Archetype) {
}
m.ID = r.ID
for _, ref := range r.Tags {
if ref.Virtual {
continue
}
m.Tags = append(
m.Tags,
model.Tag{
Expand All @@ -427,7 +432,7 @@ func (r *Archetype) Model() (m *model.Archetype) {
},
})
}
for _, ref := range r.CriteriaTags {
for _, ref := range r.Criteria {
m.CriteriaTags = append(
m.CriteriaTags,
model.Tag{
Expand Down
4 changes: 2 additions & 2 deletions api/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ func (r *Ref) With(id uint, name string) {
type TagRef struct {
ID uint `json:"id" binding:"required"`
Name string `json:"name"`
Source string `json:"source"`
Virtual bool `json:"virtual,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
Virtual bool `json:"virtual,omitempty" yaml:"virtual,omitempty"`
}

//
Expand Down

0 comments on commit 1a5f19f

Please sign in to comment.