WIP: start renaming of simulaton model to component configuration in IC endpoints

This commit is contained in:
Sonja Happ 2020-03-04 16:41:18 +01:00
parent 11a0c53b85
commit bff9efa063
2 changed files with 12 additions and 12 deletions

View file

@ -35,7 +35,7 @@ func RegisterICEndpoints(r *gin.RouterGroup) {
r.PUT("/:ICID", updateIC)
r.GET("/:ICID", getIC)
r.DELETE("/:ICID", deleteIC)
r.GET("/:ICID/models", getConfigsOfIC)
r.GET("/:ICID/configs", getConfigsOfIC)
}
// getICs godoc
@ -216,7 +216,7 @@ func deleteIC(c *gin.Context) {
// @Failure 500 {object} docs.ResponseError "Internal server error"
// @Param Authorization header string true "Authorization token"
// @Param ICID path int true "Infrastructure Component ID"
// @Router /ic/{ICID}/models [get]
// @Router /ic/{ICID}/configs [get]
func getConfigsOfIC(c *gin.Context) {
ok, s := CheckPermissions(c, database.ModelInfrastructureComponent, database.Read, true)
@ -224,10 +224,10 @@ func getConfigsOfIC(c *gin.Context) {
return
}
// get all associated simulation models
allModels, _, err := s.getModels()
// get all associated configurations
allConfigs, _, err := s.getConfigs()
if !helper.DBError(c, err) {
c.JSON(http.StatusOK, gin.H{"simulationModels": allModels})
c.JSON(http.StatusOK, gin.H{"configs": allConfigs})
}
}

View file

@ -54,10 +54,10 @@ func (s *InfrastructureComponent) update(updatedIC InfrastructureComponent) erro
func (s *InfrastructureComponent) delete() error {
db := database.GetDB()
no_simulationmodels := db.Model(s).Association("SimulationModels").Count()
no_configs := db.Model(s).Association("SimulationModels").Count()
if no_simulationmodels > 0 {
return fmt.Errorf("InfrastructureComponent cannot be deleted as it is still used in SimulationModels (active or dangling)")
if no_configs > 0 {
return fmt.Errorf("InfrastructureComponent cannot be deleted as it is still used in configurations (active or dangling)")
}
// delete InfrastructureComponent from DB (does NOT remain as dangling)
@ -65,9 +65,9 @@ func (s *InfrastructureComponent) delete() error {
return err
}
func (s *InfrastructureComponent) getModels() ([]database.SimulationModel, int, error) {
func (s *InfrastructureComponent) getConfigs() ([]database.SimulationModel, int, error) {
db := database.GetDB()
var models []database.SimulationModel
err := db.Order("ID asc").Model(s).Related(&models, "SimulationModels").Error
return models, len(models), err
var configs []database.SimulationModel
err := db.Order("ID asc").Model(s).Related(&configs, "SimulationModels").Error
return configs, len(configs), err
}