diff --git a/api/application.go b/api/application.go index 3d4940c89..7169d1c2e 100644 --- a/api/application.go +++ b/api/application.go @@ -58,22 +58,22 @@ func (h ApplicationHandler) AddRoutes(e *gin.Engine) { routeGroup.DELETE(ApplicationRoot, h.Delete) // Tags routeGroup = e.Group("/") - routeGroup.Use(Required("applications"), Transaction) + routeGroup.Use(Required("applications")) routeGroup.GET(ApplicationTagsRoot, h.TagList) routeGroup.GET(ApplicationTagsRoot+"/", h.TagList) routeGroup.POST(ApplicationTagsRoot, h.TagAdd) routeGroup.DELETE(ApplicationTagRoot, h.TagDelete) - routeGroup.PUT(ApplicationTagsRoot, h.TagReplace) + routeGroup.PUT(ApplicationTagsRoot, h.TagReplace, Transaction) // Facts routeGroup = e.Group("/") - routeGroup.Use(Required("applications.facts"), Transaction) + routeGroup.Use(Required("applications.facts")) routeGroup.GET(ApplicationFactsRoot, h.FactGet) routeGroup.GET(ApplicationFactsRoot+"/", h.FactGet) routeGroup.POST(ApplicationFactsRoot, h.FactCreate) routeGroup.GET(ApplicationFactRoot, h.FactGet) routeGroup.PUT(ApplicationFactRoot, h.FactPut) routeGroup.DELETE(ApplicationFactRoot, h.FactDelete) - routeGroup.PUT(ApplicationFactsRoot, h.FactPut) + routeGroup.PUT(ApplicationFactsRoot, h.FactPut, Transaction) // Bucket routeGroup = e.Group("/") routeGroup.Use(Required("applications.bucket")) @@ -84,11 +84,11 @@ func (h ApplicationHandler) AddRoutes(e *gin.Engine) { routeGroup.DELETE(AppBucketContentRoot, h.BucketDelete) // Stakeholders routeGroup = e.Group("/") - routeGroup.Use(Required("applications.stakeholders"), Transaction) + routeGroup.Use(Required("applications.stakeholders")) routeGroup.PUT(AppStakeholdersRoot, h.StakeholdersUpdate) // Assessments routeGroup = e.Group("/") - routeGroup.Use(Required("applications.assessments"), Transaction) + routeGroup.Use(Required("applications.assessments")) routeGroup.GET(AppAssessmentsRoot, h.AssessmentList) routeGroup.POST(AppAssessmentsRoot, h.AssessmentCreate) } @@ -210,23 +210,11 @@ func (h ApplicationHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Omit(clause.Associations).Create(m) + result := h.DB(ctx).Omit("Tags").Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - db := h.DB(ctx).Model(m) - err = db.Association("Identities").Replace(m.Identities) - if err != nil { - _ = ctx.Error(err) - return - } - db = h.DB(ctx).Model(m) - err = db.Association("Contributors").Replace(m.Contributors) - if err != nil { - _ = ctx.Error(err) - return - } tags := []model.ApplicationTag{} if len(r.Tags) > 0 { @@ -1090,21 +1078,11 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { assessment.PrepareForApplication(resolver, application, m) newAssessment = true } - result = h.DB(ctx).Omit(clause.Associations).Create(m) + result = h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) - if err != nil { - _ = ctx.Error(err) - return - } if newAssessment { metrics.AssessmentsInitiated.Inc() } @@ -1160,7 +1138,6 @@ func (r *Application) With(m *model.Application, tags []model.ApplicationTag) { r.Identities, ref) } - r.Tags = []TagRef{} for i := range tags { ref := TagRef{} ref.With(tags[i].TagID, tags[i].Tag.Name, tags[i].Source, false) diff --git a/api/archetype.go b/api/archetype.go index bcadf05cd..d62d88a13 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -136,33 +136,12 @@ func (h ArchetypeHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.CurrentUser(ctx) - result := h.DB(ctx).Omit(clause.Associations).Create(m) + result := h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("CriteriaTags").Replace("CriteriaTags", m.CriteriaTags) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("Tags").Replace("Tags", m.Tags) - if err != nil { - _ = ctx.Error(err) - return - } - archetypes := []model.Archetype{} db := h.preLoad(h.DB(ctx), "Tags", "CriteriaTags") result = db.Find(&archetypes) @@ -340,21 +319,11 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { assessment.PrepareForArchetype(resolver, archetype, m) newAssessment = true } - result = h.DB(ctx).Omit(clause.Associations).Create(m) + result = h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) - if err != nil { - _ = ctx.Error(err) - return - } if newAssessment { metrics.AssessmentsInitiated.Inc() } diff --git a/api/group.go b/api/group.go index dee59ff97..4e92337b3 100644 --- a/api/group.go +++ b/api/group.go @@ -97,21 +97,11 @@ func (h StakeholderGroupHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Omit(clause.Associations).Create(m) + result := h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Stakeholders").Replace(m.Stakeholders) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("MigrationWaves").Replace(m.MigrationWaves) - if err != nil { - _ = ctx.Error(err) - return - } r.With(m) h.Respond(ctx, http.StatusCreated, r) diff --git a/api/identity.go b/api/identity.go index 8c631c6f7..dbaf606dd 100644 --- a/api/identity.go +++ b/api/identity.go @@ -34,7 +34,7 @@ func (h IdentityHandler) AddRoutes(e *gin.Engine) { routeGroup.GET(IdentitiesRoot+"/", h.setDecrypted, h.List) routeGroup.POST(IdentitiesRoot, h.Create) routeGroup.GET(IdentityRoot, h.setDecrypted, h.Get) - routeGroup.PUT(IdentityRoot, Transaction, h.Update) + routeGroup.PUT(IdentityRoot, h.Update, Transaction) routeGroup.DELETE(IdentityRoot, h.Delete) } diff --git a/api/migrationwave.go b/api/migrationwave.go index 128bb485f..8651a369e 100644 --- a/api/migrationwave.go +++ b/api/migrationwave.go @@ -98,26 +98,11 @@ func (h MigrationWaveHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.CurrentUser(ctx) - result := h.DB(ctx).Omit(clause.Associations).Create(m) + result := h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Applications").Replace("Applications", m.Applications) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("Stakeholders").Replace("Stakeholders", m.Stakeholders) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("StakeholderGroups").Replace("StakeholderGroups", m.StakeholderGroups) - if err != nil { - _ = ctx.Error(err) - return - } r.With(m) h.Respond(ctx, http.StatusCreated, r) diff --git a/api/stakeholder.go b/api/stakeholder.go index 1a551cf4d..4cb659310 100644 --- a/api/stakeholder.go +++ b/api/stakeholder.go @@ -97,31 +97,11 @@ func (h StakeholderHandler) Create(ctx *gin.Context) { } m := r.Model() m.CreateUser = h.BaseHandler.CurrentUser(ctx) - result := h.DB(ctx).Omit(clause.Associations).Create(m) + result := h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } - err = h.DB(ctx).Model(m).Association("Groups").Replace(m.Groups) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("Owns").Replace(m.Owns) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("Contributes").Replace(m.Contributes) - if err != nil { - _ = ctx.Error(err) - return - } - err = h.DB(ctx).Model(m).Association("MigrationWaves").Replace(m.MigrationWaves) - if err != nil { - _ = ctx.Error(err) - return - } r.With(m) h.Respond(ctx, http.StatusCreated, r)