backend: add: DeleteUser, fix: validation
This commit is contained in:
@@ -2,7 +2,6 @@ package validation
|
||||
|
||||
import (
|
||||
"GoMembership/internal/models"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
@@ -10,7 +9,8 @@ import (
|
||||
|
||||
func validateDriverslicence(sl validator.StructLevel) {
|
||||
dl := sl.Current().Interface().(models.User).Licence
|
||||
if !validateLicence(dl.Number) {
|
||||
// if !vValidateLicence(dl.Number) {
|
||||
if dl.Number == "" {
|
||||
sl.ReportError(dl.Number, "licence_number", "", "invalid", "")
|
||||
}
|
||||
if dl.IssuedDate.After(time.Now()) {
|
||||
@@ -21,32 +21,33 @@ func validateDriverslicence(sl validator.StructLevel) {
|
||||
}
|
||||
}
|
||||
|
||||
func validateLicence(fieldValue string) bool {
|
||||
if len(fieldValue) != 11 {
|
||||
return false
|
||||
}
|
||||
// seems like not every country has to have an licence id and it seems that germany changed their id generation type..
|
||||
// func validateLicence(fieldValue string) bool {
|
||||
// if len(fieldValue) != 11 {
|
||||
// return false
|
||||
// }
|
||||
|
||||
id, tenthChar := string(fieldValue[:9]), string(fieldValue[9])
|
||||
// id, tenthChar := string(fieldValue[:9]), string(fieldValue[9])
|
||||
|
||||
if tenthChar == "X" {
|
||||
tenthChar = "10"
|
||||
}
|
||||
tenthValue, _ := strconv.ParseInt(tenthChar, 10, 8)
|
||||
// if tenthChar == "X" {
|
||||
// tenthChar = "10"
|
||||
// }
|
||||
// tenthValue, _ := strconv.ParseInt(tenthChar, 10, 8)
|
||||
|
||||
// for readability
|
||||
weights := []int{9, 8, 7, 6, 5, 4, 3, 2, 1}
|
||||
sum := 0
|
||||
// // for readability
|
||||
// weights := []int{9, 8, 7, 6, 5, 4, 3, 2, 1}
|
||||
// sum := 0
|
||||
|
||||
for i := 0; i < 9; i++ {
|
||||
char := string(id[i])
|
||||
value, _ := strconv.ParseInt(char, 36, 64)
|
||||
sum += int(value) * weights[i]
|
||||
}
|
||||
// for i := 0; i < 9; i++ {
|
||||
// char := string(id[i])
|
||||
// value, _ := strconv.ParseInt(char, 36, 64)
|
||||
// sum += int(value) * weights[i]
|
||||
// }
|
||||
|
||||
calcCheckDigit := sum % 11
|
||||
if calcCheckDigit != int(tenthValue) {
|
||||
return false
|
||||
}
|
||||
// calcCheckDigit := sum % 11
|
||||
// if calcCheckDigit != int(tenthValue) {
|
||||
// return false
|
||||
// }
|
||||
|
||||
return true
|
||||
}
|
||||
// return true
|
||||
// }
|
||||
|
||||
@@ -27,7 +27,6 @@ func validateUser(sl validator.StructLevel) {
|
||||
sl.ReportError(user.DateOfBirth, "DateOfBirth", "dateofbirth", "age", "")
|
||||
}
|
||||
// validate subscriptionModel
|
||||
logger.Error.Printf("User SubscriptionModel.Name: %#v", user.Membership.SubscriptionModel.Name)
|
||||
if user.Membership.SubscriptionModel.Name == "" {
|
||||
sl.ReportError(user.Membership.SubscriptionModel.Name, "SubscriptionModel.Name", "name", "required", "")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user