Skip to content

Commit

Permalink
RHINENG-10895 The app should have at least one profile present (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
r14chandra authored Jun 25, 2024
1 parent 7223ce1 commit cd9c148
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/http/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ func getProfiles(w http.ResponseWriter, r *http.Request) {
render.RenderPlain(w, r, http.StatusInternalServerError, fmt.Sprintf("cannot count profiles: %v", err), logger)
return
}

if total == 0 {
var defaultState map[string]string
if err := json.Unmarshal([]byte(config.DefaultConfig.ServiceConfig), &defaultState); err != nil {
logger.Error().Err(err).Msg("cannot unmarshal service config")
return
}

newProfile := db.NewProfile(id.Identity.OrgID, id.Identity.AccountNumber, defaultState)
if err := db.InsertProfile(*newProfile); err != nil {
render.RenderPlain(w, r, http.StatusInternalServerError, fmt.Sprintf("cannot insert new profile: %v", err), logger)
return
}

total += 1
}

logger.Debug().Int("total", total).Msg("found profiles")

profiles, err := db.GetProfiles(id.Identity.OrgID, sortBy, limit, offset)
Expand Down

0 comments on commit cd9c148

Please sign in to comment.