-
Notifications
You must be signed in to change notification settings - Fork 0
/
dto.go
90 lines (67 loc) · 1.72 KB
/
dto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package user
import (
"strings"
"github.com/novaladip/geldstroom-api-go/pkg/validator"
)
type CreateUserDto struct {
Email string `form:"email"`
Password string `form:"password"`
}
func (dto CreateUserDto) validate() validator.Validate {
v := validator.Validate{
IsValid: true,
Error: make(map[string]string),
}
if !validator.EmailRX.MatchString(dto.Email) {
v.Error["email"] = "Invalid email address"
}
if strings.TrimSpace(dto.Email) == "" {
v.Error["email"] = "Email is cannot be empty"
}
if len(strings.TrimSpace(dto.Password)) < 6 {
v.Error["password"] = "Password length must be greater than 6 characters"
}
if strings.TrimSpace(dto.Password) == "" {
v.Error["password"] = "Password is cannot be empty"
}
if len(v.Error) > 0 {
v.IsValid = false
}
return v
}
type CredentialsDto struct {
Email string `form:"email"`
Password string `form:"password"`
}
func (dto CredentialsDto) validate() validator.Validate {
v := validator.New()
if !validator.EmailRX.MatchString(dto.Email) {
v.Error["email"] = "Invalid email address"
}
if strings.TrimSpace(dto.Email) == "" {
v.Error["email"] = "Email is cannot be empty"
}
if strings.TrimSpace(dto.Password) == "" {
v.Error["password"] = "Password is cannot be empty"
}
if len(v.Error) > 0 {
v.IsValid = false
}
return v
}
type ResendEmailVerificationDto struct {
Email string `form:"email"`
}
func (dto ResendEmailVerificationDto) validate() validator.Validate {
v := validator.New()
if !validator.EmailRX.MatchString(dto.Email) {
v.Error["email"] = "Invalid email address"
}
if strings.TrimSpace(dto.Email) == "" {
v.Error["email"] = "Email is cannot be empty"
}
if len(v.Error) > 0 {
v.IsValid = false
}
return v
}