Skip to content

Commit

Permalink
Fixed issue when validating service name
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Sep 4, 2022
1 parent 7dd68ef commit 970e7b3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func patchService(ctx *gin.Context) {
var errors []error

// Small function to check whether the name is already taken
validateName := func(name string) (n string, err error) {
validateName := func(id string, name string) (n string, err error) {
for _, service := range services.Services.GetServices() {
if name == service.GetName() {
if name == service.GetName() && id != service.GetID() {
err = fmt.Errorf("name already in use")
return
}
Expand All @@ -162,7 +162,8 @@ func patchService(ctx *gin.Context) {
id := ctx.Param("id")
sv, err := services.Services.GetService(id)
if err != nil {
errors = append(errors, err)
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

// Validate the port
Expand All @@ -172,7 +173,7 @@ func patchService(ctx *gin.Context) {
}

// Validate the name
validName, err := validateName(input.Name)
validName, err := validateName(id, input.Name)
if err != nil {
errors = append(errors, err)
}
Expand Down

0 comments on commit 970e7b3

Please sign in to comment.