From 50f891d8ae9ad3bdf275769ecd4f730696248fef Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 27 Jul 2021 10:07:59 +0200 Subject: [PATCH] remove InputLength and OutputLength from ComponentConfig data model --- database/models.go | 4 --- routes/signal/signal_methods.go | 49 ++++++++------------------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/database/models.go b/database/models.go index 13604f1..fe4e918 100644 --- a/database/models.go +++ b/database/models.go @@ -81,10 +81,6 @@ type ComponentConfiguration struct { Model // Name of Component Configuration Name string `json:"name" gorm:"not null"` - // Number of output signals - OutputLength int `json:"outputLength" gorm:"default:0"` - // Number of input signals - InputLength int `json:"inputLength" gorm:"default:0"` // Start parameters of Component Configuration as JSON StartParameters postgres.Jsonb `json:"startParameters"` // ID of Scenario to which Component Configuration belongs diff --git a/routes/signal/signal_methods.go b/routes/signal/signal_methods.go index 8f8e43b..fb0a269 100644 --- a/routes/signal/signal_methods.go +++ b/routes/signal/signal_methods.go @@ -47,8 +47,9 @@ func (s *Signal) byID(id uint) error { func (s *Signal) addToConfig() error { db := database.GetDB() + var err error var m component_configuration.ComponentConfiguration - err := m.ByID(s.ConfigID) + err = m.ByID(s.ConfigID) if err != nil { return err } @@ -62,24 +63,14 @@ func (s *Signal) addToConfig() error { // associate signal with component configuration in correct direction if s.Direction == "in" { err = db.Model(&m).Association("InputMapping").Append(s).Error - if err != nil { - return err - } - - // adapt length of mapping - var newInputLength = db.Model(&m).Where("Direction = ?", "in").Association("InputMapping").Count() - err = db.Model(&m).Update("InputLength", newInputLength).Error - } else { err = db.Model(&m).Association("OutputMapping").Append(s).Error - if err != nil { - return err - } - - // adapt length of mapping - var newOutputLength = db.Model(&m).Where("Direction = ?", "out").Association("OutputMapping").Count() - err = db.Model(&m).Update("OutputLength", newOutputLength).Error } + + if err != nil { + return err + } + return err } @@ -100,8 +91,9 @@ func (s *Signal) update(modifiedSignal Signal) error { func (s *Signal) delete() error { db := database.GetDB() + var err error var m component_configuration.ComponentConfiguration - err := m.ByID(s.ConfigID) + err = m.ByID(s.ConfigID) if err != nil { return err } @@ -109,29 +101,12 @@ func (s *Signal) delete() error { // remove association between Signal and ComponentConfiguration if s.Direction == "in" { err = db.Model(&m).Association("InputMapping").Delete(s).Error - if err != nil { - return err - } - - // Update input length - noSignals := db.Model(&m).Association("InputMapping").Count() - err = db.Model(&m).Update("InputLength", noSignals).Error - if err != nil { - return err - } - } else { err = db.Model(&m).Association("OutputMapping").Delete(s).Error - if err != nil { - return err - } + } - // Reduce output length - noSignals := db.Model(&m).Association("OutputMapping").Count() - err = db.Model(&m).Update("OutputLength", noSignals).Error - if err != nil { - return err - } + if err != nil { + return err } // Delete signal