Skip to content

Commit

Permalink
feature(backend): Enabling environment upsert endpoint when creating (#…
Browse files Browse the repository at this point in the history
…2480)

feature(backend): enabling environment upsert endpoint when creating
  • Loading branch information
xoscar committed May 3, 2023
1 parent 8f0aa66 commit fb33e00
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/environment/manager.go
Expand Up @@ -84,9 +84,17 @@ func (r *Repository) SetID(environment Environment, id id.ID) Environment {

func (r *Repository) Create(ctx context.Context, environment Environment) (Environment, error) {
environment.ID = environment.Slug()
environment.CreatedAt = time.Now().UTC().Format(time.RFC3339Nano)
_, err := r.Get(ctx, environment.ID)
if err != nil {
if err == sql.ErrNoRows {
environment.CreatedAt = time.Now().UTC().Format(time.RFC3339Nano)
return r.insertIntoEnvironments(ctx, environment)
}

return Environment{}, err
}

return r.insertIntoEnvironments(ctx, environment)
return r.Update(ctx, environment)
}

func (r *Repository) Update(ctx context.Context, environment Environment) (Environment, error) {
Expand Down

0 comments on commit fb33e00

Please sign in to comment.