Skip to content

Commit d3994a4

Browse files
committed
code structure improve
1 parent d5d9d3e commit d3994a4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

pkg/infraConfig/service/infraConfigService.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,31 @@ func (impl *InfraConfigServiceImpl) loadDefaultProfile() error {
222222

223223
creatableConfigurations := make([]*repository.InfraProfileConfigurationEntity, 0, len(defaultConfigurationsFromEnv))
224224
creatableProfilePlatformMapping := make([]*repository.ProfilePlatformMapping, 0)
225-
runnerPlatFormMapping := &repository.ProfilePlatformMapping{
226-
Platform: bean.RUNNER_PLATFORM,
227-
ProfileId: profile.Id,
228-
Active: true,
229-
AuditLog: sql.NewDefaultAuditLog(1),
230-
}
231225

232226
platformsFromDb, err := impl.infraProfileRepo.GetPlatformsByProfileName(bean.GLOBAL_PROFILE_NAME)
233227
if err != nil && !errors.Is(err, pg.ErrNoRows) {
234228
impl.logger.Errorw("error in fetching platforms from db", "error", err)
235229
return err
236230
}
231+
232+
runnerPlatFormMapping := &repository.ProfilePlatformMapping{}
237233
//one platform is expected
238234
if len(platformsFromDb) > 0 {
239-
runnerPlatFormMapping.Id = platformsFromDb[0].Id
235+
for _, platform := range platformsFromDb {
236+
if platform.Platform == bean.RUNNER_PLATFORM {
237+
runnerPlatFormMapping = platform
238+
break
239+
}
240+
}
241+
} else {
242+
runnerPlatFormMapping = &repository.ProfilePlatformMapping{
243+
Platform: bean.RUNNER_PLATFORM,
244+
ProfileId: profile.Id,
245+
Active: true,
246+
AuditLog: sql.NewDefaultAuditLog(1),
247+
}
240248
}
249+
241250
//creating default platform if not found in db
242251
if len(platformsFromDb) == 0 {
243252
creatableProfilePlatformMapping = append(creatableProfilePlatformMapping, runnerPlatFormMapping)

0 commit comments

Comments
 (0)