(tx *gorm.DB, entityType params.ForgeEntityType, entityID, poolID string, preload ...string)
| 101 | } |
| 102 | |
| 103 | func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.ForgeEntityType, entityID, poolID string, preload ...string) (Pool, error) { |
| 104 | if entityID == "" { |
| 105 | return Pool{}, fmt.Errorf("error missing entity id: %w", runnerErrors.ErrBadRequest) |
| 106 | } |
| 107 | |
| 108 | u, err := uuid.Parse(poolID) |
| 109 | if err != nil { |
| 110 | return Pool{}, fmt.Errorf("error parsing id: %w", runnerErrors.ErrBadRequest) |
| 111 | } |
| 112 | |
| 113 | var fieldName string |
| 114 | var entityField string |
| 115 | switch entityType { |
| 116 | case params.ForgeEntityTypeRepository: |
| 117 | fieldName = entityTypeRepoName |
| 118 | entityField = repositoryFieldName |
| 119 | case params.ForgeEntityTypeOrganization: |
| 120 | fieldName = entityTypeOrgName |
| 121 | entityField = organizationFieldName |
| 122 | case params.ForgeEntityTypeEnterprise: |
| 123 | fieldName = entityTypeEnterpriseName |
| 124 | entityField = enterpriseFieldName |
| 125 | default: |
| 126 | return Pool{}, fmt.Errorf("invalid entityType: %v", entityType) |
| 127 | } |
| 128 | |
| 129 | q := tx |
| 130 | q = q.Preload(entityField) |
| 131 | if len(preload) > 0 { |
| 132 | for _, item := range preload { |
| 133 | q = q.Preload(item) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | var pool Pool |
| 138 | condition := fmt.Sprintf("id = ? and %s = ?", fieldName) |
| 139 | err = q.Model(&Pool{}). |
| 140 | Where(condition, u, entityID). |
| 141 | First(&pool).Error |
| 142 | if err != nil { |
| 143 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 144 | return Pool{}, fmt.Errorf("error finding pool: %w", runnerErrors.ErrNotFound) |
| 145 | } |
| 146 | return Pool{}, fmt.Errorf("error fetching pool: %w", err) |
| 147 | } |
| 148 | |
| 149 | return pool, nil |
| 150 | } |
| 151 | |
| 152 | func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, preload ...string) ([]Pool, error) { |
| 153 | if _, err := uuid.Parse(entityID); err != nil { |
no outgoing calls
no test coverage detected