Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Increment assessment counter when a new one is created #511

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading