Skip to content

Commit

Permalink
Inc assessment counter when a new one is created
Browse files Browse the repository at this point in the history
Fixes konveyor#510

Signed-off-by: Sam Lucidi <[email protected]>
  • Loading branch information
mansam committed Oct 9, 2023
1 parent 47a3daa commit 8c5caa4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/konveyor/tackle2-hub/assessment"
"github.com/konveyor/tackle2-hub/metrics"
"github.com/konveyor/tackle2-hub/model"
"gorm.io/gorm/clause"
"net/http"
Expand Down Expand Up @@ -1074,6 +1075,7 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) {
m.CreateUser = h.CurrentUser(ctx)
// if sections aren't empty that indicates that this assessment is being
// created "as-is" and should not have its sections populated or autofilled.
newAssessment := false
if len(m.Sections) == 0 {
m.Sections = q.Sections
resolver, rErr := assessment.NewTagResolver(h.DB(ctx))
Expand All @@ -1082,12 +1084,16 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) {
return
}
assessment.PrepareForApplication(resolver, application, m)
newAssessment = true
}
result = h.DB(ctx).Create(m)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}
if newAssessment {
metrics.AssessmentsInitiated.Inc()
}

r.With(m)
h.Respond(ctx, http.StatusCreated, r)
Expand Down
6 changes: 6 additions & 0 deletions api/archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"github.com/gin-gonic/gin"
"github.com/konveyor/tackle2-hub/assessment"
"github.com/konveyor/tackle2-hub/metrics"
"github.com/konveyor/tackle2-hub/model"
"gorm.io/gorm/clause"
"net/http"
Expand Down Expand Up @@ -317,6 +318,7 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
m.CreateUser = h.CurrentUser(ctx)
// if sections aren't empty that indicates that this assessment is being
// created "as-is" and should not have its sections populated or autofilled.
newAssessment := false
if len(m.Sections) == 0 {
m.Sections = q.Sections
resolver, rErr := assessment.NewTagResolver(h.DB(ctx))
Expand All @@ -325,12 +327,16 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) {
return
}
assessment.PrepareForArchetype(resolver, archetype, m)
newAssessment = true
}
result = h.DB(ctx).Create(m)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
}
if newAssessment {
metrics.AssessmentsInitiated.Inc()
}

r.With(m)
h.Respond(ctx, http.StatusCreated, r)
Expand Down

0 comments on commit 8c5caa4

Please sign in to comment.