Skip to content

Commit

Permalink
refactor: Modified CheckValidations function return values
Browse files Browse the repository at this point in the history
* Modified CheckValidations function return values from the Validator service implementation
  • Loading branch information
ralvarezdev committed Dec 22, 2024
1 parent 7d0fb6b commit 102f9fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions service/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var (
NilValidatorError = errors.New("validator cannot be nil")
NilMessageError = errors.New("message cannot be nil")
NilValidatorError = errors.New("validator cannot be nil")
NilMessageError = errors.New("message cannot be nil")
NilValidationsError = errors.New("validations cannot be nil")
)
13 changes: 10 additions & 3 deletions service/validator.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"errors"
goflagmode "github.com/ralvarezdev/go-flags/mode"
govalidatorbirthdate "github.com/ralvarezdev/go-validator/field/birthdate"
govalidatormail "github.com/ralvarezdev/go-validator/field/mail"
Expand Down Expand Up @@ -28,7 +29,7 @@ type (
*govalidatorvalidations.MapperValidations,
error,
)
CheckValidations(mapperValidations *govalidatorvalidations.MapperValidations) *string
CheckValidations(mapperValidations *govalidatorvalidations.MapperValidations) error
}

// DefaultValidator struct
Expand Down Expand Up @@ -92,10 +93,16 @@ func (d *DefaultValidator) ValidateNilFields(
// CheckValidations checks the validations and returns a pointer to the error message
func (d *DefaultValidator) CheckValidations(
mapperValidations *govalidatorvalidations.MapperValidations,
) *string {
) error {
// Get the error message from the validations if there are any
if mapperValidations.HasFailed() {
return mapperValidations.StringPtr()
// Get the validations
validations := mapperValidations.StringPtr()

if validations != nil {
return errors.New(*validations)
}
return NilValidationsError
}
return nil
}

0 comments on commit 102f9fe

Please sign in to comment.