moved to struct validation;
This commit is contained in:
@@ -1,13 +1,27 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"GoMembership/internal/models"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func ValidateLicence(fl validator.FieldLevel) bool {
|
||||
fieldValue := fl.Field().String()
|
||||
func validateDriverslicence(sl validator.StructLevel) {
|
||||
dl := sl.Current().Interface().(models.User).Licence
|
||||
if !validateLicence(dl.Number) {
|
||||
sl.ReportError(dl.Number, "licence_number", "", "invalid", "")
|
||||
}
|
||||
if dl.IssuedDate.After(time.Now()) {
|
||||
sl.ReportError(dl.IssuedDate, "issued_date", "", "invalid", "")
|
||||
}
|
||||
if dl.ExpirationDate.Before(time.Now().AddDate(0, 0, 3)) {
|
||||
sl.ReportError(dl.ExpirationDate, "expiration_date", "", "too_soon", "")
|
||||
}
|
||||
}
|
||||
|
||||
func validateLicence(fieldValue string) bool {
|
||||
if len(fieldValue) != 11 {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user