(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, scaleSetID uint, preload ...string)
| 252 | } |
| 253 | |
| 254 | func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, scaleSetID uint, preload ...string) (ScaleSet, error) { |
| 255 | if entityID == "" { |
| 256 | return ScaleSet{}, fmt.Errorf("error missing entity id: %w", runnerErrors.ErrBadRequest) |
| 257 | } |
| 258 | |
| 259 | if scaleSetID == 0 { |
| 260 | return ScaleSet{}, fmt.Errorf("error missing scaleset id: %w", runnerErrors.ErrBadRequest) |
| 261 | } |
| 262 | |
| 263 | var fieldName string |
| 264 | var entityField string |
| 265 | switch entityType { |
| 266 | case params.ForgeEntityTypeRepository: |
| 267 | fieldName = entityTypeRepoName |
| 268 | entityField = "Repository" |
| 269 | case params.ForgeEntityTypeOrganization: |
| 270 | fieldName = entityTypeOrgName |
| 271 | entityField = "Organization" |
| 272 | case params.ForgeEntityTypeEnterprise: |
| 273 | fieldName = entityTypeEnterpriseName |
| 274 | entityField = "Enterprise" |
| 275 | default: |
| 276 | return ScaleSet{}, fmt.Errorf("invalid entityType: %v", entityType) |
| 277 | } |
| 278 | |
| 279 | q := tx |
| 280 | q = q.Preload(entityField) |
| 281 | if len(preload) > 0 { |
| 282 | for _, item := range preload { |
| 283 | q = q.Preload(item) |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | var scaleSet ScaleSet |
| 288 | condition := fmt.Sprintf("id = ? and %s = ?", fieldName) |
| 289 | err := q.Model(&ScaleSet{}). |
| 290 | Where(condition, scaleSetID, entityID). |
| 291 | First(&scaleSet).Error |
| 292 | if err != nil { |
| 293 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 294 | return ScaleSet{}, fmt.Errorf("error finding scale set: %w", runnerErrors.ErrNotFound) |
| 295 | } |
| 296 | return ScaleSet{}, fmt.Errorf("error fetching scale set: %w", err) |
| 297 | } |
| 298 | |
| 299 | return scaleSet, nil |
| 300 | } |
| 301 | |
| 302 | // nolint:gocyclo |
| 303 | func (s *sqlDatabase) updateScaleSet(tx *gorm.DB, scaleSet ScaleSet, param params.UpdateScaleSetParams) (params.ScaleSet, int64, error) { |
no outgoing calls
no test coverage detected