mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
remove InputLength and OutputLength from ComponentConfig data model
This commit is contained in:
parent
d03937e34c
commit
50f891d8ae
2 changed files with 12 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue