From 3a0ff3b9d2fc56d580aad93f3018e258097b6316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Brand=C3=A3o?= Date: Mon, 19 Dec 2022 11:35:43 -0300 Subject: [PATCH] docs: add docs to methods and types --- src/factories/password_validation_service_factory.go | 2 ++ src/services/password_validation/password_validation_service.go | 1 + src/strategies/validation/min_digit.go | 1 + src/strategies/validation/min_size.go | 1 + src/strategies/validation/min_special_chars.go | 2 ++ src/strategies/validation/no_repeted.go | 1 + src/strategies/validation/validation_strategy.go | 1 + src/strategies/validation/validation_types.go | 1 + src/utils/slice_utils.go | 1 + 9 files changed, 11 insertions(+) diff --git a/src/factories/password_validation_service_factory.go b/src/factories/password_validation_service_factory.go index 7703eff..eafa57b 100644 --- a/src/factories/password_validation_service_factory.go +++ b/src/factories/password_validation_service_factory.go @@ -5,6 +5,8 @@ import ( "github.com/brandaogabriel7/studio-sol-back-end-test/src/strategies/validation" ) +// Creates the a PasswordValidation service with the following rule validation strategies: +// minSize, minSpecialChars, minDigit, noRepeted func GetDefaultPasswordValidationService() password_validation.PasswordValidationService { validationStrategies := map[string]validation.ValidationStrategy{ string(validation.MIN_SIZE): validation.MinSizeValidationStrategy{}, diff --git a/src/services/password_validation/password_validation_service.go b/src/services/password_validation/password_validation_service.go index c2b6ec9..a3e6e1b 100644 --- a/src/services/password_validation/password_validation_service.go +++ b/src/services/password_validation/password_validation_service.go @@ -5,6 +5,7 @@ import ( "github.com/brandaogabriel7/studio-sol-back-end-test/src/strategies/validation" ) +// Checks if the password is valid based on a set of rules. type PasswordValidationService struct { strategies map[string]validation.ValidationStrategy } diff --git a/src/strategies/validation/min_digit.go b/src/strategies/validation/min_digit.go index eb184d5..c71bd88 100644 --- a/src/strategies/validation/min_digit.go +++ b/src/strategies/validation/min_digit.go @@ -2,6 +2,7 @@ package validation import "regexp" +// Checks that the password contains at least the minimum number of digits. type MinDigitValidationStrategy struct { digitRegexp regexp.Regexp } diff --git a/src/strategies/validation/min_size.go b/src/strategies/validation/min_size.go index cac5c71..23dbbdd 100644 --- a/src/strategies/validation/min_size.go +++ b/src/strategies/validation/min_size.go @@ -1,5 +1,6 @@ package validation +// Checks that the password is at least the minimum size. type MinSizeValidationStrategy struct {} func (md MinSizeValidationStrategy) IsValid(password string, value int) bool { diff --git a/src/strategies/validation/min_special_chars.go b/src/strategies/validation/min_special_chars.go index 4d41064..d2b31f0 100644 --- a/src/strategies/validation/min_special_chars.go +++ b/src/strategies/validation/min_special_chars.go @@ -2,6 +2,8 @@ package validation import "regexp" +// Checks that the password contains at least the minimum number of special chars. +// The special chars are these: !@#$%^&*()-+\/{}[] type MinSpecialCharsStrategy struct { specialCharsRegexp regexp.Regexp } diff --git a/src/strategies/validation/no_repeted.go b/src/strategies/validation/no_repeted.go index 5ac39f6..f225027 100644 --- a/src/strategies/validation/no_repeted.go +++ b/src/strategies/validation/no_repeted.go @@ -2,6 +2,7 @@ package validation import "strings" +// Checks that there are no consecutive repeated characters in the given password. type NoRepetedStrategy struct {} func (nr NoRepetedStrategy) IsValid(password string, _ int) bool { diff --git a/src/strategies/validation/validation_strategy.go b/src/strategies/validation/validation_strategy.go index 6b7d751..a906720 100644 --- a/src/strategies/validation/validation_strategy.go +++ b/src/strategies/validation/validation_strategy.go @@ -1,5 +1,6 @@ package validation +// ValidationStrategy defines a strategy to validate passwords based on a rule. type ValidationStrategy interface { IsValid(password string, value int) bool } \ No newline at end of file diff --git a/src/strategies/validation/validation_types.go b/src/strategies/validation/validation_types.go index 352cdd5..134ccb0 100644 --- a/src/strategies/validation/validation_types.go +++ b/src/strategies/validation/validation_types.go @@ -1,5 +1,6 @@ package validation +// ValidationType defines a password validation rule type. type ValidationType string const MIN_SIZE ValidationType = "minSize" diff --git a/src/utils/slice_utils.go b/src/utils/slice_utils.go index d6b0d2c..2286989 100644 --- a/src/utils/slice_utils.go +++ b/src/utils/slice_utils.go @@ -1,5 +1,6 @@ package utils +// Contains checks if a slice contains the specified string. func Contains(s []string, str string) bool { for _, v := range s { if v == str {